8 Star 17 Fork 9

LibQQt应用程序开发组织 / Multi-environ Technology(PyMake)

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pydep.py 259.82 KB
一键复制 编辑 原始数据 按行查看 历史
tianduanrui 提交于 2021-06-26 16:51 . close a pypi printing in pydep.py
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907
# -*- coding: utf-8 -*-
# !/usr/bin/env python
"""PyDep 1.0
Usage:
pydep.py pypi
pydep.py pypi add <pypi-name> <pypi-source-url>
pydep.py pypi del <pypi-name>
pydep.py add pypi <pypi-name> <pypi-source-url>
pydep.py del pypi <pypi-name>
pydep.py get current pypi
pydep.py set current pypi <pypi-name>
pydep.py -------------------------------------------------------------------
pydep.py python
pydep.py python add <python-name> <python-path>
pydep.py python del <python-name>
pydep.py add python <python-name> <python-path>
pydep.py del python <python-name>
pydep.py get current python
pydep.py set current python <python-name>
pydep.py -------------------------------------------------------------------
pydep.py summary
pydep.py get requirements [ <requirements.txt> ]
pydep.py get store directory
pydep.py set store directory <store-name> <store-directory>
pydep.py get current store directory
pydep.py set current store directory to <store-name>
pydep.py store all package
pydep.py store all package to <store-name>
pydep.py store all package list to <store-name> file <requirements-txt>
pydep.py -------------------------------------------------------------------
pydep.py pip [ here | hh ] [ there | tt ] [ default | dd ] [ --workroot=<work-root-path> ] [ <pip-command> ... ]
pydep.py use <pypi-name> pip [ here | hh ] [ there | tt ] [ default | dd ] [ --workroot=<work-root-path> ] [ <pip-command> ... ]
pydep.py for <python-name> pip [ here | hh ] [ there | tt ] [ default | dd ] [ --workroot=<work-root-path> ] [ <pip-command> ... ]
pydep.py use <pypi-name> for <python-name> pip [ here | hh ] [ there | tt ] [ default | dd ] [ --workroot=<work-root-path> ] [ <pip-command> ... ]
pydep.py pip [ here | hh ] [ there | tt ] [ default | dd ] [ <pip-command> ... ] [ --workroot=<work-root-path> ]
pydep.py use <pypi-name> pip [ here | hh ] [ there | tt ] [ default | dd ] [ <pip-command> ... ] [ --workroot=<work-root-path> ]
pydep.py for <python-name> pip [ here | hh ] [ there | tt ] [ default | dd ] [ <pip-command> ... ] [ --workroot=<work-root-path> ]
pydep.py use <pypi-name> for <python-name> pip [ here | hh ] [ there | tt ] [ default | dd ] [ <pip-command> ... ] [ --workroot=<work-root-path> ]
pydep.py -------------------------------------------------------------------
pydep.py fix pip
pydep.py fix pip pip==19.1.1
pydep.py fix pip [ <python-package> ... ]
pydep.py fix pypi
pydep.py fix pypi by <pypi-name> for current user
pydep.py fix py launcher
pydep.py fix py launcher by <python-name> for current user
pydep.py fix py launcher by <python-name> for system
pydep.py fix dep
pydep.py fix dep PyQt5
pydep.py fix dep [ <python-package> ... ]
pydep.py use <pypi-name> fix dep PyQt5
pydep.py use <pypi-name> fix dep [ <python-package> ... ]
pydep.py for <python-name> fix dep PyQt5
pydep.py for <python-name> fix dep [ <python-package> ... ]
pydep.py use <pypi-name> for <python-name> fix dep PyQt5
pydep.py use <pypi-name> for <python-name> fix dep [ <python-package> ... ]
pydep.py -------------------------------------------------------------------
pydep.py collect pypi
pydep.py collect pypi from current user
pydep.py collect python
pydep.py collect python from py launcher
pydep.py collect python from finding
pydep.py save pypi
pydep.py save pypi <pypi-name>
pydep.py save pypi <pypi-name> for current user
pydep.py save python
pydep.py save python <python-name>
pydep.py save python <python-name> for system
pydep.py save python <python-name> for current user
pydep.py -------------------------------------------------------------------
pydep.py (-h | --help)
pydep.py --version
Command:
set
add
del
python
pypi
pip
summary
fix dep
collect
save
Options:
"""
from __future__ import unicode_literals
import os
import re
import sys
import uuid
import shutil
import time
import json
import copy
import types
# ===============================================================================================
# NOTICE:
# __file__ only can be used at startup position! [before os.chdir()]
# behind os.chdir(), __file__ relative to os.getcwd(), it maybe an error value!
# Dont use it later!
#
# THAT:
# __file__ maybe a relative path to os.getcwd(), it is its defination from python.
# It is a const value in its life term.
# Only at startup position, user can get its correct abs path.
# behind os.chdir(), user cannot get its correct abs path.
# Dont use it later!
# --------------------
# ===============================================================================================
# relative to project root. [relative to pymake.py]
# --------------------
pymakerelativepath = '.'
# ===============================================================================================
# load module helper
# --------------------
def load_rpath_for_local(path=''):
# add rpath. [HEADER ROOT] [LIBRARY ROOT] [MODULE ROOT]
# find module when execute.
# 1, realpath, fake_file
# 2, __file__
# 3, sys.argv[0]
basicpath = os.path.split(os.path.realpath(__file__))[0]
paths = []
if (isinstance(path, str)):
paths.append(path)
if (isinstance(path, list)):
paths.extend(path)
syspath1 = []
for key in sys.path:
temppath = key.replace('\\', '/')
syspath1.append(temppath)
for path in paths:
module_path = os.path.join(basicpath, path)
module_path = os.path.realpath(module_path)
temppath = module_path.replace('\\', '/')
if(syspath1.__contains__(temppath)):
continue
sys.path.insert(0, module_path)
return
load_rpath_for_local(pymakerelativepath)
# print(sys.path)
# ===============================================================================================
# import module
# --------------------
# common
from pycore.pycore import *
# ===============================================================================================
# PYMAKE INITIAL CODE
# --------------------
def main_function():
d = {
"tips": {
"variable.tips": [
"QQt",
"LibQQt",
"${root.build}/${qqt.proj.name}/${qt.sys.mac}/${build.release}",
"${root.src}/${qqt.proj.name}",
"${qqt.proj.name}.pro",
"${qqt.build.path}/src/bin",
"${root.prod}/QQt",
"qqtframe",
"${qqt.build.path}/examples/${qqtframe.prod.name}/bin",
"${qqt.build.path}/src/bin/QQt.framework",
"QQt.framework/Versions/1/QQt",
"${root.tool}/Source/qt5",
"${root.build}/qt5",
"androiddeployqt",
"macdeployqt",
"DownloadQueue",
"/Users/abel/Develop/c1-webrc/DownloadQueue/DownloadQueue.pro",
"${root.build}/${app.name}",
"macdeployqt ${app.path.build}/${app.name}.app",
"${prod.name}.app",
"${mac.app}/Contents",
"${mac.app.content}/MacOS",
"${mac.app.content}/Frameworks",
"${mac.app.content}/Resources",
"${mac.app.content}/PlugIns",
"${prod.name}.framework",
"${prod.name}.framework/Versions",
"${prod.name}.framework/Resources",
"macdeployqt ${}"
],
"command.tips": [
"I'm not similar to these command, so list them here, rather than forgotten them",
"cl-command, sys-command",
"replace? no, append? easy!",
"help you to remeber these command.",
"mkdir -p ${qqt.build.path}",
"cd ${build-path}",
"cmake -G\"Unix Makefiles\" -DCMAKE_INSTALL_PREFIX=${prod-root} ${source-path}",
"cmake -GXCode -DCMAKE_INSTALL_PREFIX=${prod-root} ${source-path}",
"rm -f CMakeCache.txt",
"qmake ${source-path}/${qmake-file} -spec $QTSPEC CONFIG+=$QTCONFIG && make qmake_all",
"make -j4",
"make clean in ${build-path}",
"make install",
"${deployqt} ${bin-path}/${app-bundle} -verbose=1",
"${deployqt} -dmg",
"${deployqt} --help",
"cp -fr ${lib-dep} ${lib-native}",
"install_name_tool -change ${lib-dep-name} @rpath/${lib-dep-name} ${app-native}/${prod-name} ",
"install_name_tool -change $LibDep @rpath/$LibDep ${app-native}/${prod-name} ",
"${source-path}/configure -prefix ${install-path} -hostprefix ${install-path} -xplatform android-g++ -release -nomake tests -nomake examples -android-ndk $ANDROID_NDK_ROOT -android-sdk $ANDROID_SDK_ROOT -android-ndk-host $ANDROID_NDK_HOST -android-toolchain-version $ANDROID_NDK_TOOLCHAIN_VERSION -skip qtwebkit-examples -no-warnings-are-errors",
"${qt5.path.source}/configure -prefix ${qt5.path.install} -hostprefix ${qt5.path.install} -xplatform android-g++ -release -nomake tests -nomake examples -android-ndk $ANDROID_NDK_ROOT -android-sdk $ANDROID_SDK_ROOT -android-ndk-host $ANDROID_NDK_HOST -android-toolchain-version $ANDROID_NDK_TOOLCHAIN_VERSION -skip qtwebkit-examples -no-warnings-are-errors"
],
},
"path-assemblage": {
"root": "/Users/abel/Develop",
"root.src": "${root}/a0-develop",
"root.prod": "${root}/d0-product",
"root.sdk": "${root}/d1-sdks",
"root.tool": "${root}/b0-toolskits",
"root.build": "${root}/c0-buildstation",
"root.test": "${root}/f0-test",
"root.webrc": "${root}/e0-webrc",
"cc": "${root.tool}/a0-compiler",
"pymake": "${cc}/PyMake",
"wincc": "${root.tool}/macCompilers",
"cmake.bin": "${wincc}/CMake.app/Contents/bin",
"qt": "${root.tool}/macLibraries/Qt",
"qt4.version": "4.8.6",
"qt4.clang": "${qt}/${qt4.version}/clang_64",
"qt4.clang.bin": "${qt4.clang}/bin",
"qt5.version": "5.9.2",
"qt5.ios": "${qt}/${qt5.version}/ios",
"qt5.ios.bin": "${qt}/${qt5.version}/ios/bin",
"qt5.clang": "${qt}/${qt5.version}/clang_64",
"qt5.clang.bin": "${qt}/${qt5.version}/clang_64/bin",
"qt5.android_arm": "${qt}/${qt5.version}/android_armv7",
"qt5.android_arm.bin": "${qt}/${qt5.version}/android_armv7/bin",
"qt5.android_x86": "${qt}/${qt5.version}/android_x86",
"qt5.android_x86.bin": "${qt}/${qt5.version}/android_x86/bin",
"android": "${root.tool}/macAndroidLibraries",
"android.sdk": "${android}/android-sdk-macosx",
"android.ndk": "${android}/android-ndk-r13b",
"android.ant": "${android}/apache-ant-1.10.1",
"android.java": "${android}/java-macosx/Java/JavaVirtualMachines",
"sdk.plat.tool": "${android.sdk}/platform-tools",
"sdk.build.tool": "${android.sdk}/build-tools",
"sdk.tool": "${android.sdk}/tools",
"java1.7.home": "${android.java}/jdk1.7.0_79.jdk/Contents/Home",
"java1.8.home": "${android.java}/jdk1.8.0_111.jdk/Contents/Home",
"java1.9.home": "${android.java}/jdk9.jdk/Contents/Home",
"java1.7.bin": "${java1.7.home}/bin",
"java1.8.bin": "${java1.8.home}/bin",
"java1.9.bin": "${java1.9.home}/bin",
"ant.bin": "${android.ant}/bin",
"ndk.arm": "${android.ndk}/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64",
"ndk.x86": "${android.ndk}/toolchains/x86-4.9/prebuilt/darwin-x86_64",
"ndk.x86_64": "${android.ndk}/toolchains/x86_64-4.9/prebuilt/darwin-x86_64",
"ndk.arm.bin": "${ndk.arm}/bin",
"ndk.x86.bin": "${ndk.x86}/bin",
"ndk.x86_64.bin": "${ndk.x86_64}/bin",
"ios.simulator.sysroot": "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk",
"xcode.bin": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin",
"mac.sysroot": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
},
"environ": {
"android.mobile": {
"path+": [
"${qt5.android_arm.bin}",
"${java1.8.bin}",
"${android.sdk}",
"${sdk.plat.tool}",
"${sdk.build.tool}",
"${sdk.tool}",
"${ant.bin}",
"${ndk.arm.bin}"
],
"makex": "make",
"CMAKEGENERATOR": "Unix Makefiles",
"ANDROID_API_VERSION": "android-23",
"ANDROID_SDK_ROOT": "${android.sdk}",
"ANDROID_NDK_ROOT": "${android.ndk}",
"ANDROID_NDK_HOST": "darwin-x86_64",
"ANDROID_NDK_TOOLCHAIN_PREFIX": "arm-linux-androideabi",
"ANDROID_NDK_TOOLCHAIN_VERSION": "4.9",
"ANDROID_NDK_PLATFORM": "android-23",
"NDK_TOOLCHAIN_PATH": "${ndk.arm.bin}",
"NDK_TOOLS_PREFIX": "arm-linux-androideabi",
"QTVERSION": "${qt5.version}",
"QTDIR": "${qt5.android_arm}",
"QTSPEC": "-spec android-g++",
"QTCONFIG": "",
"JAVA_HOME": "${java1.8.home}",
"CLASSPATH": ".:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar",
"PYMAKE_MYNAME": "T.D.R",
"a_special_var_const": "hello world",
"QKIT": "ANDROID",
"QSYS": "Android"
},
"android.x86": {
"path+": [
"${qt5.android_x86.bin}",
"${java1.8.bin}",
"${android.sdk}",
"${sdk.plat.tool}",
"${sdk.build.tool}",
"${sdk.tool}",
"${ant.bin}",
"${ndk.x86.bin}"
],
"makex": "make",
"CMAKEGENERATOR": "Unix Makefiles",
"CLICOLOR": "1",
"ANDROID_API_VERSION": "android-23",
"ANDROID_HOME": "${android.sdk}",
"ANDROID_SDK_ROOT": "${android.sdk}",
"ANDROID_NDK_PLATFORM": "android-23",
"ANDROID_NDK_ROOT": "${android.ndk}",
"ANDROID_NDK_HOST": "darwin-x86_64",
"ANDROID_NDK_TOOLCHAIN_PREFIX": "x86",
"ANDROID_NDK_TOOLCHAIN_VERSION": "4.9",
"ANDROID_NDK_TOOLS_PREFIX": "i686-linux-android",
"NDK_TOOLCHAIN_PATH": "${ndk.x86.bin}",
"NDK_TOOLS_PREFIX": "i686-linux-android",
"PYMAKE_MYNAME": "T.D.R",
"a_special_var_const": "hello world",
"QTDIR": "${qt5.android_x86}",
"QTSPEC": "-spec android-g++",
"QTCONFIG": "",
"JAVA_HOME": "${java1.8.home}",
"CLASSPATH": ".:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar",
"QTVERSION": "${qt5.version}",
"QKIT": "ANDROIDX86",
"QSYS": "AndroidX86"
},
"qt4": {
"path+": [
"${qt4.clang.bin}"
],
"makex": "make",
"CMAKEGENERATOR": "Unix Makefiles",
"QTVERSION": "${qt4.version}",
"QTDIR": "${qt4.clang}",
"QTSPEC": "-spec macx-llvm",
"QTCONFIG": "CONFIG+=x86_64",
"QKIT": "macOS",
"QSYS": "macOS"
},
"ios": {
"path+": [
"${qt5.ios.bin}"
],
"makex": "make",
"CMAKEGENERATOR": "Unix Makefiles",
"QTVERSION": "${qt5.version}",
"QTDIR": "${qt5.ios}",
"QTSPEC": "-spec macx-ios-clang",
"QTCONFIG": "CONFIG+=iphoneos CONFIG+=device -after QMAKE_MAC_XCODE_SETTINGS+=qteam qteam.name=DEVELOPMENT_TEAM qteam.value=4EGMLT3G6T",
"QKIT": "iOS",
"QSYS": "iOS"
},
"iossimulator": {
"path+": [
"${qt5.ios.bin}"
],
"makex": "make",
"CMAKEGENERATOR": "Unix Makefiles",
"QTVERSION": "${qt5.version}",
"QTDIR": "${qt5.ios}",
"QTSPEC": "-spec macx-ios-clang",
"QTCONFIG": "CONFIG+=iphonesimulator CONFIG+=simulator",
"QKIT": "iOSSimulator",
"QSYS": "iOSSimulator"
},
"macos": {
"path+": [
"${qt5.clang.bin}"
],
"makex": "make",
"CMAKEGENERATOR": "Unix Makefiles",
"QTVERSION": "${qt5.version}",
"QTDIR": "${qt5.clang}",
"QTSPEC": "-spec macx-clang",
"QTCONFIG": "CONFIG+=x86_64",
"QKIT": "macOS",
"QSYS": "macOS"
},
"current": "macos"
},
"command": {
"test": [
"echo $(pwd)"
],
"test.2": [
"#echo $*",
"param=$*",
"ping 127.0.0.1 $param"
],
"test.3": [
"#echo $*",
"ping $*"
],
"test.4": [
"echo param1: $1",
"echo param2: $2",
"echo param3: $3",
"echo param4: $4"
],
"test.5": [
"exit 0"
],
"test.6": [
"echo 中文"
],
"test.7": [
"echo $PATH"
],
"open.env": [
"open $(pymake source)",
"open $(pymake source root)/custom.path+.ini",
"open $(pymake source root)/custom.var+.ini"
],
"qt": [
"open \"/Applications/Qt Creator.app\""
],
"cmake-app": [
"open ${wincc}/CMake.app"
],
"prod": [
"open /Users/abel/Develop/d0-product/ProductExecTool/macOS/ProductExecTool_debug.app"
],
"libtool": [
"open /Users/abel/Develop/d0-product/AddLibraryTool/macOS/AddLibraryTool_debug.app"
],
"android.sdk": [
"/Users/abel/Develop/b0-toolskits/macAndroidLibraries/android-sdk-macosx/tools/android"
],
"open-dir": [
"open $1"
],
"qtdir": [
"echo $QTDIR"
],
"build.info": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"if [ -f \"$1.pro\" ]; then",
" echo $1.pro existed.",
"else",
" echo has $1.pro? please add here command to restrict.",
" break",
"fi",
"src=$src_path/$profilename.pro",
"build=${root.build}/$profilename/$QSYS/$QTVERSION/Debug",
"prod=${root.prod}/$profilename/$QSYS",
"sdk=${root.sdk}/$profilename/$QSYS",
"echo src file: $src",
"echo src path: $src_path",
"echo sdk at: $sdk",
"echo prod at: $prod",
"echo build at: $build",
"echo build inf $QTSPEC $QTCONFIG",
"endtime=`date +'%Y-%m-%d %H:%M:%S'`",
"echo 现在时间:$endtime",
"break",
"done"
],
"build.qmake": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"if [ -f \"$1.pro\" ]; then",
" echo $1.pro existed.",
"else",
" echo has $1.pro? please add here command to restrict.",
" break",
"fi",
"src=$src_path/$profilename.pro",
"build=${root.build}/$profilename/$QSYS/$QTVERSION/Debug",
"prod=${root.prod}/$profilename/$QSYS",
"sdk=${root.sdk}/$profilename/$QSYS",
"mkdir -p $build",
"cd $build",
"echo src file: $src",
"echo src path: $src_path",
"echo sdk at: $sdk",
"echo prod at: $prod",
"echo build at: $build",
"echo $QTSPEC $QTCONFIG",
"#starttime=`date +'%Y-%m-%d %H:%M:%S'`",
"qmake $src $QTSPEC CONFIG+=debug CONFIG+=qml_debug $QTCONFIG && make qmake_all",
"make -j4",
"echo build inf $QTSPEC $QTCONFIG",
"echo src file: $src",
"echo src path: $src_path",
"echo build at: $build",
"echo sdk at: $sdk",
"echo prod at: $prod",
"#endtime=`date +'%Y-%m-%d %H:%M:%S'`",
"#start_seconds=$(date --date=\"$starttime\" +%s);",
"#end_seconds=$(date --date=\"$endtime\" +%s);",
"#echo \"本次运行时间: \"$((end_seconds-start_seconds))\"s\"",
"break",
"done"
],
"build.qmake.all": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"if [ -f \"$1.pro\" ]; then",
" echo $1.pro existed.",
"else",
" echo has $1.pro? please add here command to restrict.",
" break",
"fi",
"echo You must use pymake system ccvp here command to execute this command!",
"envlist=(\"macos\" \"iossimulator\" \"android.mobile\" \"android.x86\")",
"length=${#envlist[@]}",
"cmd0=${envlist[0]}",
"#for envname in $envlist 这个是个bug",
"for envname in ${envlist[@]}",
"do",
" #echo $envname",
" #echo pymake use $envname ccvp here build.qmake $profilename",
" #export aiya=$envname",
" #echo $aiya",
" #osascript -e \"",
" # set a to \\\"$aiya\\\"",
" # tell application \\\"Terminal\\\" to do script \\\"echo - $a - \\\" & a & - \\\"$aiya\\\"",
" #\"",
" #osascript",
" #set a to POSIX file \"$envname\"",
" #env",
" #osascript -e 'tell application \"Terminal\" to do script \"echo $aiya\"'",
" osascript -e \"",
" tell application \\\"Terminal\\\" to do script \\\"cd $src_path && echo $profilename - $envname && pymake use $envname ccvp here build.qmake $profilename\\\"",
" \"",
"done",
"break",
"done"
],
"build.cmake.gui": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"if [ -f \"CMakeLists.txt\" ]; then",
" echo CMakeLists.txt existed.",
"else",
" echo has CMakeLists.txt? please add here command to restrict.",
" break",
"fi",
"src=$src_path/CMakeLists.txt",
"build=${root.build}/$profilename/$QSYS/$QTVERSION/Debug",
"prod=${root.prod}/$profilename/$QSYS",
"sdk=${root.sdk}/$profilename/$QSYS",
"mkdir -p $build",
"cd $build",
"echo src file: $src",
"echo src path: $src_path",
"echo sdk at: $sdk",
"echo prod at: $prod",
"echo build at: $build",
"echo $QTSPEC $QTCONFIG",
"open ${wincc}/CMake.app",
"errorlevel=$?",
"if [ $errorlevel -ne 0 ]; then",
" echo cmake exit code: $errorlevel",
" break",
"fi",
"echo build inf $QTSPEC $QTCONFIG",
"echo src file: $src",
"echo src path: $src_path",
"echo build at: $build",
"echo sdk at: $sdk",
"echo prod at: $prod",
"break",
"done"
],
"build.cmake.sdk": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"if [ -f \"CMakeLists.txt\" ]; then",
" echo CMakeLists.txt existed.",
"else",
" echo has CMakeLists.txt? please add here command to restrict.",
" break",
"fi",
"src=$src_path/CMakeLists.txt",
"build=${root.build}/$profilename/$QSYS/$QTVERSION/Debug",
"prod=${root.prod}/$profilename/$QSYS",
"sdk=${root.sdk}/$profilename/$QSYS",
"mkdir -p $build",
"cd $build",
"echo src file: $src",
"echo src path: $src_path",
"echo sdk at: $sdk",
"echo prod at: $prod",
"echo build at: $build",
"echo $QTSPEC $QTCONFIG",
"cmake $src_path -G\"$CMAKEGENERATOR\" -DCMAKE_INSTALL_PREFIX=${root.sdk}/$profilename/$QSYS -DCMAKE_BUILD_TYPE=Debug",
"errorlevel=$?",
"if [ $errorlevel -ne 0 ]; then",
" echo cmake exit code: $errorlevel",
" break",
"fi",
"echo build inf $QTSPEC $QTCONFIG",
"echo src file: $src",
"echo src path: $src_path",
"echo build at: $build",
"echo sdk at: $sdk",
"echo prod at: $prod",
"break",
"done"
],
"build.cmake.app": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"if [ -f \"CMakeLists.txt\" ]; then",
" echo CMakeLists.txt existed.",
"else",
" echo has CMakeLists.txt? please add here command to restrict.",
" break",
"fi",
"src=$src_path/CMakeLists.txt",
"build=${root.build}/$profilename/$QSYS/$QTVERSION/Debug",
"prod=${root.prod}/$profilename/$QSYS",
"sdk=${root.sdk}/$profilename/$QSYS",
"mkdir -p $build",
"cd $build",
"echo src file: $src",
"echo src path: $src_path",
"echo sdk at: $sdk",
"echo prod at: $prod",
"echo build at: $build",
"echo $QTSPEC $QTCONFIG",
"cmake $src_path -G\"$CMAKEGENERATOR\" -DCMAKE_INSTALL_PREFIX=${root.prod}/$profilename/$QSYS -DCMAKE_BUILD_TYPE=Debug",
"errorlevel=$?",
"if [ $errorlevel -ne 0 ]; then",
" echo cmake exit code: $errorlevel",
" break",
"fi",
"echo build inf $QTSPEC $QTCONFIG",
"echo src file: $src",
"echo src path: $src_path",
"echo build at: $build",
"echo sdk at: $sdk",
"echo prod at: $prod",
"break",
"done"
],
"build.make": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"src=$src_path/$profilename.pro",
"build=${root.build}/$profilename/$QSYS/$QTVERSION/Debug",
"prod=${root.prod}/$profilename/$QSYS",
"sdk=${root.sdk}/$profilename/$QSYS",
"#mkdir -p $build",
"cd $build",
"echo src file: $src",
"echo src path: $src_path",
"echo sdk at: $sdk",
"echo prod at: $prod",
"echo build at: $build",
"echo $QTSPEC $QTCONFIG",
"#qmake $src $QTSPEC CONFIG+=debug CONFIG+=qml_debug $QTCONFIG && $makex qmake_all",
"$makex",
"echo build inf $QTSPEC $QTCONFIG",
"echo src file: $src",
"echo src path: $src_path",
"echo build at: $build",
"echo sdk at: $sdk",
"echo prod at: $prod",
"break",
"done"
],
"build.make.install": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"src=$src_path/$profilename.pro",
"build=${root.build}/$profilename/$QSYS/$QTVERSION/Debug",
"prod=${root.prod}/$profilename/$QSYS",
"sdk=${root.sdk}/$profilename/$QSYS",
"#mkdir -p $build",
"cd $build",
"echo src file: $src",
"echo src path: $src_path",
"echo sdk at: $sdk",
"echo prod at: $prod",
"echo build at: $build",
"echo $QTSPEC $QTCONFIG",
"#qmake $src $QTSPEC CONFIG+=debug CONFIG+=qml_debug $QTCONFIG && $makex qmake_all",
"$makex install",
"echo build inf $QTSPEC $QTCONFIG",
"echo src file: $src",
"echo src path: $src_path",
"echo build at: $build",
"echo sdk at: $sdk",
"echo prod at: $prod",
"break",
"done"
],
"build.make.clean": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"src=$src_path/$profilename.pro",
"build=${root.build}/$profilename/$QSYS/$QTVERSION/Debug",
"prod=${root.prod}/$profilename/$QSYS",
"sdk=${root.sdk}/$profilename/$QSYS",
"#mkdir -p $build",
"cd $build",
"echo src file: $src",
"echo src path: $src_path",
"echo sdk at: $sdk",
"echo prod at: $prod",
"echo build at: $build",
"echo $QTSPEC $QTCONFIG",
"#qmake $src $QTSPEC CONFIG+=debug CONFIG+=qml_debug $QTCONFIG && $makex qmake_all",
"$makex clean",
"echo build inf $QTSPEC $QTCONFIG",
"echo src file: $src",
"echo src path: $src_path",
"echo build at: $build",
"echo sdk at: $sdk",
"echo prod at: $prod",
"break",
"done"
],
"build.go": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"if [ -f \"$1.go\" ]; then",
" echo $1.go existed.",
"else",
" echo has $1.go? please add here command to restrict.",
" break",
"fi",
"src=$src_path/$profilename.go",
"build=${root.build}/$profilename/$QSYS/$QTVERSION/Debug",
"prod=${root.prod}/$profilename/$QSYS",
"sdk=${root.sdk}/$profilename/$QSYS",
"mkdir -p $build",
"cd $build",
"echo src file: $src",
"echo src path: $src_path",
"echo sdk at: $sdk",
"echo prod at: $prod",
"echo build at: $build",
"echo $QTSPEC $QTCONFIG",
"#qmake $src $QTSPEC CONFIG+=debug CONFIG+=qml_debug $QTCONFIG && make qmake_all",
"#make -j4",
"go build $src",
"echo build inf $QTSPEC $QTCONFIG",
"echo src file: $src",
"echo src path: $src_path",
"echo build at: $build",
"echo sdk at: $sdk",
"echo prod at: $prod",
"break",
"done"
],
"build.configure": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"if [ -f \"configure\" ]; then",
" echo configure existed.",
"else",
" echo has configure? please add here command to restrict.",
" break",
"fi",
"src=$src_path/configure",
"build=${root.build}/$profilename/$QSYS/$QTVERSION/Debug",
"prod=${root.prod}/$profilename/$QSYS",
"sdk=${root.sdk}/$profilename/$QSYS",
"mkdir -p $build",
"cd $build",
"echo src file: $src",
"echo src path: $src_path",
"echo sdk at: $sdk",
"echo prod at: $prod",
"echo build at: $build",
"echo $QTSPEC $QTCONFIG",
"#qmake $src $QTSPEC CONFIG+=debug CONFIG+=qml_debug $QTCONFIG && make qmake_all",
"#make -j4",
"configure \"$@\"",
"echo build inf $QTSPEC $QTCONFIG",
"echo src file: $src",
"echo src path: $src_path",
"echo build at: $build",
"echo sdk at: $sdk",
"echo prod at: $prod",
"break",
"done"
],
"build.autogen": [
"while [ 1 ]",
"do",
"src_path=$(pwd)",
"profilename=$1",
"if [ \"$profilename\" == \"\" ]; then",
" echo please input a project name",
" break",
"fi",
"if [ -f \"autogen.sh\" ]; then",
" echo autogen.sh existed.",
"else",
" echo has autogen.sh? please add here command to restrict.",
" break",
"fi",
"src=$src_path/autogen.sh",
"build=${root.build}/$profilename/$QSYS/$QTVERSION/Debug",
"prod=${root.prod}/$profilename/$QSYS",
"sdk=${root.sdk}/$profilename/$QSYS",
"mkdir -p $build",
"cd $build",
"echo src file: $src",
"echo src path: $src_path",
"echo sdk at: $sdk",
"echo prod at: $prod",
"echo build at: $build",
"echo $QTSPEC $QTCONFIG",
"#qmake $src $QTSPEC CONFIG+=debug CONFIG+=qml_debug $QTCONFIG && make qmake_all",
"#make -j4",
"autogen.sh \"$@\"",
"echo build inf $QTSPEC $QTCONFIG",
"echo src file: $src",
"echo src path: $src_path",
"echo build at: $build",
"echo sdk at: $sdk",
"echo prod at: $prod",
"break",
"done"
],
"Qt.move": [
"while [ 1 ]",
"do",
"srcdir=$1",
"srcver=$2",
"if [ \"$1\" = \"\" ]; then",
" echo please input old qtdir.",
" break",
"fi",
"if [ \"$2\" = \"\" ]; then",
" echo please input old qtversion.",
" break",
"fi",
"mv -f $srcdir/$srcver/* Qt2/$srcver/",
"mv -f $srcdir/Docs/* Qt2/Docs/",
"mv -f $srcdir/Examples/* Qt2/Examples/",
"mv -f $srcdir/*.zip Qt2/",
"break",
"done"
],
"qt4.build": [
"src=${root.tool}/z0-Source/qt",
"build=${root.build}/qt",
"install=${root.tool}/macLibraries/Qt/4.8/gcc_64",
"mkdir -p $build",
"cd $build",
"echo build $(pwd)",
"CXXFLAGS=-stdlib=libc++",
"${src}/configure -prefix ${install}",
"make -j4",
"make install"
],
"qtsoap.build": [
"src=/Users/abel/Develop/c1-webrc/qt-solutions/qtsoap",
"build=${root.build}/qtsoap",
"install=/Users/abel/Develop/d1-product/QtSoap",
"cd $build",
"${src}/configure -library"
],
"qqt.build.all": [
"osascript -e 'tell application \"Terminal\" to do script \"echo hello\"'"
],
"qqt.daily": [
"src_path=/Users/abel/Develop/a0-develop/LibQQt",
"src=$src_path/QQt.pro",
"build=/Users/abel/Develop/c0-buildstation/QQt/$QSYS/$QTVERSION/Debug",
"mkdir -p $build",
"cd $build",
"rm -rf src examples",
"qmake $src $QTSPEC $QTCONFIG CONFIG+=debug CONFIG+=qml_debug && make qmake_all",
"make -j4"
],
"qqt.daily.release": [
"src_path=/Users/abel/Develop/a0-develop/LibQQt",
"src=$src_path/QQt.pro",
"build=/Users/abel/Develop/c0-buildstation/QQt/$QSYS/$QTVERSION/Release",
"mkdir -p $build",
"cd $build",
"rm -rf src examples",
"qmake $src $QTSPEC $QTCONFIG CONFIG+=release && make qmake_all",
"make -j4"
],
"qqt.build.release": [
"src_path=/Users/abel/Develop/a0-develop/LibQQt",
"src=$src_path/QQt.pro",
"build=/Users/abel/Develop/c0-buildstation/QQt/$QSYS/$QTVERSION/Release",
"mkdir -p $build",
"cd $build",
"qmake $src $QTSPEC $QTCONFIG CONFIG+=release && make qmake_all",
"make -j4"
],
"qqt.build": [
"src_path=${root.src}/LibQQt",
"src=${root.src}/LibQQt/QQt.pro",
"build=${root.build}/QQt/$QSYS/$QTVERSION/Debug",
"mkdir -p $build",
"cd $build",
"echo build $(pwd)",
"qmake ${src} $QTSPEC CONFIG+=debug CONFIG+=qml_debug $QTCONFIG && make qmake_all",
"make -j4"
],
"qqt.clean": [
"src=${root.src}/LibQQt/QQt.pro",
"build=${root.build}/QQt/$QSYS/$QTVERSION/Debug",
"cd $build",
"make clean"
],
"qqt.clean.release": [
"src=/Users/abel/Develop/a0-develop/LibQQt/QQt.pro",
"build=/Users/abel/Develop/c0-buildstation/QQt/$QSYS/$QTVERSION/Release",
"cd $build",
"make clean"
],
"qt.check": [
"src=${root.tool}/z0-Source/qt-everywhere-opensource-src-4.8.7",
"build=${root.build}/qt4.7",
"install=${root.tool}/macLibraries/Qt/4.8.7/gcc_64",
"mkdir -p $build",
"cd $build",
"echo build $(pwd)",
"${src}/configure --help"
],
"qt.build": [
"src=/Users/abel/Develop/b0-toolskits/z0-Source/qt",
"build=/Users/abel/Develop/c0-buildstation/qt",
"install=/Users/abel/Develop/b0-toolskits/macLibraries/Qt/4.8/gcc_64",
"mkdir -p $build",
"cd $build",
"echo build $(pwd)",
"CXXFLAGS=-stdlib=libc++",
"${src}/configure -prefix ${install}",
"make -j4",
"make install"
],
"qt4.7.build": [
"src=${root.tool}/z0-Source/qt-everywhere-opensource-src-4.8.7",
"build=${root.build}/qt4.7",
"install=${root.tool}/macLibraries/Qt/4.8.7/gcc_64",
"mkdir -p $build",
"cd $build",
"echo build $(pwd)",
"${src}/configure -prefix ${install}",
"make -j4",
"make install"
],
"soap.build": [
"src=/Users/abel/Develop/c1-webrc/qt-solutions/qtsoap",
"build=/Users/abel/Develop/c0-buildstation/qtsoap",
"install=/Users/abel/Develop/d1-product/QtSoap",
"cd $build",
"${src}/configure -library"
],
"qqt.push": [
"src=${root.src}/LibQQt",
"cd $src",
"git push",
"git push --tag"
],
"qqt.pull": [
"src=${root.src}/LibQQt",
"cd $src",
"git pull"
],
"qqt.cloc": [
"src=${root.src}/LibQQt",
"cd $src",
"perl ${pymake}/demo/cloc-1.74.pl .",
"date"
],
"light.cloc": [
"src=${root.src}/LightUnderWater/App",
"cd $src",
"perl ${pymake}/demo/cloc-1.74.pl .",
"date"
]
}
}
# record current directory [pwd, execute path]
startupworkdirectory = os.getcwd()
# print( "pymake start up work directory:", startupworkdirectory )
# here work root
# use __file__ , but ... [relative path]
# record pymake file directory, program file path.
pymakefile = os.path.realpath(__file__)
pymakefileroot = os.path.dirname(os.path.realpath(__file__))
pymakefilename = os.path.basename(os.path.realpath(__file__))
# print( "pymake file :", pymakefile )
# print( "pymake file root:", pymakefileroot )
# print( "pymake file name:", pymakefilename )
# record pymake project root, project files root.
# important relative path. [relative to pymake.py] [relative to project root] [relative to caller file]
pymakeprojectroot = os.path.join(pymakefileroot, pymakerelativepath)
pymakeprojectroot = os.path.realpath(pymakeprojectroot)
# print( "pymake project root:", pymakeprojectroot )
# record pymake user source root [env, *.json] [ + auto create ]
pymakedefaultsourceroot = pymakeprojectroot + os.path.sep + 'UserSource'
if (not os.path.exists(pymakedefaultsourceroot)):
os.makedirs(pymakedefaultsourceroot)
# print( "pymake default source root:", pymakedefaultsourceroot )
# record default user source config file name
pymakedefaultsourcefile = 'pymake.json'
# print( "pymake default source file:", pymakedefaultsourcefile )
# print( "pymake default source config:", os.path.join(pymakedefaultsourceroot, pymakedefaultsourcefile) )
# print( "pymake default source root :", pymakedefaultsourceroot )
# print( "pymake default source file :", pymakedefaultsourcefile )
# record pymake user shell root [ dynamic work path ]
# default work directory
pymakedefaultshellroot = pymakedefaultsourceroot + os.path.sep + 'UserShell'
if (not os.path.exists(pymakedefaultshellroot)):
os.makedirs(pymakedefaultshellroot)
# print( "pymake default shell path:", pymakedefaultshellroot )
# ===============================================================================================
# PYMAKE PROGRAM CONFIGURE INITIAL CODE
# --------------------
"""
[pymake]
[source]
root = $pymakedefaultsourceroot
config = $pymakedefaultsourcefile
"""
userroot = getuserroot()
configroot = getconfigroot()
plat = getplatform()
# record pymake configure directory. [ in user config path ]
pymakeconfigureroot = userroot + os.path.sep + '.pymake'
if (not os.path.exists(pymakeconfigureroot)):
os.makedirs(pymakeconfigureroot)
# initial pymake.ini
pymakeconfigureini = pymakeconfigureroot + os.path.sep + 'pymake.ini'
# add green ability
# pymakegreenconfigureroot = pymakeprojectroot
# pymakegreenconfigureini = os.path.join(pymakegreenconfigureroot, 'pymake.ini')
# if (os.path.exists(pymakegreenconfigureini)):
# pymakeconfigureroot = pymakegreenconfigureroot
# pymakeconfigureini = pymakegreenconfigureini
# print(pymakeconfigureroot)
# print(pymakeconfigureini)
# return
conf = MyConfigParser()
conf.read(pymakeconfigureini)
if (not conf.has_section('pymake')):
conf.add_section('pymake')
conf.write(open(pymakeconfigureini, 'w'))
if (not conf.has_section('source')):
conf.add_section('source')
conf.write(open(pymakeconfigureini, 'w'))
if (not conf.has_option('source', 'root')):
conf.set('source', 'root', pymakedefaultsourceroot)
conf.write(open(pymakeconfigureini, 'w'))
if (not conf.has_option('source', 'config')):
conf.set('source', 'config', pymakedefaultsourcefile)
conf.write(open(pymakeconfigureini, 'w'))
# ===============================================================================================
# PYMAKE ARGS COMMAND INITIAL CODE
# --------------------
args = {}
args = docopt(__doc__, version='pydep.py v1.0')
# print(args)
# ===============================================================================================
# PYMAKE INITIALIZE COMMAND INITIAL CODE
# --------------------
# initialize
# ===============================================================================================
# PYMAKE SOURCE ROOT INITIAL CODE
# --------------------
# init pymake.json in sourceroot [ + program create ]
# record user source root directory
sourceroot = conf.get('source', 'root')
# record source config file name
sourcefile = conf.get('source', 'config')
# record source config file
sourceconfigfile = sourceroot + os.path.sep + sourcefile
# print("root: %s, config: %s" % (sourceroot, sourcefile))
# print("use source config: %s" % (sourceconfigfile) )
# record default source config file
defaultsourceconfigfile = sourceroot + os.path.sep + pymakedefaultsourcefile
# print ("root: %s, default config: %s" % (sourceroot, pymakedefaultsourcefile))
# print("default source config: %s" % (defaultsourceconfigfile) )
# print("user default source config: %s" % (defaultsourceconfigfile) )
# print("user default source root : %s" % (sourceroot))
# print("user default source file : %s" % (pymakedefaultsourcefile) )
# check source root
# prepare to user source root
if (not os.path.exists(sourceroot)):
os.makedirs(sourceroot)
os.chdir(sourceroot)
# check default source file [default:d]
if (os.path.exists(sourceroot)):
if (os.path.abspath(sourceroot) != os.path.abspath(pymakeconfigureroot)
and os.path.abspath(sourceroot) != os.path.abspath(pymakeprojectroot)
and os.path.abspath(sourceroot) != os.path.abspath(pymakefileroot)):
if (not os.path.exists(defaultsourceconfigfile)):
writeJsonData(defaultsourceconfigfile, d)
# check source file [default:d]
if (os.path.exists(sourceroot)):
if (os.path.abspath(sourceroot) != os.path.abspath(pymakeconfigureroot)
and os.path.abspath(sourceroot) != os.path.abspath(pymakeprojectroot)
and os.path.abspath(sourceroot) != os.path.abspath(pymakefileroot)):
if (not os.path.exists(sourceconfigfile)):
writeJsonData(sourceconfigfile, d)
def open_file(file0):
plat = getplatform()
cmd0 = ''
if (plat == "Windows"):
if (file0.__contains__(' ')):
cmd0 = 'start "" ' + '"%s"' % file0
else:
cmd0 = "start " + file0
elif (plat == "Darwin"):
if (file0.__contains__(' ')):
cmd0 = 'open ' + '"%s"' % file0
else:
cmd0 = "open " + file0
else:
if (file0.__contains__(' ')):
cmd0 = 'xdg-open ' + '"%s" ' % file0 + ">/dev/null 2>&1"
else:
cmd0 = "xdg-open " + '%s ' % file0 + ">/dev/null 2>&1"
return cmd0
# record source config file postfix
pymakesourcesuffix = '.json'
# ===============================================================================================
# PYMAKE SOURCE COMMAND INITIAL CODE
# --------------------
# source
# ===============================================================================================
# PYMAKE SOURCE ROOT INITIAL 2 CODE
# --------------------
# check source root directory
if (os.path.exists(sourceroot) is False):
print("You have changed sourceroot manually, please change it using source command")
return
# check source root .json file
if (os.path.abspath(sourceroot) == os.path.abspath(pymakeconfigureroot)
or os.path.abspath(sourceroot) == os.path.abspath(pymakeprojectroot)
or os.path.abspath(sourceroot) == os.path.abspath(pymakefileroot)):
print("I checked you use pymakeconfigureroot or pymakeprojectroot to be sourceroot, I suggest you use source command changing one.")
print("This progrom can store building env and building command forever, please repleace source root then using it.")
return
elif (os.path.abspath(sourceroot) != os.path.abspath(pymakeconfigureroot)):
if (not os.path.exists(defaultsourceconfigfile)):
writeJsonData(defaultsourceconfigfile, d)
print("initialize pymake.json in source root %s." % sourceroot)
if (not os.path.exists(sourceconfigfile)):
print("source config file %s is not existed." % sourceconfigfile)
print("You can use source command to fix it.")
return
# ===============================================================================================
# PYMAKE INITIALIZE COMMAND INITIAL CODE
# --------------------
# initialize
# ===============================================================================================
# PYMAKE SHELL ROOT INITIAL CODE
# --------------------
# record user shell root directory [default]
defaultshellroot = sourceroot + os.path.sep + "UserShell"
# print("execute directory: %s" % (defaultshellroot) )
if (not os.path.exists(defaultshellroot)):
os.makedirs(defaultshellroot)
# support pymake default shell root, pymake custom shell root, pymake current shell root.
pymakeexecini = sourceroot + os.path.sep + 'exec.ini'
execconf = MyConfigParser()
execconf.read(pymakeexecini)
if (not execconf.has_section('exec')):
execconf.add_section('exec')
execconf.write(open(pymakeexecini, 'w'))
if (not execconf.has_section('work')):
execconf.add_section('work')
execconf.write(open(pymakeexecini, 'w'))
if (not execconf.has_section('root')):
execconf.add_section('root')
execconf.write(open(pymakeexecini, 'w'))
if (not execconf.has_option('work', 'where')):
execconf.set('work', 'where', 'default')
execconf.write(open(pymakeexecini, 'w'))
if (not execconf.has_option('root', 'default')):
execconf.set('root', 'default', defaultshellroot)
execconf.write(open(pymakeexecini, 'w'))
if (not execconf.has_option('root', 'there')):
execconf.set('root', 'there', defaultshellroot)
execconf.write(open(pymakeexecini, 'w'))
if (not execconf.has_option('root', 'here')):
execconf.set('root', 'here', '')
execconf.write(open(pymakeexecini, 'w'))
# record pymake work root type [ where is the work root ? default, there, here ]
workroottype = execconf.get('work', 'where')
# record pymake custom shell root [ user custom work path ]
customshellroot = execconf.get('root', 'there')
if (not os.path.exists(customshellroot)):
os.makedirs(customshellroot)
# custom work root
# record user shell root directory [starting] [1/3 maybe startup directory]
shellroot = defaultshellroot
if (workroottype == 'default'):
shellroot = defaultshellroot
elif (workroottype == 'here'):
shellroot = startupworkdirectory
elif (workroottype == 'there'):
shellroot = customshellroot
# if(workroottype == 'default'):
# print("WORK STARTING : %s" % (defaultshellroot))
# elif (workroottype == 'here'):
# print("WORK STARTING : %s" % (startupworkdirectory))
# elif (workroottype == 'there'):
# print("WORK STARTING : %s" % (customshellroot))
# print("execute root type: %s" % (workroottype) )
# print("execute directory: %s" % (shellroot) )
# I set this,
# pymake execute user bat/sh in shellroot,
# user can use here param to restrict exec action.
# cd user shell root [ default shell execute path ]
# prepare to user shell root
if (not os.path.exists(shellroot)):
os.makedirs(shellroot)
os.chdir(shellroot)
# print( "pymake user shell root:", pymakeshellroot )
# ===============================================================================================
# PYMAKE BACKUP COMMAND INITIAL CODE
# --------------------
# backup
# recovery
# ===============================================================================================
# PYMAKE PORT INITIAL CODE
# --------------------
# port translate function
portdefaultsourceconfig = pymakedefaultsourcefile
portdefaulttargetconfig = 'temporary-target.json'
portiniconfig = 'port.ini'
portinifile = os.path.join(sourceroot, "port.ini")
def init_portconf():
portconf = MyConfigParser()
portconf.read(portinifile)
if (not portconf.has_section('port')):
portconf.add_section('port')
portconf.write(open(portinifile, 'w'))
if (not portconf.has_option('port', 'sourceroot')):
portconf.set('port', 'sourceroot', sourceroot)
portconf.write(open(portinifile, 'w'))
if (not portconf.has_option('port', 'sourceconfig')):
portconf.set('port', 'sourceconfig', portdefaultsourceconfig)
portconf.write(open(portinifile, 'w'))
if (not portconf.has_option('port', 'targetroot')):
portconf.set('port', 'targetroot', sourceroot)
portconf.write(open(portinifile, 'w'))
if (not portconf.has_option('port', 'targetconfig')):
portconf.set('port', 'targetconfig', portdefaulttargetconfig)
portconf.write(open(portinifile, 'w'))
# print (portinifile)
# print ("sourceroot :", portconf['port']['sourceroot'])
# print ("sourceconfig:", portconf['port']['sourceconfig'])
# print ("targetroot :", portconf['port']['targetroot'])
# print ("targetconfig:", portconf['port']['targetconfig'])
return portconf, portinifile
def init_portconfig(portconf=MyConfigParser()):
portsourceconfigfile = os.path.join(portconf['port']['sourceroot'], portconf['port']['sourceconfig'])
porttargetconfigfile = os.path.join(portconf['port']['targetroot'], portconf['port']['targetconfig'])
d_temp = {
"path-assemblage": {
},
"environ": {
"default": {
"path+": [
]
},
"current": "default"
},
"command": {
}
}
if (not os.path.exists(portsourceconfigfile)):
writeJsonData(portsourceconfigfile, d_temp)
if (not os.path.exists(porttargetconfigfile)):
writeJsonData(porttargetconfigfile, d_temp)
srcsize = os.path.getsize(portsourceconfigfile)
tarsize = os.path.getsize(porttargetconfigfile)
if (srcsize < 166):
writeJsonData(portsourceconfigfile, d_temp)
if (tarsize < 166):
writeJsonData(porttargetconfigfile, d_temp)
portconfig = readJsonData(portsourceconfigfile)
porttargetconfig = readJsonData(porttargetconfigfile)
# hard
if (portconfig.__contains__("path-assemblage") is False):
portconfig['path-assemblage'] = {}
writeJsonData(portsourceconfigfile, portconfig)
if (portconfig.__contains__("environ") is False):
portconfig['environ'] = {}
writeJsonData(portsourceconfigfile, portconfig)
if (portconfig.__contains__("command") is False):
portconfig['command'] = {}
writeJsonData(portsourceconfigfile, portconfig)
# soft
# if(portconfig['environ'].__contains__("default") is False):
# portconfig['environ']['default']={"path+":[]}
# writeJsonData(portsourceconfigfile, portconfig)
# if(portconfig['environ']['default'].__contains__("path+") is False):
# portconfig['environ']['default']['path+']=[]
# writeJsonData(portsourceconfigfile, portconfig)
# if(portconfig['environ'].__contains__("current") is False):
# portconfig['environ']['current']='default'
# writeJsonData(portsourceconfigfile, portconfig)
# hard
if (porttargetconfig.__contains__("path-assemblage") is False):
porttargetconfig['path-assemblage'] = {}
writeJsonData(porttargetconfigfile, porttargetconfig)
if (porttargetconfig.__contains__("environ") is False):
porttargetconfig['environ'] = {}
writeJsonData(porttargetconfigfile, porttargetconfig)
if (porttargetconfig.__contains__("command") is False):
porttargetconfig['command'] = {}
writeJsonData(porttargetconfigfile, porttargetconfig)
# soft
order_of_keys = porttargetconfig['environ'].keys()
list_of_tuples = [key for key in order_of_keys]
if (list_of_tuples.__len__() < 2):
if (porttargetconfig['environ'].__contains__("default") is False):
porttargetconfig['environ']['default'] = {"path+": []}
writeJsonData(porttargetconfigfile, porttargetconfig)
if (porttargetconfig['environ']['default'].__contains__("path+") is False):
porttargetconfig['environ']['default']['path+'] = []
writeJsonData(porttargetconfigfile, porttargetconfig)
if (porttargetconfig['environ'].__contains__("current") is False):
porttargetconfig['environ']['current'] = 'default'
writeJsonData(porttargetconfigfile, porttargetconfig)
# move 'current' to be last key
order_of_keys = porttargetconfig['environ'].keys()
list_of_tuples = [key for key in order_of_keys]
# print(order_of_keys)
# print(list_of_tuples)
# print(list_of_tuples[-1])
if (list_of_tuples[-1] != 'current'):
# print(".....")
current_var = porttargetconfig['environ']['current']
porttargetconfig['environ'].__delitem__('current')
porttargetconfig['environ']['current'] = current_var
writeJsonData(porttargetconfigfile, porttargetconfig)
return portconfig, porttargetconfig
# initialize when need port function? no case.
portconf, temp_var = init_portconf()
init_portconfig(portconf)
# port translate
# set this command here .
# program
# ===============================================================================================
# PYMAKE DEBUG INITIAL CODE
# --------------------
# debug.
debugini = sourceroot + os.path.sep + "debug.ini"
debugconf = MyConfigParser()
debugconf.read(debugini)
if (not debugconf.has_section('debug')):
debugconf.add_section('debug')
debugconf.write(open(debugini, 'w'))
if (not debugconf.has_option('debug', 'switch')):
debugconf.set('debug', 'switch', '0')
debugconf.write(open(debugini, 'w'))
debugswitch = debugconf['debug']['switch']
if (debugswitch != '0' and debugswitch != '1'):
debugswitch = '0'
debugconf.set('debug', 'switch', debugswitch)
debugconf.write(open(debugini, 'w'))
# debug
# ===============================================================================================
# PYMAKE SOURCE CONFIG INITIAL CODE
# --------------------
config = readJsonData(sourceconfigfile)
# print(config)
def check_config():
# hard
if (config.__contains__("path-assemblage") is False):
config['path-assemblage'] = {}
writeJsonData(sourceconfigfile, config)
if (config.__contains__("environ") is False):
config['environ'] = {}
writeJsonData(sourceconfigfile, config)
if (config.__contains__("command") is False):
config['command'] = {}
writeJsonData(sourceconfigfile, config)
# soft
# if(portconfig['environ'].__contains__("default") is False):
# portconfig['environ']['default']={"path+":[]}
# writeJsonData(portsourceconfigfile, portconfig)
# if(portconfig['environ']['default'].__contains__("path+") is False):
# portconfig['environ']['default']['path+']=[]
# writeJsonData(portsourceconfigfile, portconfig)
# if(portconfig['environ'].__contains__("current") is False):
# portconfig['environ']['current']='default'
# writeJsonData(portsourceconfigfile, portconfig)
# soft
order_of_keys = config['environ'].keys()
list_of_tuples = [key for key in order_of_keys]
if (list_of_tuples.__len__() < 2):
if (config['environ'].__contains__("default") is False):
config['environ']['default'] = {"path+": []}
writeJsonData(sourceconfigfile, config)
if (config['environ']['default'].__contains__("path+") is False):
config['environ']['default']['path+'] = []
writeJsonData(sourceconfigfile, config)
if (config['environ'].__contains__("current") is False):
config['environ']['current'] = 'default'
writeJsonData(sourceconfigfile, config)
# move 'current' to be last key
order_of_keys = config['environ'].keys()
list_of_tuples = [key for key in order_of_keys]
# print(order_of_keys)
# print(list_of_tuples)
# print(list_of_tuples[-1])
if (list_of_tuples[-1] != 'current'):
# print(".....")
current_var = config['environ']['current']
config['environ'].__delitem__('current')
config['environ']['current'] = current_var
writeJsonData(sourceconfigfile, config)
return
check_config()
# ===============================================================================================
# PYMAKE IMPORT COMMAND INITIAL CODE
# --------------------
# import command
# set
# set
# get
# ===============================================================================================
# PYMAKE SOURCE RAW CONFIG INITIAL CODE
# --------------------
# record system environ
pymakesystemenviron = copy.deepcopy(os.environ)
### config -> raw config
rawconfig = copy.deepcopy(config)
# print ( config )
# print ( rawconfig )
# replace path
for (key, value) in rawconfig["path-assemblage"].items():
# print (key) #...
startpos = 0
while (True):
# print (startpos)
index = value.find('${', startpos)
if (index == -1):
break
index2 = value.find('}', index)
startpos = index2
key_replace = value[index:index2 + 1]
# print ( key0 ) #${...}
key_from = key_replace.split('{')[1].split('}')[0].strip()
# print ( key1 ) #...
for (find_key, find_value) in rawconfig["path-assemblage"].items():
if (key == find_key):
break
if (find_key == key_from):
rawconfig["path-assemblage"][key] = rawconfig["path-assemblage"][key].replace(
key_replace, rawconfig["path-assemblage"][key_from])
# print("xxx %s" % rawconfig["path-assemblage"][key])
break
# NO! ignore [in command, has various interpretations]
# for (find_key, find_value) in pymakesystemenviron.items():
# if (key == find_key):
# break
# if (str(find_key).lower() == 'path'):
# continue
# if (find_key == key_from):
# rawconfig["path-assemblage"][key] = rawconfig["path-assemblage"][key].replace(
# key_replace, pymakesystemenviron[key_from])
# # print("xxx %s" % rawconfig["path-assemblage"][key])
# break
# fix windows platform path sep
# but no nessesary
plat = getplatform()
if (plat == "Windows"):
""
# rawconfig["path-assemblage"][key] = rawconfig["path-assemblage"][key].replace('/', os.path.sep)
# replace env
# from path var env
for current_var in rawconfig["environ"].keys():
if (current_var == "current"):
continue
# replace path+
step = 0
for value in rawconfig["environ"][current_var]['path+']:
startpos = 0
while (True):
# print (startpos)
# print (value)
index = value.find('${', startpos)
if (index == -1):
break
index2 = value.find('}', index)
startpos = index2
key_replace = value[index:index2 + 1]
# print ( key0 ) #${...}
key_from = key_replace.split('{')[1].split('}')[0].strip()
# print ( key1 ) #...
for (find_key, find_value) in rawconfig["path-assemblage"].items():
if (find_key == key_from):
rawconfig["environ"][current_var]['path+'][step] = rawconfig["environ"][current_var]['path+'][step].replace(
key_replace, rawconfig["path-assemblage"][key_from])
break
step += 1
for (key, value) in rawconfig["environ"][current_var].items():
# print (key) #...
if (key == "path+"):
continue
startpos = 0
while (True):
# print (startpos)
index = value.find('${', startpos)
if (index == -1):
break
index2 = value.find('}', index)
startpos = index2
key_replace = value[index:index2 + 1]
# print ( key0 ) #${...}
key_from = key_replace.split('{')[1].split('}')[0].strip()
# print ( key1 ) #...
for (find_key, find_value) in rawconfig["path-assemblage"].items():
if (find_key == key_from):
rawconfig["environ"][current_var][key] = rawconfig["environ"][current_var][key].replace(
key_replace, rawconfig["path-assemblage"][key_from])
break
for (find_key, find_value) in rawconfig["environ"][current_var].items():
if (key == find_key):
break
if (find_key == key_from):
rawconfig["environ"][current_var][key] = rawconfig["environ"][current_var][key].replace(
key_replace, rawconfig["environ"][current_var][key_from])
break
# replace cmd
# from path env
for (cmd, stream) in rawconfig["command"].items():
# print (key) #...
step = 0
for value in stream:
startpos = 0
while (True):
# print (startpos)
# print (value)
index = value.find('${', startpos)
if (index == -1):
break
index2 = value.find('}', index)
startpos = index2
key_replace = value[index:index2 + 1]
# print ( key0 ) #${...}
key_from = key_replace.split('{')[1].split('}')[0].strip()
# print ( key1 ) #...
for (find_key, find_value) in rawconfig["path-assemblage"].items():
if (find_key == key_from):
rawconfig['command'][cmd][step] = rawconfig['command'][cmd][step].replace(
key_replace, rawconfig["path-assemblage"][key_from])
break
current_env_var = rawconfig["environ"]["current"]
for (find_key, find_value) in rawconfig["environ"][current_env_var].items():
if (find_key == key_from):
rawconfig['command'][cmd][step] = rawconfig['command'][cmd][step].replace(
key_replace, rawconfig["environ"][current_env_var][key_from])
break
step += 1
# raw path function, parse custom path tuple
def raw_path(pathgroup0):
pathgroup = copy.deepcopy(pathgroup0)
# replace path
for (key, value) in enumerate(pathgroup):
# print (key) #...
startpos = 0
while (True):
# print (startpos)
index = value.find('${', startpos)
if (index == -1):
break
index2 = value.find('}', index)
startpos = index2
key_replace = value[index:index2 + 1]
# print ( key0 ) #${...}
key_from = key_replace.split('{')[1].split('}')[0].strip()
# print ( key1 ) #...
for (find_key, find_value) in rawconfig["path-assemblage"].items():
if (key == find_key):
break
if (find_key == key_from):
pathgroup[key] = pathgroup[key].replace(key_replace, rawconfig["path-assemblage"][key_from])
# print("xxx %s" % pathgroup[key])
break
return pathgroup
# custom command function
# custom command stream from rawconfig
def raw_command(env_name=None):
command_dict = copy.deepcopy(config['command'])
# replace cmd
# from path env
for (cmd, stream) in command_dict.items():
# print (key) #...
step = 0
for value in stream:
startpos = 0
while (True):
# print (startpos)
# print (value)
index = value.find('${', startpos)
if (index == -1):
break
index2 = value.find('}', index)
startpos = index2
key_replace = value[index:index2 + 1]
# print ( key0 ) #${...}
key_from = key_replace.split('{')[1].split('}')[0].strip()
# print ( key1 ) #...
for (find_key, find_value) in rawconfig["path-assemblage"].items():
if (find_key == key_from):
command_dict[cmd][step] = command_dict[cmd][step].replace(
key_replace, rawconfig["path-assemblage"][key_from])
break
current_env_var = env_name
if (env_name is None):
current_env_var = config["environ"]["current"]
for (find_key, find_value) in rawconfig["environ"][current_env_var].items():
if (find_key == key_from):
command_dict[cmd][step] = command_dict[cmd][step].replace(
key_replace, rawconfig["environ"][current_env_var][key_from])
break
step += 1
return command_dict
# custom string dict -> raw dict
def raw_string(pathgroup0, env_name=None):
pathgroup = {k: v for k, v in pathgroup0.items()}
# print(pathgroup)
dict0 = {k: v for k, v in rawconfig['path-assemblage'].items()}
dict1 = {}
current_env = env_name
if (current_env == "current"):
current_env = rawconfig['environ']['current']
if (env_name is not None):
dict1 = {k: v for k, v in rawconfig['environ'][current_env].items()}
dict2 = {k: v for k, v in os.environ.items()}
# replace path
for (key, value) in pathgroup.items():
# print (key, value) #...
if (instanceof(value) != 'str'):
continue
if (dict0.__contains__(value) is True):
pathgroup[key] = dict0[value]
# print(pathgroup[key])
continue
if (dict2.__contains__(value) is True):
pathgroup[key] = dict2[value]
continue
if (dict1.__contains__(value) is True):
pathgroup[key] = dict1[value]
continue
startpos = 0
while (True):
# print (startpos)
index = value.find('${', startpos)
if (index == -1):
break
index2 = value.find('}', index)
startpos = index2
key_replace = value[index:index2 + 1]
# print ( key0 ) #${...}
key_from = key_replace.split('{')[1].split('}')[0].strip()
# print ( key1 ) #...
for (find_key, find_value) in dict0.items():
# print("%-30s, %-30s, %-30s, path-assemblage" % (key, key_from, find_key))
if (key == find_key):
break
# if (find_key == 'path+'):
# continue
# if (find_key == "path"):
# continue
if (find_key == key_from):
pathgroup[key] = pathgroup[key].replace(key_replace, dict0[key_from])
# print("path-assemblage %s" % pathgroup[key])
break
for (find_key, find_value) in dict2.items():
# print("%-30s, %-30s, %-30s, system env" % (key, key_from, find_key))
if (key == find_key):
break
# if (find_key == 'path+'):
# continue
if (find_key == "path"):
continue
if (find_key == key_from):
pathgroup[key] = pathgroup[key].replace(key_replace, dict2[key_from])
# print("system env %s" % pathgroup[key])
break
for (find_key, find_value) in dict1.items():
# print("%-30s, %-30s, %-30s, separate env" % (key, key_from, find_key))
if (key == find_key):
break
if (find_key == 'path+'):
continue
# if (find_key == "path"):
# continue
if (find_key == key_from):
pathgroup[key] = pathgroup[key].replace(key_replace, dict1[key_from])
# print("separate env %s" % pathgroup[key])
break
return pathgroup
# custom string dict -> raw dict [ignore case]
def raw_string1(pathgroup0, env_name=None):
# pathgroup = {k: v.lower() for k, v in pathgroup0.items()}
pathgroup1 = {k: v for k, v in pathgroup0.items()}
# print(pathgroup)
dict0 = {k.lower(): v for k, v in rawconfig['path-assemblage'].items()}
dict1 = {}
current_env = env_name
if (current_env == "current"):
current_env = rawconfig['environ']['current']
if (env_name is not None):
dict1 = {k.lower(): v for k, v in rawconfig['environ'][current_env].items()}
dict2 = {k.lower(): v for k, v in os.environ.items()}
# replace path
for (key, value) in pathgroup0.items():
# print (key, value) #...
if (instanceof(value) != 'str'):
continue
if (dict0.__contains__(value.lower()) is True):
pathgroup1[key] = dict0[value.lower()]
# print(pathgroup1[key])
continue
if (dict2.__contains__(value.lower()) is True):
pathgroup1[key] = dict2[value.lower()]
continue
if (dict1.__contains__(value.lower()) is True):
pathgroup1[key] = dict1[value.lower()]
continue
startpos = 0
while (True):
# print (startpos)
index = value.find('${', startpos)
if (index == -1):
break
index2 = value.find('}', index)
startpos = index2
key_replace = value[index:index2 + 1]
# print ( key0 ) #${...}
key_from = key_replace.split('{')[1].split('}')[0].strip()
# print ( key1 ) #...
for (find_key, find_value) in dict0.items():
# print("%-30s, %-30s, %-30s, path-assemblage" % (key, key_from, find_key))
if (key.lower() == find_key):
break
# if (find_key == 'path+'):
# continue
# if (find_key == "path"):
# continue
if (find_key == key_from.lower()):
pathgroup1[key] = pathgroup1[key].replace(key_replace, key_replace.lower())
pathgroup1[key] = pathgroup1[key].replace(key_replace.lower(), dict0[key_from.lower()])
# print("path-assemblage %s" % pathgroup1[key])
break
for (find_key, find_value) in dict2.items():
# print("%-30s, %-30s, %-30s, system env" % (key, key_from, find_key))
if (key.lower() == find_key):
break
# if (find_key == 'path+'):
# continue
if (find_key == "path"):
continue
if (find_key == key_from.lower()):
pathgroup1[key] = pathgroup1[key].replace(key_replace, key_replace.lower())
pathgroup1[key] = pathgroup1[key].replace(key_replace.lower(), dict2[key_from.lower()])
# print("system env %s" % pathgroup1[key])
break
for (find_key, find_value) in dict1.items():
# print("%-30s, %-30s, %-30s, separate env" % (key, key_from, find_key))
if (key.lower() == find_key):
break
if (find_key == 'path+'):
continue
# if (find_key == "path"):
# continue
if (find_key == key_from.lower()):
pathgroup1[key] = pathgroup1[key].replace(key_replace, key_replace.lower())
pathgroup1[key] = pathgroup1[key].replace(key_replace.lower(), dict1[key_from.lower()])
# print("separate env %s" % pathgroup1[key])
break
return pathgroup1
# which command [internal]
def which_command(env_name=None, name='', postfix=[]):
if (name is None or name == ''):
return None
# get python command.
pycmd = name
# get path ext
pathext = []
pathext.append('')
pathext.extend(postfix)
plat = getplatform()
if (plat == "Windows"):
pathext.extend(os.environ['PATHEXT'].split(os.path.pathsep))
else:
pathext.extend(['.sh', '.out', '.cmd'])
# find in current path
specialpath = [
startupworkdirectory,
os.getcwd()
]
list0 = copy.deepcopy(specialpath)
list0.reverse()
for path0a in list0:
for path0 in path0a.split(os.path.pathsep):
path0 = path0.strip()
# print(path0)
path1 = ''
for pext0 in pathext:
path1 = path0 + os.path.sep + pycmd + pext0
if (os.path.isfile(path1)):
if (plat == "Windows"):
return path1.replace('/', '\\')
else:
return path1.replace('\\', '/')
if (env_name is not None):
if (rawconfig['environ'].__contains__(env_name) is False):
print("Fault Error! .json file is broken, env %s is losing!" % env_name)
return None
# find in separate env
list0 = copy.deepcopy(rawconfig['environ'][env_name]['path+'])
list0.reverse()
for path0a in list0:
for path0 in path0a.split(os.path.pathsep):
path0 = path0.strip()
# print(path0)
path1 = ''
for pext0 in pathext:
path1 = path0 + os.path.sep + pycmd + pext0
if (os.path.isfile(path1)):
if (plat == "Windows"):
return path1.replace('/', '\\')
else:
return path1.replace('\\', '/')
# find in env. [custom+, local+, system]
env = os.environ
# for pathA in env['PATH'].split(os.path.pathsep):
# print(pathA)
list0 = copy.deepcopy(env['PATH'].split(os.path.pathsep))
# list0.reverse()
for path0a in list0:
for path0 in path0a.split(os.path.pathsep):
path0 = path0.strip()
# print(path0)
path1 = ''
for pext0 in pathext:
path1 = path0 + os.path.sep + pycmd + pext0
# print("[%s]" % path1)
if (os.path.isfile(path1)):
if (plat == "Windows"):
return path1.replace('/', '\\')
else:
return path1.replace('\\', '/')
return None
# which file [internal]
def which_file(env_name=None, name='', postfix=[]):
if (name is None or name == ''):
return None
# get python command.
pycmd = name
# get path ext
pathext = []
pathext.append('')
pathext.extend(postfix)
plat = getplatform()
if (plat == "Windows"):
pathext.extend([])
else:
pathext.extend([])
# find in current path
specialpath = [
startupworkdirectory,
os.getcwd()
]
list0 = copy.deepcopy(specialpath)
list0.reverse()
for path0a in list0:
for path0 in path0a.split(os.path.pathsep):
path0 = path0.strip()
# print(path0)
path1 = ''
for pext0 in pathext:
path1 = path0 + os.path.sep + pycmd + pext0
if (os.path.isfile(path1)):
if (plat == "Windows"):
return path1.replace('/', '\\')
else:
return path1.replace('\\', '/')
if (env_name is not None):
if (rawconfig['environ'].__contains__(env_name) is False):
print("Fault Error! .json file is broken, env %s is losing!" % env_name)
return None
# find in separate env
list0 = copy.deepcopy(rawconfig['environ'][env_name]['path+'])
list0.reverse()
for path0a in list0:
for path0 in path0a.split(os.path.pathsep):
path0 = path0.strip()
# print(path0)
path1 = ''
for pext0 in pathext:
path1 = path0 + os.path.sep + pycmd + pext0
if (os.path.isfile(path1)):
if (plat == "Windows"):
return path1.replace('/', '\\')
else:
return path1.replace('\\', '/')
# find in env. [custom+, local+, system]
env = os.environ
# for pathA in env['PATH'].split(os.path.pathsep):
# print(pathA)
list0 = copy.deepcopy(env['PATH'].split(os.path.pathsep))
# list0.reverse()
for path0a in list0:
for path0 in path0a.split(os.path.pathsep):
path0 = path0.strip()
# print(path0)
path1 = ''
for pext0 in pathext:
path1 = path0 + os.path.sep + pycmd + pext0
# print("[%s]" % path1)
if (os.path.isfile(path1)):
if (plat == "Windows"):
return path1.replace('/', '\\')
else:
return path1.replace('\\', '/')
return None
# pymake expand command-line.
# current_var = args['<env-name>']
# args = raw_string(args, current_var)
# print(args)
# for (k, v) in args.items():
# if(isinstance(v, str)):
# print(k, v)
# return
# system command function
# system command stream from rawconfig path-assemblage
def raw_command_system():
command_dict = copy.deepcopy(config['command'])
# replace cmd
# from path env
for (cmd, stream) in command_dict.items():
# print (key) #...
step = 0
for value in stream:
startpos = 0
while (True):
# print (startpos)
# print (value)
index = value.find('${', startpos)
if (index == -1):
break
index2 = value.find('}', index)
startpos = index2
key_replace = value[index:index2 + 1]
# print ( key0 ) #${...}
key_from = key_replace.split('{')[1].split('}')[0].strip()
# print ( key1 ) #...
for (find_key, find_value) in rawconfig["path-assemblage"].items():
if (find_key == key_from):
command_dict[cmd][step] = command_dict[cmd][step].replace(
key_replace, rawconfig["path-assemblage"][key_from])
break
step += 1
return command_dict
# .bat .sh, windows, unix, system
def createCmdList06(env_name=None, local=True, list0=[], params0=[]):
cmd_list = []
name = uuid.uuid4().__str__()
name = name.split('-')[0]
# print (name)
plat = getplatform()
if (plat == "Windows"):
cmd_status = "echo pymake-command-status:%ERRORLEVEL%"
cmd_sep = '&'
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_exit = 'exit /b %ERRORLEVEL%'
cmd_suffix = ".bat"
cmd_header = "@echo off"
cmd_call = "call "
# window close echo, close promot
cmd_list.append(cmd_header)
# os.system("type env_effect.bat > cmd_exec.bat")
if (env_name != None):
cmd_list.append("call %s_effect.bat" % name)
else:
cmd_status = "echo pymake-command-status:$?"
cmd_sep = ';'
cmd_suffix = ".sh"
cmd_exit = 'exit $?'
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash"
cmd_call = "./"
cmd_list.append(cmd_header)
if (env_name != None):
cmd_list.append("source %s_effect.sh" % name)
params_string = ""
for param in params0:
if (str(param).__contains__(' ')):
params_string += '"' + param + '"' + ' '
else:
params_string += param + ' '
# print(params_string)
if (local is True):
for cmd in list0:
cmd_list.append(cmd)
else:
for cmd in list0:
if (str(cmd).__contains__(' ')):
pycmd = which_command(env_name, str(cmd))
# print(pycmd)
if (pycmd is not None and os.path.isfile(pycmd)):
cmd_list.append('"' + cmd + '"' + ' ' + params_string)
else:
cmd_list.append(cmd + ' ' + params_string)
else:
cmd_list.append(cmd + ' ' + params_string)
# append exit 0
cmd_list.append(cmd_exit)
# print( cmd_list )
cmd_execute = name + "_exec" + cmd_suffix
with open(cmd_execute, "w", encoding=cmd_codec) as f:
for line in cmd_list:
f.write(line + cmd_return)
# print(cmd_execute)
if (debugswitch == '1'):
print("IN: execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_execute)
cmd_list.clear()
if (plat == "Windows"):
cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("call " + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("call " + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
else:
# cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("./" + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("./" + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
cmd_list.append(cmd_exit)
# print (cmd_list)
if (debugswitch == '1'):
print("CMD: call execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
return cmd_list, name
# system export function
def system_env_export(env_name=None, file_name=None):
if (env_name == None):
return env_name, '', ''
# select env
current_var = rawconfig['environ']['current']
if (env_name is not None):
current_var = env_name
dict0 = copy.deepcopy(rawconfig['environ'][current_var])
plat = getplatform()
if (plat == "Windows"):
cmd_suffix = ".bat"
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
cmd_return = "\n"
cmd_header = "@echo off" + cmd_return
env_set = 'set '
else:
cmd_suffix = ".sh"
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash" + cmd_return
env_set = 'export '
# export effect env
cmd_effect = 'env'
if (file_name is not None):
cmd_effect = file_name
cmd_effect += '_effect' + cmd_suffix
# export path
lines = ""
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=' + key + os.path.pathsep + '%PATH%' + cmd_return)
else:
lines += (env_set + 'PATH="' + key + '"' + os.path.pathsep + '$PATH' + cmd_return)
# export var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += (env_set + key + '=' + value + cmd_return)
else:
lines += (env_set + key + '=\"' + value + '\"' + cmd_return)
with open(cmd_effect, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
# export unset env
cmd_unset = 'env'
if (file_name is not None):
cmd_unset = file_name
cmd_unset += '_unset' + cmd_suffix
# export unset path
lines = ""
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=%PATH:' + key + ';=%' + cmd_return)
else:
lines += (env_set + 'PATH=$(' + 'echo ${PATH//' + key.replace('/', '\/') + ':/})' + cmd_return)
# export unset var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += ('set ' + key + '=' + cmd_return)
else:
lines += ('unset ' + key + cmd_return)
with open(cmd_unset, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_effect)
os.system("chmod +x " + cmd_unset)
# return file name
return current_var, cmd_effect, cmd_unset
# ===============================================================================================
# PYMAKE SYSTEM COMMAND INITIAL CODE
# --------------------
# print(args)
# system ccvp
# outport command
# get open path's cmd list
def open_command(pathlist0, env_name=None):
pathgroup0 = {}
for (k, v) in enumerate(pathlist0):
pathgroup0[str('-pymake-open-p%d' % k)] = str(v)
cmd_list = []
pathgroup1 = {}
# if(args['-i'] or args['--ignorecase'] is True):
# pathgroup1 = raw_string1(pathgroup0, env_name)
# else:
# pathgroup1 = raw_string(pathgroup0, env_name)
pathgroup1 = raw_string1(pathgroup0, env_name)
plat = getplatform()
for (k, v) in pathgroup1.items():
path0 = str(v)
pathslist = path0.split(os.path.pathsep)
while (pathslist.__contains__('')):
pathslist.remove('')
# print(pathslist)
for path0 in pathslist:
cmd0 = ''
if (plat == "Windows"):
if (path0.__contains__(' ')):
cmd0 = 'start "" ' + '"%s"' % path0
else:
cmd0 = "start " + path0
elif (plat == "Darwin"):
if (path0.__contains__(' ')):
cmd0 = 'open ' + '"%s"' % path0
else:
cmd0 = "open " + path0
else:
if (path0.__contains__(' ')):
cmd0 = 'xdg-open ' + '"%s" ' % path0 + ">/dev/null 2>&1"
else:
cmd0 = "xdg-open " + '%s ' % path0 + ">/dev/null 2>&1"
cmd_list.append(cmd0)
return cmd_list
# print(args)
# open command
# ===============================================================================================
# PYMAKE LOCAL ENV INITIAL CODE
# --------------------
# pymake local const variable.
localini = sourceroot + os.path.sep + "local.ini"
localconf = MyConfigParser()
localconf.read(localini)
if (not localconf.has_section('local')):
localconf.add_section('local')
localconf.write(open(localini, 'w'))
if (not localconf.has_section('path+')):
localconf.add_section('path+')
localconf.write(open(localini, 'w'))
if (not localconf.has_section('variable')):
localconf.add_section('variable')
localconf.write(open(localini, 'w'))
# status readonly
# if( not localconf.has_option('local', 'status') ):
# localconf.set('local', 'status', 'readonly')
# localconf.write(open(localini, 'w'))
# localswitch = localconf['local']['status']
# if(localswitch != 'readonly'):
# localswitch = 'readonly'
# localconf.set('local', 'status', localswitch)
# localconf.write(open(localini, 'w'))
# switch [1, default]
if (not localconf.has_option('local', 'switch')):
localconf.set('local', 'switch', '1')
localconf.write(open(localini, 'w'))
localswitch = localconf['local']['switch']
if (localswitch != '0' and localswitch != '1'):
localswitch = '1'
localconf.set('local', 'switch', localswitch)
localconf.write(open(localini, 'w'))
localenv = {}
localenv['path+'] = []
# set into env [no effect to system environ]
while (True):
if (int(localswitch) == 0):
break
env = os.environ
localenv['PYMAKEDEFAULTSOURCEROOT'] = pymakedefaultsourceroot
localenv['PYMAKEDEFAULTSOURCECONFIG'] = pymakedefaultsourcefile
localenv['PYMAKESOURCEFILE'] = sourceconfigfile
localenv['PYMAKESOURCEROOT'] = sourceroot
localenv['PYMAKESOURCECONFIG'] = sourcefile
localenv['PYMAKEDEFAULTWORKROOT'] = defaultshellroot
localenv['PYMAKETHEREWORKROOT'] = customshellroot
localenv['PYMAKEHEREWORKROOT'] = startupworkdirectory
localenv['PYMAKEWORKROOT'] = shellroot
# localenv['PYMAKEWORKROOTTYPE'] = workroottype
if ((args.__contains__('here') or args.__contains__('hh')) and (args['here'] or args['hh'] is True)):
localenv['PYMAKEWORKROOT'] = startupworkdirectory
elif ((args.__contains__('there') or args.__contains__('tt')) and (args['there'] or args['tt'] is True)):
localenv['PYMAKEWORKROOT'] = customshellroot
elif ((args.__contains__('default') or args.__contains__('dd')) and (args['default'] or args['dd'] is True)):
localenv['PYMAKEWORKROOT'] = defaultshellroot
if (args.__contains__('--workroot') and args['--workroot'] is not None):
if (os.path.isdir(args['--workroot'])
and os.path.isabs(args['--workroot'])):
localenv['PYMAKEWORKROOT'] = args['--workroot']
# os.chdir(args['--workroot'])
else:
print('please input a legal work root.')
return
localenv['PYMAKEPROGRAM'] = pymakefile
localenv['PYMAKEPROGRAMROOT'] = pymakefileroot
localenv['PYMAKEPROGRAMFILE'] = pymakefilename
localenv['PYMAKEPROGRAMCONFIGURE'] = os.path.realpath(pymakeconfigureini)
localenv['PYMAKEPROGRAMCONFIGUREROOT'] = os.path.split(os.path.realpath(pymakeconfigureini))[0]
localenv['PYMAKEPROGRAMCONFIGUREFILE'] = os.path.split(os.path.realpath(pymakeconfigureini))[1]
if (getplatform() == 'Windows'):
localenv['PYMAKEINSTALLROOT'] = env['windir']
else:
localenv['PYMAKEINSTALLROOT'] = '/usr/local/bin'
localenv['path+'].append(localenv['PYMAKEPROGRAMROOT'])
localenv['path+'].append(localenv['PYMAKESOURCEROOT'])
localenv['path+'].append(localenv['PYMAKEDEFAULTWORKROOT'])
# if(localenv['path+'].__contains__(localenv['PYMAKETHEREWORKROOT']) is False):
localenv['path+'].append(localenv['PYMAKETHEREWORKROOT'])
# if(localenv['path+'].__contains__(localenv['PYMAKEHEREWORKROOT']) is False):
localenv['path+'].append(localenv['PYMAKEHEREWORKROOT'])
# if(localenv['path+'].__contains__(localenv['PYMAKEWORKROOT']) is False):
localenv['path+'].append(localenv['PYMAKEWORKROOT'])
# store to file
for (key, value) in enumerate(localenv["path+"]):
localconf.set('path+', str("%d" % key), value)
for (key, value) in localenv.items():
if (key == 'path+'):
continue
localconf.set('variable', key, value)
localconf.write(open(localini, 'w'))
# set into env
for (key) in localenv["path+"]:
env["PATH"] = key + os.path.pathsep + env["PATH"]
for (key, value) in localenv.items():
if (key == 'path+'):
continue
env[key] = value
# print(json.dumps(localenv, indent=4, sort_keys=False, ensure_ascii=False))
break
# local command
# ===============================================================================================
# PYMAKE CUSTOM ENV INITIAL CODE
# --------------------
# initial custom environ module
pymakecustomini = sourceroot + os.path.sep + "custom.ini"
customconf = MyConfigParser()
customconf.read(pymakecustomini)
if (not customconf.has_section('custom')):
customconf.add_section('custom')
customconf.write(open(pymakecustomini, 'w'))
if (not customconf.has_option('custom', 'switch')):
customconf.set('custom', 'switch', '1')
customconf.write(open(pymakecustomini, 'w'))
switch0 = customconf['custom']['switch']
if (switch0 != '0' and switch0 != '1'):
switch0 = '1'
customconf.set('custom', 'switch', switch0)
customconf.write(open(pymakecustomini, 'w'))
custompathfile = sourceroot + os.path.sep + "custom.path+.ini"
customenvfile = sourceroot + os.path.sep + "custom.var+.ini"
storecustompaths = []
storecustomvars = []
envcustomlistpaths = []
envcustomlistvars = {}
envcustomlistrawpaths = []
envcustomlistrawvars = {}
plat = getplatform()
cmd_codec = "utf8"
cmd_return = "\n"
if (plat == "Windows"):
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
else:
cmd_codec = "utf8"
cmd_return = "\n"
# custom environ
# user can use custom environ to effect pymake basic environment.
# it will effect every executing environment.
while (True):
if (int(switch0) == 0):
break
# print("open custom environ.")
# set custom path+ to env.
# print(sourceroot)
# print(shellroot)
# init file
# custompathfile = sourceroot + os.path.sep + "custom.path+.ini"
if (os.path.exists(custompathfile) is False):
with open(custompathfile, 'w', encoding=cmd_codec) as f:
''
# read all
custompaths = []
with open(custompathfile, 'r', encoding=cmd_codec) as f:
for l in f.readlines():
# important format
# l = l.strip()
while (l.endswith('\r') or l.endswith('\n') or l.endswith('\r\n')):
l = l.rstrip('\r\n')
l = l.rstrip('\n')
l = l.rstrip('\r')
# if(l == ''):
# continue
custompaths.append(l)
# while(custompaths.__contains__('') is True):
# custompaths.remove('')
# print(custompaths)
# print(os.linesep)
# for l in custompaths:
# print("AAAA:" + l)
# write back
# strip
storecustompaths = copy.deepcopy(custompaths)
for (i, l) in enumerate(storecustompaths):
# import format
l = l.strip()
storecustompaths[i] = l
# added by local, ignore
'''
# default [ fixed ]
# add pymake default source root to environ.
if (storecustompaths.__contains__(pymakedefaultsourceroot) is False):
storecustompaths.append(pymakedefaultsourceroot)
# add pymake default shell root to environ.
if (storecustompaths.__contains__(pymakedefaultshellroot) is False):
storecustompaths.append(pymakedefaultshellroot)
# default [ movable, follow user source root ]
# add user source root to environ.
if (sourceroot != pymakedefaultsourceroot and storecustompaths.__contains__(sourceroot) is False):
storecustompaths.append(sourceroot)
# add user shell root to environ.
if (customshellroot != defaultshellroot and storecustompaths.__contains__(customshellroot) is False):
storecustompaths.append(customshellroot)
if (startupworkdirectory != defaultshellroot and storecustompaths.__contains__(startupworkdirectory) is False):
storecustompaths.append(startupworkdirectory)
if (shellroot != defaultshellroot and storecustompaths.__contains__(shellroot) is False):
storecustompaths.append(shellroot)
'''
# clean repeat path [for store]
clean_list = []
temp_list = []
for l in storecustompaths:
if (l == ''):
continue
if (os.path.isabs(l) is False):
continue
if (temp_list.__contains__(str(l).replace('\\', '/').lower())):
clean_list.append(l)
continue
else:
temp_list.append(str(l).replace('\\', '/').lower())
# print(clean_list)
storecustompaths.reverse()
for l in clean_list:
if (storecustompaths.__contains__(l) is True):
storecustompaths.remove(l)
storecustompaths.reverse()
if (custompaths != storecustompaths):
with open(custompathfile, 'w', encoding=cmd_codec) as f:
for l in storecustompaths:
f.write(l + cmd_return)
# set into env
# raw
envcustompaths = copy.deepcopy(storecustompaths)
envcustomrawpaths = raw_path(envcustompaths)
# print(envcustompaths)
# print(envcustomrawpaths)
# envcustomlistpaths
for (key, l) in zip(envcustompaths, envcustomrawpaths):
if (l == ''):
continue
# print(os.path.isabs(l), l)
if (os.path.isabs(l) is False):
continue
envcustomlistpaths.append(key)
# clean illgal path
clean_list = []
for l in envcustomrawpaths:
if (l == ''):
clean_list.append(l)
continue
if (os.path.isabs(l) is False):
clean_list.append(l)
continue
# print(clean_list)
for l in clean_list:
if (envcustomrawpaths.__contains__(l) is True):
envcustomrawpaths.remove(l)
env = os.environ
for l in envcustomrawpaths:
env["PATH"] = l + os.path.pathsep + env["PATH"]
for l in envcustomrawpaths:
envcustomlistrawpaths.append(l)
# set custom env+ to env.
# customenvfile = sourceroot + os.path.sep + "custom.var+.ini"
# print(customenvfile)
# init
if (os.path.exists(customenvfile) is False):
with open(customenvfile, 'w', encoding=cmd_codec) as f:
''
# read all
customenvs = []
with open(customenvfile, 'r', encoding=cmd_codec) as f:
for l in f.readlines():
# important format
# l = l.strip()
while (l.endswith('\r') or l.endswith('\n') or l.endswith('\r\n')):
l = l.rstrip('\r\n')
l = l.rstrip('\n')
l = l.rstrip('\r')
# if(l == ''):
# continue
customenvs.append(l)
# write back
# strip
storecustomvars = copy.deepcopy(customenvs)
for (i, l) in enumerate(storecustomvars):
# important format
l = l.strip()
storecustomvars[i] = l
avarkeyvalue = "PYMAKEAUTHOR=T.D.R."
if (storecustomvars.__contains__(avarkeyvalue) is False):
storecustomvars.append(avarkeyvalue)
# clean repeat var [for store]
clean_list = []
temp_list = []
for l in storecustomvars:
if (l == ''):
continue
if (str(l).__contains__('=') is False):
continue
if (temp_list.__contains__(str(l).split('=')[0].strip().lower())):
clean_list.append(l)
continue
else:
temp_list.append(str(l).split('=')[0].strip().lower())
# print(clean_list)
storecustomvars.reverse()
for l in clean_list:
if (storecustomvars.__contains__(l) is True):
storecustomvars.remove(l)
storecustomvars.reverse()
if (storecustomvars != customenvs):
with open(customenvfile, 'w', encoding=cmd_codec) as f:
for l in storecustomvars:
f.write(l + cmd_return)
# set into env
# raw
envcustomvars = copy.deepcopy(storecustomvars)
envcustomrawvars = raw_path(envcustomvars)
# print(envcustomvars)
# print(envcustomrawvars)
for (key0, l) in zip(envcustomvars, envcustomrawvars):
if (l == ''):
continue
if (str(l).__contains__('=') is False):
continue
key = str(key0).split('=')[0].strip()
value = '='.join(str(key0).split('=')[1:]).strip()
envcustomlistvars[key] = value
# clean illgal var
clean_list = []
for l in envcustomrawvars:
if (l == ''):
clean_list.append(l)
continue
if (str(l).__contains__('=') is False):
clean_list.append(l)
continue
# print(clean_list)
for l in clean_list:
if (envcustomrawvars.__contains__(l) is True):
envcustomrawvars.remove(l)
env = os.environ
for l in envcustomrawvars:
key = str(l).split('=')[0].strip()
value = '='.join(str(l).split('=')[1:]).strip()
env[key] = value
for l in envcustomrawvars:
key = str(l).split('=')[0].strip()
value = '='.join(str(l).split('=')[1:]).strip()
envcustomlistrawvars[key] = value
break
# ===============================================================================================
# PYMAKE VC MODULE INITIAL CODE
# --------------------
# initial vc module
# record vc shell root.
vcroot = sourceroot + os.path.sep + "VCShell"
if (not os.path.exists(vcroot)):
os.mkdir(vcroot)
d_vc = {
'environ': {
}
}
pymakevcconfigfile = vcroot + os.path.sep + 'pymake-vc-command.json'
# print(pymakevcconfigfile)
if (not os.path.exists(pymakevcconfigfile)):
writeJsonData(pymakevcconfigfile, d_vc)
pymakevcdict = readJsonData(pymakevcconfigfile)
if (pymakevcdict.__contains__('environ') is False):
# print('Fault error: %s is broken, please delete it manully.' % pymakevcconfigfile)
# return
pymakevcdict['environ'] = {}
writeJsonData(pymakevcconfigfile, pymakevcdict)
# print(pymakevcdict)
# check command
def vc_createCmdList08(shellenvname=None, env_name=None, local=True, list0=[], params0=[]):
cmd_list = []
if (env_name is None):
env_name = rawconfig['environ']['current']
# print(env_name)
name = uuid.uuid4().__str__()
name = name.split('-')[0]
# print (name)
plat = getplatform()
if (plat == "Windows"):
cmd_status = "echo pymake-command-status:%ERRORLEVEL%"
cmd_sep = '&'
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_exit = 'exit /b %ERRORLEVEL%'
cmd_suffix = ".bat"
cmd_header = "@echo off"
cmd_call = "call "
# window close echo, close promot
cmd_list.append(cmd_header)
# os.system("type env_effect.bat > cmd_exec.bat")
cmd_list.append("call %s_effect.bat" % name)
if (shellenvname is not None):
cmd_list.append('call \"%s_effect%s\"' % (shellenvname, cmd_suffix))
else:
cmd_status = "echo pymake-command-status:$?"
cmd_sep = ';'
cmd_suffix = ".sh"
cmd_exit = 'exit $?'
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash"
cmd_call = "./"
cmd_list.append(cmd_header)
cmd_list.append("source %s_effect.sh" % name)
if (shellenvname is not None):
cmd_list.append('source \"%s_effect%s\"' % (shellenvname, cmd_suffix))
# print(params0)
params_string = ""
for param in params0:
# print(param)
if (str(param).__contains__(' ')):
params_string += '"' + param + '"' + ' '
else:
params_string += param + ' '
# print(params_string)
if (local is True):
for cmd in list0:
cmd_list.append(cmd)
else:
for cmd in list0:
if (str(cmd).__contains__(' ')):
pycmd = which_command(env_name, str(cmd))
# print(str(cmd))
# print(Fore.RED + "which command:", pycmd)
if (pycmd is not None and os.path.isfile(pycmd)):
cmd_list.append('"' + cmd + '"' + ' ' + params_string)
else:
cmd_list.append(cmd + ' ' + params_string)
else:
cmd_list.append(cmd + ' ' + params_string)
# append exit 0
cmd_list.append(cmd_exit)
# print( cmd_list )
cmd_execute = name + "_exec" + cmd_suffix
with open(cmd_execute, "w", encoding=cmd_codec) as f:
for line in cmd_list:
f.write(line + cmd_return)
# print(cmd_execute)
if (debugswitch == '1'):
print("IN: execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_execute)
cmd_list.clear()
if (plat == "Windows"):
cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("call " + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("call " + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
else:
# cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("./" + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("./" + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
cmd_list.append(cmd_exit)
# print (cmd_list)
if (debugswitch == '1'):
print("CMD: call execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
return cmd_list, name
def vc_powershell_createCmdList08(shellenvname=None, env_name=None, local=True, list0=[], params0=[]):
cmd_list = []
if (env_name is None):
env_name = rawconfig['environ']['current']
name = uuid.uuid4().__str__()
name = name.split('-')[0]
# print (name)
# plat = getplatform()
cmd_status = "echo pymake-command-status:$LASTEXITCODE"
cmd_sep = ';'
cmd_suffix = ".ps1"
cmd_suffix_powershell = cmd_suffix
cmd_exit = 'exit $LASTEXITCODE'
cmd_codec = 'ansi'
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash"
cmd_call = "./"
# cmd_list.append(cmd_header)
cmd_list.append("./%s_effect%s" % (name, cmd_suffix))
if (shellenvname is not None):
cmd_list.append('. \"%s_effect%s\"' % (shellenvname, cmd_suffix))
params_string = ""
for param in params0:
if (str(param).__contains__(' ')):
params_string += '"' + param + '"' + ' '
else:
params_string += param + ' '
# print(params_string)
if (local is True):
for cmd in list0:
cmd_list.append(cmd)
else:
# actually now has only one command.
for cmd in list0:
# warning: now pymake is in user setted workroot.
if (str(cmd).endswith(cmd_suffix_powershell)):
cmd_suffix_powershell = ''
powershellexecfile = ""
while (True):
# find in current path [+workroot]
powershellexecfile = os.getcwd() + os.path.sep + cmd + cmd_suffix_powershell
if (os.path.exists(powershellexecfile)):
break
powershellexecfile = startupworkdirectory + os.path.sep + cmd + cmd_suffix_powershell
if (os.path.exists(powershellexecfile)):
break
# find in .json environ
separateenvlistpath = os.path.pathsep.join(rawconfig['environ'][env_name]['path+'])
separateenvlistpath = separateenvlistpath.split(os.path.pathsep)
separateenvlistpath.reverse()
# for path0 in separateenvlistpath:
# print(path0)
find_flag = 0
for path0 in separateenvlistpath:
powershellexecfile = path0 + os.path.sep + cmd + cmd_suffix_powershell
if (os.path.exists(powershellexecfile)):
find_flag = 1
break
if (find_flag == 1):
break
# find in basic environ [+custom]
env = os.environ
find_flag = 0
for path0 in env["PATH"].split(os.path.pathsep):
powershellexecfile = path0 + os.path.sep + cmd + cmd_suffix_powershell
if (os.path.exists(powershellexecfile)):
find_flag = 1
break
if (find_flag == 1):
break
# none? a powershell command, or powershell command-line.
powershellexecfile = cmd
break
# print(powershellexecfile)
# wow
# cmd_list.append(powershellexecfile + ' ' + params_string)
if (str(powershellexecfile).__contains__(' ')):
if (os.path.isfile(powershellexecfile)):
powershellexecfile = powershellexecfile.replace('/', os.path.sep)
powershellexecfile = powershellexecfile.replace('\\', os.path.sep)
cmd_list.append(". \"%s\" @args" % powershellexecfile)
else:
cmd_list.append("%s" % powershellexecfile)
else:
if (os.path.isfile(powershellexecfile)):
powershellexecfile = powershellexecfile.replace('/', os.path.sep)
powershellexecfile = powershellexecfile.replace('\\', os.path.sep)
cmd_list.append(". %s @args" % powershellexecfile)
else:
cmd_list.append("%s" % powershellexecfile)
# append exit 0
cmd_list.append(cmd_exit)
# print( cmd_list )
cmd_execute = "" + name + "_exec" + cmd_suffix
with open(cmd_execute, "w", encoding=cmd_codec) as f:
for line in cmd_list:
f.write(line + cmd_return)
# print(cmd_execute)
if (debugswitch == '1'):
print("IN: execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
# if (plat == "Windows"):
# ""
# else:
# os.system("chmod +x " + cmd_execute)
cmd_list.clear()
cmd_list.append(cmd_call + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
cmd_list.append(cmd_exit)
# print (cmd_list)
if (debugswitch == '1'):
print("CMD: call execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
return cmd_list, name
def vc_python_createCmdList08(shellenvname=None, env_name=None, local=True, list0=[], params0=[]):
cmd_list = []
if (env_name is None):
env_name = rawconfig['environ']['current']
name = uuid.uuid4().__str__()
name = name.split('-')[0]
# print (name)
plat = getplatform()
if (plat == "Windows"):
cmd_status = "echo pymake-command-status:%ERRORLEVEL%"
cmd_sep = '&'
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_exit = 'exit /b %ERRORLEVEL%'
cmd_suffix = ".bat"
cmd_header = "@echo off"
cmd_call = "call "
# window close echo, close promot
cmd_list.append(cmd_header)
# os.system("type env_effect.bat > cmd_exec.bat")
cmd_list.append("call %s_effect.bat" % name)
if (shellenvname is not None):
cmd_list.append('call \"%s_effect%s\"' % (shellenvname, cmd_suffix))
else:
cmd_status = "echo pymake-command-status:$?"
cmd_sep = ';'
cmd_suffix = ".sh"
cmd_exit = 'exit $?'
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash"
cmd_call = "./"
cmd_list.append(cmd_header)
cmd_list.append("source %s_effect.sh" % name)
if (shellenvname is not None):
cmd_list.append('source \"%s_effect%s\"' % (shellenvname, cmd_suffix))
cmd_suffix_python = '.py'
cmd_codec_python = "utf8"
cmd_return_python = "\n"
params_string = ""
for param in params0:
if (str(param).__contains__(' ')):
params_string += '"' + param + '"' + ' '
else:
params_string += param + ' '
# print(params_string)
pythonexecfile = ''
if (local is True):
# fixed
pythonexecfile = name + '_exec' + cmd_suffix_python
with open(pythonexecfile, 'w', encoding=cmd_codec_python) as f:
for cmd in list0:
f.write(cmd + cmd_return_python)
# print(1, pythonexecfile)
else:
# actually now has only one command.
for cmd in list0:
# warning: now pymake is in user setted workroot.
if (str(cmd).endswith(cmd_suffix_python)):
cmd_suffix_python = ''
pythonexecfile = ""
while (True):
# find in current path [+workroot]
pythonexecfile = os.getcwd() + os.path.sep + cmd + cmd_suffix_python
# print(2, pythonexecfile)
if (os.path.exists(pythonexecfile)):
break
pythonexecfile = startupworkdirectory + os.path.sep + cmd + cmd_suffix_python
# print(2, pythonexecfile)
if (os.path.exists(pythonexecfile)):
break
# find in .json environ
separateenvlistpath = os.path.pathsep.join(rawconfig['environ'][env_name]['path+'])
separateenvlistpath = separateenvlistpath.split(os.path.pathsep)
separateenvlistpath.reverse()
# for path0 in separateenvlistpath:
# print(path0)
find_flag = 0
for path0 in separateenvlistpath:
pythonexecfile = path0 + os.path.sep + cmd + cmd_suffix_python
# print(2, pythonexecfile)
if (os.path.exists(pythonexecfile)):
find_flag = 1
break
if (find_flag == 1):
break
# find in basic environ [custom+]
env = os.environ
find_flag = 0
for path0 in env["PATH"].split(os.path.pathsep):
pythonexecfile = path0 + os.path.sep + cmd + cmd_suffix_python
# print(2, pythonexecfile)
if (os.path.exists(pythonexecfile)):
find_flag = 1
break
if (find_flag == 1):
break
# none? a python command, or python command-line.
pythonexecfile = cmd
break
# print(2, pythonexecfile)
# cmd_list.append(pythonexecfile + ' ' + params_string)
# print params.
# print(3, pythonexecfile)
# get python command.
pycmd = ''
if (plat == "Windows"):
pycmd = 'python.exe'
else:
pycmd = 'python3'
pycmd = which_command(env_name, pycmd)
# print(pycmd)
if (plat == "Windows"):
if (pycmd is None):
pycmd = 'py'
elif (pycmd != 'py'):
pycmd = 'python'
else:
pycmd = 'python3'
if (os.path.isfile(pythonexecfile)):
if (plat == "Windows"):
cmd_list.append("call %s \"%s\" %s" % (pycmd, pythonexecfile, '%*'))
else:
cmd_list.append("%s \"%s\" %s" % (pycmd, pythonexecfile, '"$@"'))
else:
if (plat == "Windows"):
cmd_list.append("call %s -c \"%s\" %s" % (pycmd, pythonexecfile, '%*'))
else:
cmd_list.append("%s -c \"%s\" %s" % (pycmd, pythonexecfile, '"$@"'))
# append exit 0
cmd_list.append(cmd_exit)
cmd_execute = name + "_exec" + cmd_suffix
with open(cmd_execute, "w", encoding=cmd_codec) as f:
for line in cmd_list:
f.write(line + cmd_return)
# print(cmd_execute)
if (debugswitch == '1'):
print("IN: execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_execute)
cmd_list.clear()
if (plat == "Windows"):
cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("call " + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("call " + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
else:
# cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("./" + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("./" + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
cmd_list.append(cmd_exit)
if (debugswitch == '1'):
print("CMD: call execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
return cmd_list, name
def vc_language_createCmdList08(shellenvname=None, suffix=None, encoding=None, env_name=None, local=True, list0=[], params0=[]):
cmd_list = []
name = uuid.uuid4().__str__()
name = name.split('-')[0]
# print (name)
plat = getplatform()
if (plat == "Windows"):
cmd_status = "echo pymake-command-status:%ERRORLEVEL%"
cmd_sep = '&'
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_exit = 'exit /b %ERRORLEVEL%'
cmd_suffix = ".bat"
cmd_header = "@echo off"
cmd_call = "call "
# window close echo, close promot
cmd_list.append(cmd_header)
# os.system("type env_effect.bat > cmd_exec.bat")
cmd_list.append("call %s_effect.bat" % name)
if (shellenvname is not None):
cmd_list.append('call \"%s_effect%s\"' % (shellenvname, cmd_suffix))
else:
cmd_status = "echo pymake-command-status:$?"
cmd_sep = ';'
cmd_suffix = ".sh"
cmd_exit = 'exit $?'
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash"
cmd_call = "./"
cmd_list.append(cmd_header)
cmd_list.append("source %s_effect.sh" % name)
if (shellenvname is not None):
cmd_list.append('source \"%s_effect%s\"' % (shellenvname, cmd_suffix))
if (env_name is None):
env_name = rawconfig['environ']['current']
if (env_name == "current"):
env_name = rawconfig['environ']['current']
cmd_suffix_language = cmd_suffix
cmd_codec_language = cmd_codec
cmd_return_language = cmd_return
if (suffix is not None):
cmd_suffix_language = suffix
if (encoding is not None):
cmd_codec_language = encoding
list1 = []
# for current_var in str(args['<command-param>']).split():
# list1.append(current_var)
if (params0.__len__() > 0):
current_var = params0[0]
list1.append(current_var)
params0.pop(0)
# print(list1)
params_string = ""
for param in params0:
if (str(param).__contains__(' ')):
params_string += '"' + param + '"' + ' '
else:
params_string += param + ' '
# print(params_string)
local2 = True
if (list1.__len__() > 0):
current_var = list1[0]
if (current_var in rawconfig['command']):
local2 = True
else:
local2 = False
languageparams = ''
# actually only one param.
if (local2 is True):
for param1 in list1:
languageparams += param1
else:
for param1 in list1:
# warning: now pymake is in user setted workroot.
languageparams = ""
while (True):
# find in current path [+--workroot]
languageparams = os.getcwd() + os.path.sep + param1
# print(2, languageparams)
if (os.path.exists(languageparams)):
break
languageparams = startupworkdirectory + os.path.sep + param1
# print(2, languageparams)
if (os.path.exists(languageparams)):
break
# find in .json environ
separateenvlistpath = os.path.pathsep.join(rawconfig['environ'][env_name]['path+'])
separateenvlistpath = separateenvlistpath.split(os.path.pathsep)
separateenvlistpath.reverse()
# for path0 in separateenvlistpath:
# print(path0)
find_flag = 0
for path0 in separateenvlistpath:
languageparams = path0 + os.path.sep + param1
# print(2, languageparams)
if (os.path.exists(languageparams)):
find_flag = 1
break
if (find_flag == 1):
break
# find in basic environ [custom+]
env = os.environ
find_flag = 0
for path0 in env["PATH"].split(os.path.pathsep):
languageparams = path0 + os.path.sep + param1
# print(2, languageparams)
if (os.path.exists(languageparams)):
find_flag = 1
break
if (find_flag == 1):
break
# none? a language command, or language command-line.
languageparams = param1
break
# print(2, languageparams)
# cmd_list.append(languageparams + ' ' + params_string)
if (list1.__len__() > 0):
''
if (local2 is True):
''
current_var = env_name
local_command = raw_command(current_var)
dict0 = copy.deepcopy(local_command)
inside_name = name + '_2'
languageparams = inside_name + '_exec' + cmd_suffix_language
with open(languageparams, 'w', encoding=cmd_codec_language) as f:
for cmd1 in list1:
for cmd in dict0[cmd1]:
f.write(cmd + cmd_return_language)
# print(1, cmd_suffix_language)
# print(1, cmd_return_language)
# print(1, cmd_codec_language)
# print(1, languageparams)
else:
''
# print(3, languageparams)
if (list1.__len__() > 0):
if (local2 is True):
params_string = languageparams + ' ' + params_string
else:
if (str(languageparams).__contains__(' ')):
params_string = '"' + languageparams + '"' + ' ' + params_string
else:
params_string = languageparams + ' ' + params_string
# print(params_string)
languageexecfile = ''
if (local is True):
# fixed
# inside_name = name
# inside_name = hex( int( inside_name, 16 ) + 1).split('x')[1]
inside_name = name + '_1'
# print(inside_name)
languageexecfile = inside_name + '_exec' + cmd_suffix
with open(languageexecfile, 'w', encoding=cmd_codec) as f:
for cmd in list0:
f.write(cmd + cmd_return)
# print(1, languageexecfile)
else:
languageexecfile = ''
# actually now has only one command.
for cmd in list0:
# actually this is a command.
if (str(cmd).__contains__(' ')):
pycmd = which_command(env_name, str(cmd))
# print(cmd)
# print(pycmd)
if (pycmd is not None and os.path.isfile(pycmd)):
languageexecfile = '"' + cmd + '"'
else:
languageexecfile = cmd
else:
languageexecfile = cmd
# print(3, languageexecfile)
if (plat == "Windows"):
cmd_list.append("call %s %s" % (languageexecfile, '%*'))
else:
if (languageexecfile.endswith('.sh')):
cmd_list.append("sh %s %s" % (languageexecfile, '"$@"'))
else:
cmd_list.append("%s %s" % (languageexecfile, '"$@"'))
# append exit 0
cmd_list.append(cmd_exit)
cmd_execute = name + "_exec" + cmd_suffix
with open(cmd_execute, "w", encoding=cmd_codec) as f:
for line in cmd_list:
f.write(line + cmd_return)
if (debugswitch == '1'):
print("IN: execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_execute)
cmd_list.clear()
if (plat == "Windows"):
cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("call " + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("call " + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
else:
# cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("./" + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("./" + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
cmd_list.append(cmd_exit)
if (debugswitch == '1'):
print("CMD: call execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
return cmd_list, name, cmd_suffix, cmd_suffix_language
# vc json export function
def vc_json_export(dict0=None, env_name=None, file_name=None):
if (dict0 is None):
return "", "", ""
# select env
current_var = rawconfig['environ']['current']
if (env_name is not None):
current_var = env_name
cmd_suffix = ".json"
cmd_codec = 'utf8'
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash" + cmd_return
env_set = ''
# export effect env
cmd_effect = 'vcenv'
if (file_name is not None):
cmd_effect = file_name
cmd_effect += cmd_suffix
if (os.path.exists(cmd_effect) is False):
tempdict = {
'environ': {
}
}
writeJsonData(cmd_effect, tempdict)
vcdict = readJsonData(cmd_effect)
if (vcdict.__contains__('environ') is False):
vcdict['environ'] = {}
vcdict['environ'][current_var] = dict0
writeJsonData(cmd_effect, vcdict)
return cmd_effect
# vc powershell export function
def vc_powershell_export(dict0=None, env_name=None, file_name=None):
if (dict0 is None):
return "", "", ""
# select env
current_var = rawconfig['environ']['current']
if (env_name is not None):
current_var = env_name
cmd_suffix = ".ps1"
cmd_codec = 'ansi'
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash" + cmd_return
env_set = ''
# export effect env
cmd_effect = 'env'
if (file_name is not None):
cmd_effect = "" + file_name
cmd_effect += '_effect' + cmd_suffix
# export path
lines = ""
for (key) in dict0["path+"]:
lines += ("if ( !$env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Insert(0, \"%s;\") }" % (key, key)) + cmd_return
# export var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
lines += ("${env:" + key + '} = \'' + value + '\'' + cmd_return)
# print(lines.split('\n'))
with open(cmd_effect, 'w', encoding=cmd_codec) as f:
# f.write(cmd_header)
f.write(lines)
# export unset env
cmd_unset = 'env'
if (file_name is not None):
cmd_unset = "" + file_name
cmd_unset += '_unset' + cmd_suffix
# export unset path
lines = ""
for (key) in dict0["path+"]:
# lines += ("$env:Path = $env:Path.Replace(\"%s;\", \"\")" % key) + cmd_return
lines += ("if ( $env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Replace(\"%s;\", \"\") }" % (key, key)) + cmd_return
# export unset var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
lines += ("${env:%s} = \"\"" % key) + cmd_return
with open(cmd_unset, 'w', encoding=cmd_codec) as f:
# f.write(cmd_header)
f.write(lines)
return cmd_effect, cmd_unset
def vc_powershell_export2(dict0=None, env_name=None, file_name=None):
if (dict0 is None):
return "", "", ""
# select env
current_var = rawconfig['environ']['current']
if (env_name is not None):
current_var = env_name
cmd_suffix = ".ps1"
cmd_codec = 'ansi'
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash" + cmd_return
env_set = ''
# export effect env
cmd_effect = 'env'
if (file_name is not None):
cmd_effect = "" + file_name
cmd_effect += '_effect' + cmd_suffix
lines = ""
# +system
if (args['-s'] or args['--system'] is True):
# export path
# print(envcustomlistrawpaths)
for (key) in pymakesystemenviron['PATH'].split(os.path.pathsep):
lines += ("if ( !$env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Insert(0, \"%s;\") }" % (key, key)) + cmd_return
# export var
for (key, value) in pymakesystemenviron.items():
if (key == 'path+'):
continue
if (str(key).lower() == "path"):
continue
lines += ("${env:" + key + '} = \'' + value + '\'' + cmd_return)
else:
''
# +local
if (args['-l'] or args['--local'] is True):
# export path
for (key) in localenv['path+']:
lines += ("if ( !$env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Insert(0, \"%s;\") }" % (key, key)) + cmd_return
# export var
for (key, value) in localenv.items():
if (key == 'path+'):
continue
lines += ("${env:" + key + '} = \'' + value + '\'' + cmd_return)
else:
''
# +custom
if (args['-c'] or args['--custom'] is True):
# export path
# print(envcustomlistrawpaths)
for (key) in envcustomlistrawpaths:
lines += ("if ( !$env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Insert(0, \"%s;\") }" % (key, key)) + cmd_return
# export var
for (key, value) in envcustomlistrawvars.items():
if (key == 'path+'):
continue
lines += ("${env:" + key + '} = \'' + value + '\'' + cmd_return)
else:
''
# export path
for (key) in dict0["path+"]:
lines += ("if ( !$env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Insert(0, \"%s;\") }" % (key, key)) + cmd_return
# export var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
lines += ("${env:" + key + '} = \'' + value + '\'' + cmd_return)
# print(lines.split('\n'))
with open(cmd_effect, 'w', encoding=cmd_codec) as f:
# f.write(cmd_header)
f.write(lines)
# export unset env
cmd_unset = 'env'
if (file_name is not None):
cmd_unset = "" + file_name
cmd_unset += '_unset' + cmd_suffix
lines = ""
# +system
if (args['-s'] or args['--system'] is True):
# export unset path
for (key) in pymakesystemenviron['PATH'].split(os.path.pathsep):
lines += ("if ( $env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Replace(\"%s;\", \"\") }" % (key, key)) + cmd_return
# export unset var
for (key, value) in pymakesystemenviron.items():
if (key == 'path+'):
continue
if (str(key).lower() == "path"):
continue
lines += ("${env:%s} = \"\"" % key) + cmd_return
else:
''
# +local
if (args['-l'] or args['--local'] is True):
# export unset path
for (key) in localenv['path+']:
lines += ("if ( $env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Replace(\"%s;\", \"\") }" % (key, key)) + cmd_return
# export unset var
for (key, value) in localenv.items():
if (key == 'path+'):
continue
lines += ("${env:%s} = \"\"" % key) + cmd_return
else:
''
# +custom
if (args['-c'] or args['--custom'] is True):
# export unset path
for (key) in envcustomlistrawpaths:
lines += ("if ( $env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Replace(\"%s;\", \"\") }" % (key, key)) + cmd_return
# export unset var
for (key, value) in envcustomlistrawvars.items():
if (key == 'path+'):
continue
lines += ("${env:%s} = \"\"" % key) + cmd_return
else:
''
# export unset path
for (key) in dict0["path+"]:
# lines += ("$env:Path = $env:Path.Replace(\"%s;\", \"\")" % key) + cmd_return
lines += ("if ( $env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Replace(\"%s;\", \"\") }" % (key, key)) + cmd_return
# export unset var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
lines += ("${env:%s} = \"\"" % key) + cmd_return
with open(cmd_unset, 'w', encoding=cmd_codec) as f:
# f.write(cmd_header)
f.write(lines)
return cmd_effect, cmd_unset
# vc export function
# dict0: VC effect env
# env_name: separate env
# file_name: script name
def vc_export(dict0=None, env_name=None, file_name=None):
if (dict0 is None):
return "", "", ""
# select env
current_var = rawconfig['environ']['current']
if (env_name is not None):
current_var = env_name
plat = getplatform()
if (plat == "Windows"):
cmd_suffix = ".bat"
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
cmd_return = "\n"
cmd_header = "@echo off" + cmd_return
env_set = 'set '
else:
cmd_suffix = ".sh"
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash" + cmd_return
env_set = 'export '
# export effect env
cmd_effect = 'env'
if (file_name is not None):
cmd_effect = file_name
cmd_effect += '_effect' + cmd_suffix
# export path
lines = ""
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=' + key + os.path.pathsep + '%PATH%' + cmd_return)
else:
lines += (env_set + 'PATH="' + key + '"' + os.path.pathsep + '$PATH' + cmd_return)
# export var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += (env_set + key + '=' + value + cmd_return)
else:
lines += (env_set + key + '=\"' + value + '\"' + cmd_return)
with open(cmd_effect, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
# export unset env
cmd_unset = 'env'
if (file_name is not None):
cmd_unset = file_name
cmd_unset += '_unset' + cmd_suffix
# export unset path
lines = ""
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=%PATH:' + key + ';=%' + cmd_return)
else:
lines += (env_set + 'PATH=$(' + 'echo ${PATH//' + key.replace('/', '\/') + ':/})' + cmd_return)
# export unset var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += ('set ' + key + '=' + cmd_return)
else:
lines += ('unset ' + key + cmd_return)
with open(cmd_unset, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_effect)
os.system("chmod +x " + cmd_unset)
# return file name
return cmd_effect, cmd_unset
def vc_export2(dict0=None, env_name=None, file_name=None):
if (dict0 is None):
return "", "", ""
# select env
current_var = rawconfig['environ']['current']
if (env_name is not None):
current_var = env_name
plat = getplatform()
if (plat == "Windows"):
cmd_suffix = ".bat"
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
cmd_return = "\n"
cmd_header = "@echo off" + cmd_return
env_set = 'set '
else:
cmd_suffix = ".sh"
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash" + cmd_return
env_set = 'export '
# export effect env
cmd_effect = 'env'
if (file_name is not None):
cmd_effect = file_name
cmd_effect += '_effect' + cmd_suffix
lines = ""
# +system
if (args['-s'] or args['--system'] is True):
# export path
# print(envcustomlistrawpaths)
for (key) in pymakesystemenviron['PATH'].split(os.path.pathsep):
if (plat == "Windows"):
lines += (env_set + 'PATH=' + key + os.path.pathsep + '%PATH%' + cmd_return)
else:
lines += (env_set + 'PATH="' + key + '"' + os.path.pathsep + '$PATH' + cmd_return)
# export var
for (key, value) in pymakesystemenviron.items():
if (key == 'path+'):
continue
if (str(key).lower() == "path"):
continue
if (plat == "Windows"):
lines += (env_set + key + '=' + value + cmd_return)
else:
lines += (env_set + key + '=\"' + value + '\"' + cmd_return)
else:
''
# +local
if (args['-l'] or args['--local'] is True):
# export path
for (key) in localenv['path+']:
if (plat == "Windows"):
lines += (env_set + 'PATH=' + key + os.path.pathsep + '%PATH%' + cmd_return)
else:
lines += (env_set + 'PATH="' + key + '"' + os.path.pathsep + '$PATH' + cmd_return)
# export var
for (key, value) in localenv.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += (env_set + key + '=' + value + cmd_return)
else:
lines += (env_set + key + '=\"' + value + '\"' + cmd_return)
else:
''
# +custom
if (args['-c'] or args['--custom'] is True):
# export path
# print(envcustomlistrawpaths)
for (key) in envcustomlistrawpaths:
if (plat == "Windows"):
lines += (env_set + 'PATH=' + key + os.path.pathsep + '%PATH%' + cmd_return)
else:
lines += (env_set + 'PATH="' + key + '"' + os.path.pathsep + '$PATH' + cmd_return)
# export var
for (key, value) in envcustomlistrawvars.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += (env_set + key + '=' + value + cmd_return)
else:
lines += (env_set + key + '=\"' + value + '\"' + cmd_return)
else:
''
# export path
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=' + key + os.path.pathsep + '%PATH%' + cmd_return)
else:
lines += (env_set + 'PATH="' + key + '"' + os.path.pathsep + '$PATH' + cmd_return)
# export var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += (env_set + key + '=' + value + cmd_return)
else:
lines += (env_set + key + '=\"' + value + '\"' + cmd_return)
with open(cmd_effect, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
# export unset env
cmd_unset = 'env'
if (file_name is not None):
cmd_unset = file_name
cmd_unset += '_unset' + cmd_suffix
lines = ""
# +system
if (args['-s'] or args['--system'] is True):
# export unset path
for (key) in pymakesystemenviron['PATH'].split(os.path.pathsep):
if (plat == "Windows"):
lines += (env_set + 'PATH=%PATH:' + key + ';=%' + cmd_return)
else:
lines += (env_set + 'PATH=$(' + 'echo ${PATH//' + key.replace('/', '\/') + ':/})' + cmd_return)
# export unset var
for (key, value) in pymakesystemenviron.items():
if (key == 'path+'):
continue
if (str(key).lower() == "path"):
continue
if (plat == "Windows"):
lines += ('set ' + key + '=' + cmd_return)
else:
lines += ('unset ' + key + cmd_return)
else:
''
# +local
if (args['-l'] or args['--local'] is True):
# export unset path
for (key) in localenv['path+']:
if (plat == "Windows"):
lines += (env_set + 'PATH=%PATH:' + key + ';=%' + cmd_return)
else:
lines += (env_set + 'PATH=$(' + 'echo ${PATH//' + key.replace('/', '\/') + ':/})' + cmd_return)
# export unset var
for (key, value) in localenv.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += ('set ' + key + '=' + cmd_return)
else:
lines += ('unset ' + key + cmd_return)
else:
''
# +custom
if (args['-c'] or args['--custom'] is True):
# export unset path
for (key) in envcustomlistrawpaths:
if (plat == "Windows"):
lines += (env_set + 'PATH=%PATH:' + key + ';=%' + cmd_return)
else:
lines += (env_set + 'PATH=$(' + 'echo ${PATH//' + key.replace('/', '\/') + ':/})' + cmd_return)
# export unset var
for (key, value) in envcustomlistrawvars.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += ('set ' + key + '=' + cmd_return)
else:
lines += ('unset ' + key + cmd_return)
else:
''
# export unset path
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=%PATH:' + key + ';=%' + cmd_return)
else:
lines += (env_set + 'PATH=$(' + 'echo ${PATH//' + key.replace('/', '\/') + ':/})' + cmd_return)
# export unset var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += ('set ' + key + '=' + cmd_return)
else:
lines += ('unset ' + key + cmd_return)
with open(cmd_unset, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_effect)
os.system("chmod +x " + cmd_unset)
# return file name
return cmd_effect, cmd_unset
# vc settings function
def vc_settings(env_name=None):
current_env = env_name
if (env_name is None):
current_env = rawconfig['environ']['current']
print("source file: %s" % sourceconfigfile)
vcvarslist = [
'vcvarsall-1998',
'vcvarsall-2003',
'vcvarsall-2005',
'vcvarsall-2008',
'vcvarsall-2010',
'vcvarsall-2012',
'vcvarsall-2013',
'vcvarsall-2015',
'vcvarsall-2017',
'vcvarsall-2019',
'vcvarsall-20XX'
]
'''
vcvarslist = []
for key, vcconfig in rawconfig['path-assemblage'].items():
if(str(key).startswith('vcvarsall')):
vcvarslist.append(key)
'''
print('path-assemblage:')
for key in vcvarslist:
if (rawconfig['path-assemblage'].__contains__(key) is False):
rawconfig['path-assemblage'][key] = "<CAN SET>"
print(' "%s": "%s"' % (key, rawconfig['path-assemblage'][key]))
current_vcvarsall = 'vcvarsall'
current_vcvarsallparam = 'vcvarsallparam'
print('system env:')
if (pymakesystemenviron.__contains__(current_vcvarsall) is False):
pymakesystemenviron[current_vcvarsall] = "<CAN SET>"
print(' "%s" : "%s"' % (current_vcvarsall, pymakesystemenviron[current_vcvarsall]))
if (pymakesystemenviron.__contains__(current_vcvarsallparam) is False):
pymakesystemenviron[current_vcvarsallparam] = "<CAN SET>"
print(' "%s": "%s"' % (current_vcvarsallparam, pymakesystemenviron[current_vcvarsallparam]))
print('custom env:')
if (envcustomlistrawvars.__contains__(current_vcvarsall) is False):
envcustomlistrawvars[current_vcvarsall] = "<CAN SET>"
print(' "%s" : "%s"' % (current_vcvarsall, envcustomlistrawvars[current_vcvarsall]))
if (envcustomlistrawvars.__contains__(current_vcvarsallparam) is False):
envcustomlistrawvars[current_vcvarsallparam] = "<CAN SET>"
print(' "%s": "%s"' % (current_vcvarsallparam, envcustomlistrawvars[current_vcvarsallparam]))
print('env %s:' % current_env)
if (rawconfig['environ'][current_env].__contains__(current_vcvarsall) is False):
rawconfig['environ'][current_env][current_vcvarsall] = "<CAN SET>"
print(' "%s" : "%s"' % (current_vcvarsall, rawconfig['environ'][current_env][current_vcvarsall]))
if (rawconfig['environ'][current_env].__contains__(current_vcvarsallparam) is False):
rawconfig['environ'][current_env][current_vcvarsallparam] = "<CAN SET>"
print(' "%s": "%s"' % (current_vcvarsallparam, rawconfig['environ'][current_env][current_vcvarsallparam]))
return
# vc settings2 function
def vc_settings2(env_name = None):
print("source root: %s" % sourceroot)
current_vcvarsall = 'vcvarsall'
current_vcvarsallparam = 'vcvarsallparam'
print('system env:')
if (pymakesystemenviron.__contains__(current_vcvarsall) is False):
pymakesystemenviron[current_vcvarsall] = "<CAN SET>"
print(' "%s" : "%s"' % (current_vcvarsall, pymakesystemenviron[current_vcvarsall]))
if (pymakesystemenviron.__contains__(current_vcvarsallparam) is False):
pymakesystemenviron[current_vcvarsallparam] = "<CAN SET>"
print(' "%s": "%s"' % (current_vcvarsallparam, pymakesystemenviron[current_vcvarsallparam]))
print('custom env:')
if (envcustomlistrawvars.__contains__(current_vcvarsall) is False):
envcustomlistrawvars[current_vcvarsall] = "<CAN SET>"
print(' "%s" : "%s"' % (current_vcvarsall, envcustomlistrawvars[current_vcvarsall]))
if (envcustomlistrawvars.__contains__(current_vcvarsallparam) is False):
envcustomlistrawvars[current_vcvarsallparam] = "<CAN SET>"
print(' "%s": "%s"' % (current_vcvarsallparam, envcustomlistrawvars[current_vcvarsallparam]))
vcvarslist = []
for key, vcconfig in rawconfig['path-assemblage'].items():
if(str(key).startswith('vcvarsall')):
vcvarslist.append(key)
if(str(key).startswith('vcbuildtools')):
vcvarslist.append(key)
vcvarslist.append('vcvarsall-20XX')
print("source file: %s" % sourceconfigfile)
print('path-assemblage:')
for key in vcvarslist:
if (rawconfig['path-assemblage'].__contains__(key) is False):
rawconfig['path-assemblage'][key] = "<CAN SET>"
print(' %-24s: %s' % (key, rawconfig['path-assemblage'][key]))
print('environ:')
print(' %-30s %-30s %-30s %s' % ('[env]', '[status]', '[vcvarsall]', '[vcvarsallparam]'))
set_content = '<WAIT SET>'
set_content2 = '<CAN SET>'
set_content3 = '<INSTALLED>'
set_content4 = '<NEED INSTALL>'
for (k, v) in rawconfig['environ'].items():
current_env = k
if (current_env == 'current'):
continue
status = set_content
vcvarsall = set_content2
vcvarsallparam = set_content2
if (rawconfig['environ'].__contains__(current_env) is True):
if (rawconfig['environ'][current_env].__contains__(current_vcvarsall) is True):
if(os.path.exists(rawconfig['environ'][current_env][current_vcvarsall])):
status = set_content3
else:
status = set_content4
if (rawconfig['environ'][current_env].__contains__(current_vcvarsall) is True):
vcvarsall = rawconfig['environ'][current_env][current_vcvarsall]
if (rawconfig['environ'][current_env].__contains__(current_vcvarsallparam) is True):
vcvarsallparam = rawconfig['environ'][current_env][current_vcvarsallparam]
if (current_env == rawconfig['environ']['current']):
print(Fore.LIGHTMAGENTA_EX + ' %-30s %-30s %-30s %s' % (current_env, status, vcvarsall, vcvarsallparam))
continue
print(' %-30s %-30s %-30s %s' % (current_env, status, vcvarsall, vcvarsallparam))
return
# vc command
# vc init command
# ===============================================================================================
# PYMAKE LANGUAGE CCVP COMMAND INITIAL CODE
# --------------------
# export2 command
# powershell export env function
def powershell_environ_export(env_name=None, file_name=None):
# select env
current_var = rawconfig['environ']['current']
if (env_name is not None):
current_var = env_name
dict0 = copy.deepcopy(rawconfig['environ'][current_var])
cmd_suffix = ".ps1"
cmd_codec = 'ansi'
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash" + cmd_return
env_set = ''
# export effect env
cmd_effect = 'env'
if (file_name is not None):
cmd_effect = "" + file_name
cmd_effect += '_effect' + cmd_suffix
# export path
lines = ""
for (key) in dict0["path+"]:
lines += ("if ( !$env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Insert(0, \"%s;\") }" % (key, key)) + cmd_return
# export var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
lines += ("${env:" + key + '} = \'' + value + '\'' + cmd_return)
# print(lines.split('\n'))
with open(cmd_effect, 'w', encoding=cmd_codec) as f:
# f.write(cmd_header)
f.write(lines)
# export unset env
cmd_unset = 'env'
if (file_name is not None):
cmd_unset = "" + file_name
cmd_unset += '_unset' + cmd_suffix
# export unset path
lines = ""
for (key) in dict0["path+"]:
# lines += ("$env:Path = $env:Path.Replace(\"%s;\", \"\")" % key) + cmd_return
lines += ("if ( $env:Path.Contains(\"%s;\" ) ) { $env:Path = $env:Path.Replace(\"%s;\", \"\") }" % (key, key)) + cmd_return
# export unset var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
lines += ("${env:%s} = \"\"" % key) + cmd_return
with open(cmd_unset, 'w', encoding=cmd_codec) as f:
# f.write(cmd_header)
f.write(lines)
return current_var, cmd_effect, cmd_unset
# powershell [windows, unix]
def createCmdList03(env_name=None, local=True, list0=[], params0=[]):
cmd_list = []
if (env_name is None):
env_name = rawconfig['environ']['current']
name = uuid.uuid4().__str__()
name = name.split('-')[0]
# print (name)
# plat = getplatform()
cmd_status = "echo pymake-command-status:$LASTEXITCODE"
cmd_sep = ';'
cmd_suffix = ".ps1"
cmd_suffix_powershell = cmd_suffix
cmd_exit = 'exit $LASTEXITCODE'
cmd_codec = 'ansi'
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash"
cmd_call = "./"
# cmd_list.append(cmd_header)
cmd_list.append("./%s_effect%s" % (name, cmd_suffix))
params_string = ""
for param in params0:
if (str(param).__contains__(' ')):
params_string += '"' + param + '"' + ' '
else:
params_string += param + ' '
# print(params_string)
if (local is True):
for cmd in list0:
cmd_list.append(cmd)
else:
# actually now has only one command.
for cmd in list0:
# warning: now pymake is in user setted workroot.
if (str(cmd).endswith(cmd_suffix_powershell)):
cmd_suffix_powershell = ''
powershellexecfile = ""
while (True):
# find in current path [+workroot]
powershellexecfile = os.getcwd() + os.path.sep + cmd + cmd_suffix_powershell
if (os.path.exists(powershellexecfile)):
break
powershellexecfile = startupworkdirectory + os.path.sep + cmd + cmd_suffix_powershell
if (os.path.exists(powershellexecfile)):
break
# find in .json environ
separateenvlistpath = os.path.pathsep.join(rawconfig['environ'][env_name]['path+'])
separateenvlistpath = separateenvlistpath.split(os.path.pathsep)
separateenvlistpath.reverse()
# for path0 in separateenvlistpath:
# print(path0)
find_flag = 0
for path0 in separateenvlistpath:
powershellexecfile = path0 + os.path.sep + cmd + cmd_suffix_powershell
if (os.path.exists(powershellexecfile)):
find_flag = 1
break
if (find_flag == 1):
break
# find in basic environ [+custom]
env = os.environ
find_flag = 0
for path0 in env["PATH"].split(os.path.pathsep):
powershellexecfile = path0 + os.path.sep + cmd + cmd_suffix_powershell
if (os.path.exists(powershellexecfile)):
find_flag = 1
break
if (find_flag == 1):
break
# none? a powershell command, or powershell command-line.
powershellexecfile = cmd
break
# print(powershellexecfile)
# wow
# cmd_list.append(powershellexecfile + ' ' + params_string)
if (str(powershellexecfile).__contains__(' ')):
if (os.path.isfile(powershellexecfile)):
powershellexecfile = powershellexecfile.replace('/', os.path.sep)
powershellexecfile = powershellexecfile.replace('\\', os.path.sep)
cmd_list.append(". \"%s\" @args" % powershellexecfile)
else:
cmd_list.append("%s" % powershellexecfile)
else:
if (os.path.isfile(powershellexecfile)):
powershellexecfile = powershellexecfile.replace('/', os.path.sep)
powershellexecfile = powershellexecfile.replace('\\', os.path.sep)
cmd_list.append(". %s @args" % powershellexecfile)
else:
cmd_list.append("%s" % powershellexecfile)
# append exit 0
cmd_list.append(cmd_exit)
# print( cmd_list )
cmd_execute = "" + name + "_exec" + cmd_suffix
with open(cmd_execute, "w", encoding=cmd_codec) as f:
for line in cmd_list:
f.write(line + cmd_return)
# print(cmd_execute)
if (debugswitch == '1'):
print("IN: execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
# if (plat == "Windows"):
# ""
# else:
# os.system("chmod +x " + cmd_execute)
cmd_list.clear()
cmd_list.append(cmd_call + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
cmd_list.append(cmd_exit)
# print (cmd_list)
if (debugswitch == '1'):
print("CMD: call execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
return cmd_list, name
# print(args)
# print(args['powershell'])
# powershell is using basic, .json, and custom environ data.
# powershell command
# python export function
def python_env_export(env_name=None, file_name=None):
# select env
current_var = rawconfig['environ']['current']
if (env_name is not None):
current_var = env_name
dict0 = copy.deepcopy(rawconfig['environ'][current_var])
plat = getplatform()
if (plat == "Windows"):
cmd_suffix = ".bat"
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
cmd_return = "\n"
cmd_header = "@echo off" + cmd_return
env_set = 'set '
else:
cmd_suffix = ".sh"
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash" + cmd_return
env_set = 'export '
# export effect env
cmd_effect = 'env'
if (file_name is not None):
cmd_effect = file_name
cmd_effect += '_effect' + cmd_suffix
# export path
lines = ""
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=' + key + os.path.pathsep + '%PATH%' + cmd_return)
else:
lines += (env_set + 'PATH="' + key + '"' + os.path.pathsep + '$PATH' + cmd_return)
# export var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += (env_set + key + '=' + value + cmd_return)
else:
lines += (env_set + key + '=\"' + value + '\"' + cmd_return)
with open(cmd_effect, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
# export unset env
cmd_unset = 'env'
if (file_name is not None):
cmd_unset = file_name
cmd_unset += '_unset' + cmd_suffix
# export unset path
lines = ""
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=%PATH:' + key + ';=%' + cmd_return)
else:
lines += (env_set + 'PATH=$(' + 'echo ${PATH//' + key.replace('/', '\/') + ':/})' + cmd_return)
# export unset var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += ('set ' + key + '=' + cmd_return)
else:
lines += ('unset ' + key + cmd_return)
with open(cmd_unset, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_effect)
os.system("chmod +x " + cmd_unset)
# return file name
return current_var, cmd_effect, cmd_unset
# python [windows unix]
def createCmdList05(env_name=None, local=True, list0=[], params0=[]):
cmd_list = []
if (env_name is None):
env_name = rawconfig['environ']['current']
name = uuid.uuid4().__str__()
name = name.split('-')[0]
# print (name)
plat = getplatform()
if (plat == "Windows"):
cmd_status = "echo pymake-command-status:%ERRORLEVEL%"
cmd_sep = '&'
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_exit = 'exit /b %ERRORLEVEL%'
cmd_suffix = ".bat"
cmd_header = "@echo off"
cmd_call = "call "
# window close echo, close promot
cmd_list.append(cmd_header)
# os.system("type env_effect.bat > cmd_exec.bat")
cmd_list.append("call %s_effect.bat" % name)
else:
cmd_status = "echo pymake-command-status:$?"
cmd_sep = ';'
cmd_suffix = ".sh"
cmd_exit = 'exit $?'
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash"
cmd_call = "./"
cmd_list.append(cmd_header)
cmd_list.append("source %s_effect.sh" % name)
cmd_suffix_python = '.py'
cmd_codec_python = "utf8"
cmd_return_python = "\n"
params_string = ""
for param in params0:
if (str(param).__contains__(' ')):
params_string += '"' + param + '"' + ' '
else:
params_string += param + ' '
# print(params_string)
pythonexecfile = ''
if (local is True):
# fixed
pythonexecfile = name + '_exec' + cmd_suffix_python
with open(pythonexecfile, 'w', encoding=cmd_codec_python) as f:
for cmd in list0:
f.write(cmd + cmd_return_python)
# print(1, pythonexecfile)
else:
# actually now has only one command.
for cmd in list0:
# warning: now pymake is in user setted workroot.
if (str(cmd).endswith(cmd_suffix_python)):
cmd_suffix_python = ''
pythonexecfile = ""
while (True):
# find in current path [+workroot]
pythonexecfile = os.getcwd() + os.path.sep + cmd + cmd_suffix_python
# print(2, pythonexecfile)
if (os.path.exists(pythonexecfile)):
break
pythonexecfile = startupworkdirectory + os.path.sep + cmd + cmd_suffix_python
# print(2, pythonexecfile)
if (os.path.exists(pythonexecfile)):
break
# find in .json environ
separateenvlistpath = os.path.pathsep.join(rawconfig['environ'][env_name]['path+'])
separateenvlistpath = separateenvlistpath.split(os.path.pathsep)
separateenvlistpath.reverse()
# for path0 in separateenvlistpath:
# print(path0)
find_flag = 0
for path0 in separateenvlistpath:
pythonexecfile = path0 + os.path.sep + cmd + cmd_suffix_python
# print(2, pythonexecfile)
if (os.path.exists(pythonexecfile)):
find_flag = 1
break
if (find_flag == 1):
break
# find in basic environ [custom+]
env = os.environ
find_flag = 0
for path0 in env["PATH"].split(os.path.pathsep):
pythonexecfile = path0 + os.path.sep + cmd + cmd_suffix_python
# print(2, pythonexecfile)
if (os.path.exists(pythonexecfile)):
find_flag = 1
break
if (find_flag == 1):
break
# none? a python command, or python command-line.
pythonexecfile = cmd
break
# print(2, pythonexecfile)
# cmd_list.append(pythonexecfile + ' ' + params_string)
# print params.
# print(3, pythonexecfile)
# get python command.
pycmd = ''
if (plat == "Windows"):
pycmd = 'python.exe'
else:
pycmd = 'python3'
pycmd = which_command(env_name, pycmd)
# print(pycmd)
if (plat == "Windows"):
if (pycmd is None):
pycmd = 'py'
elif (pycmd != 'py'):
pycmd = 'python'
else:
pycmd = 'python3'
if (os.path.isfile(pythonexecfile)):
if (plat == "Windows"):
cmd_list.append("call %s \"%s\" %s" % (pycmd, pythonexecfile, '%*'))
else:
cmd_list.append("%s \"%s\" %s" % (pycmd, pythonexecfile, '"$@"'))
else:
if (plat == "Windows"):
cmd_list.append("call %s -c \"%s\" %s" % (pycmd, pythonexecfile, '%*'))
else:
cmd_list.append("%s -c \"%s\" %s" % (pycmd, pythonexecfile, '"$@"'))
# append exit 0
cmd_list.append(cmd_exit)
cmd_execute = name + "_exec" + cmd_suffix
with open(cmd_execute, "w", encoding=cmd_codec) as f:
for line in cmd_list:
f.write(line + cmd_return)
# print(cmd_execute)
if (debugswitch == '1'):
print("IN: execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_execute)
cmd_list.clear()
if (plat == "Windows"):
cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("call " + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("call " + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
else:
# cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("./" + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("./" + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
cmd_list.append(cmd_exit)
if (debugswitch == '1'):
print("CMD: call execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
return cmd_list, name
# python command
# python ccvp command
# print(args)
# print(args['custom'])
# print(args['hh'])
# custom command
# system command
# language export function
def language_env_export(env_name=None, file_name=None):
# select env
current_var = rawconfig['environ']['current']
if (env_name is not None):
current_var = env_name
dict0 = copy.deepcopy(rawconfig['environ'][current_var])
plat = getplatform()
if (plat == "Windows"):
cmd_suffix = ".bat"
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
cmd_return = "\n"
cmd_header = "@echo off" + cmd_return
env_set = 'set '
else:
cmd_suffix = ".sh"
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash" + cmd_return
env_set = 'export '
# export effect env
cmd_effect = 'env'
if (file_name is not None):
cmd_effect = file_name
cmd_effect += '_effect' + cmd_suffix
# export path
lines = ""
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=' + key + os.path.pathsep + '%PATH%' + cmd_return)
else:
lines += (env_set + 'PATH="' + key + '"' + os.path.pathsep + '$PATH' + cmd_return)
# export var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += (env_set + key + '=' + value + cmd_return)
else:
lines += (env_set + key + '=\"' + value + '\"' + cmd_return)
with open(cmd_effect, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
# export unset env
cmd_unset = 'env'
if (file_name is not None):
cmd_unset = file_name
cmd_unset += '_unset' + cmd_suffix
# export unset path
lines = ""
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=%PATH:' + key + ';=%' + cmd_return)
else:
lines += (env_set + 'PATH=$(' + 'echo ${PATH//' + key.replace('/', '\/') + ':/})' + cmd_return)
# export unset var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += ('set ' + key + '=' + cmd_return)
else:
lines += ('unset ' + key + cmd_return)
with open(cmd_unset, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_effect)
os.system("chmod +x " + cmd_unset)
# return file name
return current_var, cmd_effect, cmd_unset
# language [ .bat .sh .ps1 .py ...] [windows unix] --suffix --encoding
def createCmdList07(suffix=None, encoding=None, env_name=None, local=True, list0=[], params0=[]):
cmd_list = []
name = uuid.uuid4().__str__()
name = name.split('-')[0]
# print (name)
plat = getplatform()
if (plat == "Windows"):
cmd_status = "echo pymake-command-status:%ERRORLEVEL%"
cmd_sep = '&'
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_exit = 'exit /b %ERRORLEVEL%'
cmd_suffix = ".bat"
cmd_header = "@echo off"
cmd_call = "call "
# window close echo, close promot
cmd_list.append(cmd_header)
# os.system("type env_effect.bat > cmd_exec.bat")
cmd_list.append("call %s_effect.bat" % name)
else:
cmd_status = "echo pymake-command-status:$?"
cmd_sep = ';'
cmd_suffix = ".sh"
cmd_exit = 'exit $?'
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash"
cmd_call = "./"
cmd_list.append(cmd_header)
cmd_list.append("source %s_effect.sh" % name)
if (env_name is None):
env_name = rawconfig['environ']['current']
if (env_name == "current"):
env_name = rawconfig['environ']['current']
cmd_suffix_language = cmd_suffix
cmd_codec_language = cmd_codec
cmd_return_language = cmd_return
if (suffix is not None):
cmd_suffix_language = suffix
if (encoding is not None):
cmd_codec_language = encoding
list1 = []
# for current_var in str(args['<command-param>']).split():
# list1.append(current_var)
if (params0.__len__() > 0):
current_var = params0[0]
list1.append(current_var)
params0.pop(0)
# print(list1)
params_string = ""
for param in params0:
if (str(param).__contains__(' ')):
params_string += '"' + param + '"' + ' '
else:
params_string += param + ' '
# print(params_string)
local2 = True
if (list1.__len__() > 0):
current_var = list1[0]
if (current_var in rawconfig['command']):
local2 = True
else:
local2 = False
languageparams = ''
# actually only one param.
if (local2 is True):
for param1 in list1:
languageparams += param1
else:
for param1 in list1:
# warning: now pymake is in user setted workroot.
languageparams = ""
while (True):
# find in current path [+--workroot]
languageparams = os.getcwd() + os.path.sep + param1
# print(2, languageparams)
if (os.path.exists(languageparams)):
break
languageparams = startupworkdirectory + os.path.sep + param1
# print(2, languageparams)
if (os.path.exists(languageparams)):
break
# find in .json environ
separateenvlistpath = os.path.pathsep.join(rawconfig['environ'][env_name]['path+'])
separateenvlistpath = separateenvlistpath.split(os.path.pathsep)
separateenvlistpath.reverse()
# for path0 in separateenvlistpath:
# print(path0)
find_flag = 0
for path0 in separateenvlistpath:
languageparams = path0 + os.path.sep + param1
# print(2, languageparams)
if (os.path.exists(languageparams)):
find_flag = 1
break
if (find_flag == 1):
break
# find in basic environ [custom+]
env = os.environ
find_flag = 0
for path0 in env["PATH"].split(os.path.pathsep):
languageparams = path0 + os.path.sep + param1
# print(2, languageparams)
if (os.path.exists(languageparams)):
find_flag = 1
break
if (find_flag == 1):
break
# none? a language command, or language command-line.
languageparams = param1
break
# print(2, languageparams)
# cmd_list.append(languageparams + ' ' + params_string)
if (list1.__len__() > 0):
''
if (local2 is True):
''
current_var = env_name
local_command = raw_command(current_var)
dict0 = copy.deepcopy(local_command)
inside_name = name + '_2'
languageparams = inside_name + '_exec' + cmd_suffix_language
with open(languageparams, 'w', encoding=cmd_codec_language) as f:
for cmd1 in list1:
for cmd in dict0[cmd1]:
f.write(cmd + cmd_return_language)
# print(1, cmd_suffix_language)
# print(1, cmd_return_language)
# print(1, cmd_codec_language)
# print(1, languageparams)
else:
''
# print(3, languageparams)
if (list1.__len__() > 0):
if (local2 is True):
params_string = languageparams + ' ' + params_string
else:
if (str(languageparams).__contains__(' ')):
params_string = '"' + languageparams + '"' + ' ' + params_string
else:
params_string = languageparams + ' ' + params_string
# print(params_string)
languageexecfile = ''
if (local is True):
# fixed
# inside_name = name
# inside_name = hex( int( inside_name, 16 ) + 1).split('x')[1]
inside_name = name + '_1'
# print(inside_name)
languageexecfile = inside_name + '_exec' + cmd_suffix
with open(languageexecfile, 'w', encoding=cmd_codec) as f:
for cmd in list0:
f.write(cmd + cmd_return)
# print(1, languageexecfile)
else:
languageexecfile = ''
# actually now has only one command.
for cmd in list0:
# actually this is a command.
if (str(cmd).__contains__(' ')):
pycmd = which_command(env_name, str(cmd))
# print(cmd)
# print(pycmd)
if (pycmd is not None and os.path.isfile(pycmd)):
languageexecfile = '"' + cmd + '"'
else:
languageexecfile = cmd
else:
languageexecfile = cmd
# print(3, languageexecfile)
if (plat == "Windows"):
cmd_list.append("call %s %s" % (languageexecfile, '%*'))
else:
if (languageexecfile.endswith('.sh')):
cmd_list.append("sh %s %s" % (languageexecfile, '"$@"'))
else:
cmd_list.append("%s %s" % (languageexecfile, '"$@"'))
# append exit 0
cmd_list.append(cmd_exit)
cmd_execute = name + "_exec" + cmd_suffix
with open(cmd_execute, "w", encoding=cmd_codec) as f:
for line in cmd_list:
f.write(line + cmd_return)
if (debugswitch == '1'):
print("IN: execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_execute)
cmd_list.clear()
if (plat == "Windows"):
cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("call " + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("call " + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
else:
# cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("./" + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("./" + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
cmd_list.append(cmd_exit)
if (debugswitch == '1'):
print("CMD: call execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
return cmd_list, name, cmd_suffix, cmd_suffix_language
# language command
# ===============================================================================================
# PYMAKE CCVP COMMAND INITIAL CODE
# --------------------
# cmd type2 function
def cmd_type2(cmd_name=None, file_name=None, env_name=None):
if (cmd_name is None):
for (key, value) in rawconfig['command'].items():
print(Fore.CYAN + "%s" % key)
return
if (rawconfig['command'].__contains__(cmd_name) is False):
print("please check your command name")
return
if (env_name is None or env_name == rawconfig['environ']['current']):
list0 = copy.deepcopy(rawconfig['command'][cmd_name])
else:
list0 = copy.deepcopy(raw_command(env_name)[cmd_name])
# for cmd in list0:
# print(Fore.RED + "%s" % (cmd))
temp_file_name = ""
if (file_name is None):
temp_file_name = "cmd"
else:
temp_file_name = "" + file_name
cmd_header = ""
cmd_codec = "utf8"
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_suffix = ""
if (getplatform() == "Windows"):
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
cmd_header = "@echo off"
cmd_suffix = ".bat"
else:
cmd_codec = 'utf8'
cmd_header = "#!/usr/bin/env bash"
cmd_suffix = ".sh"
suffix = args['--suffix']
if (suffix is not None):
cmd_suffix = str("%s" % suffix)
encoding = args['--encoding']
if (encoding is not None):
cmd_codec = encoding
cmd_exec = temp_file_name + cmd_suffix
with open(cmd_exec, 'w', encoding=cmd_codec, errors='ignore') as f:
# f.write(cmd_header + cmd_return)
cmd = ''
# add shebang line
if (list(list0).__len__() > 0):
cmd = list0[0]
# print(".....")
if (getplatform() == "Windows"):
if (cmd_suffix == '.bat'):
if (cmd.startswith('@echo') is False):
f.write(cmd_header + cmd_return)
else:
if (cmd_suffix == '.sh'):
if (cmd.startswith('#!') is False):
f.write(cmd_header + cmd_return)
for cmd in list0:
f.write(cmd + cmd_return)
if (plat == "Windows"):
""
else:
if (cmd_suffix == '.sh'):
os.system("chmod +x " + cmd_exec)
# print(cmd_codec)
# print(cmd_suffix)
# print(cmd_exec)
return cmd_exec
# type2 command
# open command
# clean *_effect *_unset *_exec .bat[.sh]
# list show
# have has
# need return, set return, default break.
# get
# get
# env environ
# cmd_type function
def cmd_type(cmd_name=None, file_name=None, env_name=None):
if (cmd_name is None):
for (key, value) in rawconfig['command'].items():
print(Fore.CYAN + "%s" % key)
return ""
if (rawconfig['command'].__contains__(cmd_name) is False):
print("please check your command name")
return ""
if (env_name is None or env_name == rawconfig['environ']['current']):
list0 = copy.deepcopy(rawconfig['command'][cmd_name])
else:
list0 = copy.deepcopy(raw_command(env_name)[cmd_name])
# for cmd in list0:
# print(Fore.RED + "%s" % (cmd))
temp_file_name = ""
if (file_name is None):
temp_file_name = "cmd"
else:
temp_file_name = file_name
if (getplatform() == "Windows"):
cmd_header = "@echo off"
cmd_suffix = "_exec.bat"
else:
cmd_header = "#!/usr/bin/env bash"
cmd_suffix = "_exec.sh"
cmd_exec = temp_file_name + cmd_suffix
with open(cmd_exec, 'w', encoding=cmd_codec) as f:
cmd = ''
# add shebang line
if (list(list0).__len__() > 0):
cmd = list0[0]
# print(".....")
if (getplatform() == "Windows"):
if (cmd.startswith('@echo') is False):
f.write(cmd_header + cmd_return)
else:
if (cmd.startswith('#!') is False):
f.write(cmd_header + cmd_return)
for cmd in list0:
f.write(cmd + cmd_return)
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_exec)
return cmd_exec
# use - see/ss/cmd
# see ss cmd
# use env type command
# type
# export function
def env_export(env_name=None, file_name=None):
# select env
current_var = rawconfig['environ']['current']
if (env_name is not None):
current_var = env_name
dict0 = copy.deepcopy(rawconfig['environ'][current_var])
plat = getplatform()
if (plat == "Windows"):
cmd_suffix = ".bat"
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
cmd_return = "\n"
cmd_header = "@echo off" + cmd_return
env_set = 'set '
else:
cmd_suffix = ".sh"
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash" + cmd_return
env_set = 'export '
# export effect env
cmd_effect = 'env'
if (file_name is not None):
cmd_effect = file_name
cmd_effect += '_effect' + cmd_suffix
# export path
lines = ""
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=' + key + os.path.pathsep + '%PATH%' + cmd_return)
else:
lines += (env_set + 'PATH="' + key + '"' + os.path.pathsep + '$PATH' + cmd_return)
# export var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += (env_set + key + '=' + value + cmd_return)
else:
lines += (env_set + key + '=\"' + value + '\"' + cmd_return)
with open(cmd_effect, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
# export unset env
cmd_unset = 'env'
if (file_name is not None):
cmd_unset = file_name
cmd_unset += '_unset' + cmd_suffix
# export unset path
lines = ""
for (key) in dict0["path+"]:
if (plat == "Windows"):
lines += (env_set + 'PATH=%PATH:' + key + ';=%' + cmd_return)
else:
lines += (env_set + 'PATH=$(' + 'echo ${PATH//' + key.replace('/', '\/') + ':/})' + cmd_return)
# export unset var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += ('set ' + key + '=' + cmd_return)
else:
lines += ('unset ' + key + cmd_return)
with open(cmd_unset, 'w', encoding=cmd_codec) as f:
f.write(cmd_header)
f.write(lines)
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_effect)
os.system("chmod +x " + cmd_unset)
# return file name
return current_var, cmd_effect, cmd_unset
# export
# get
# .bat .sh, windows unix
def createCmdList0(list0):
cmd_list = []
name = uuid.uuid4().__str__()
name = name.split('-')[0]
# print (name)
plat = getplatform()
if (plat == "Windows"):
cmd_status = "echo pymake-command-status:%ERRORLEVEL%"
cmd_sep = '&'
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_exit = 'exit /b %ERRORLEVEL%'
cmd_suffix = ".bat"
cmd_header = "@echo off"
# window close echo, close promot
cmd_list.append(cmd_header)
# os.system("type env_effect.bat > cmd_exec.bat")
cmd_list.append("call %s_effect.bat" % name)
else:
cmd_status = "echo pymake-command-status:$?"
cmd_sep = ';'
cmd_suffix = ".sh"
cmd_exit = 'exit $?'
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash"
cmd_list.append(cmd_header)
cmd_list.append("source %s_effect.sh" % name)
for cmd in list0:
cmd_list.append(cmd)
# append exit 0
cmd_list.append(cmd_exit)
# print( cmd_list )
cmd_execute = name + "_exec" + cmd_suffix
with open(cmd_execute, "w", encoding=cmd_codec) as f:
for line in cmd_list:
f.write(line + cmd_return)
if (debugswitch == '1'):
print("IN: execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_execute)
cmd_list.clear()
if (plat == "Windows"):
cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
cmd_list.append("call " + cmd_execute + ' ' + cmd_sep + ' ' + cmd_status)
else:
# cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
cmd_list.append("./" + cmd_execute + ' ' + cmd_sep + ' ' + cmd_status)
cmd_list.append(cmd_exit)
if (debugswitch == '1'):
print("CMD: call execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
# print (cmd_list)
return cmd_list, name
# .bat .sh, windows not compatibility, unix only [ignore]
def createCmdList01(list0):
cmd_list = []
name = uuid.uuid4().__str__()
name = name.split('-')[0]
plat = getplatform()
if (plat == "Windows"):
cmd_status = "echo pymake-command-status:%errorlevel%"
cmd_sep = '&'
cmd_header = "@echo off"
cmd_exit = 'exit /b %ERRORLEVEL%'
# window close echo, close promot
cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
cmd_list.append("call %s_effect.bat" % name + ' ' + cmd_sep + ' ' + cmd_status)
else:
cmd_status = "echo pymake-command-status:$?"
cmd_sep = ';'
cmd_exit = 'exit $?'
cmd_header = "#!/usr/bin/env bash"
cmd_list.append("source %s_effect.sh" % name + ' ' + cmd_sep + ' ' + cmd_status)
for cmd in list0:
cmd_list.append(cmd + ' ' + cmd_sep + ' ' + cmd_status)
# append exit 0
cmd_list.append(cmd_exit)
# print( cmd_list )
return cmd_list, name
# use env exec command
# cc exec
# .bat .sh, windows, unix
def createCmdList02(env_name=None, local=True, list0=[], params0=[]):
cmd_list = []
if (env_name is None):
env_name = rawconfig['environ']['current']
# print(env_name)
name = uuid.uuid4().__str__()
name = name.split('-')[0]
# print (name)
plat = getplatform()
if (plat == "Windows"):
cmd_status = "echo pymake-command-status:%ERRORLEVEL%"
cmd_sep = '&'
cmd_codec = "ansi"
if (getplatform_release() == "XP"):
cmd_codec = None
# but windows, it is \r\n, python helpping me?
cmd_return = "\n"
cmd_exit = 'exit /b %ERRORLEVEL%'
cmd_suffix = ".bat"
cmd_header = "@echo off"
cmd_call = "call "
# window close echo, close promot
cmd_list.append(cmd_header)
# os.system("type env_effect.bat > cmd_exec.bat")
cmd_list.append("call %s_effect.bat" % name)
else:
cmd_status = "echo pymake-command-status:$?"
cmd_sep = ';'
cmd_suffix = ".sh"
cmd_exit = 'exit $?'
cmd_codec = "utf8"
cmd_return = "\n"
cmd_header = "#!/usr/bin/env bash"
cmd_call = "./"
cmd_list.append(cmd_header)
cmd_list.append("source %s_effect.sh" % name)
# print(params0)
params_string = ""
for param in params0:
# print(param)
if (str(param).__contains__(' ')):
params_string += '"' + param + '"' + ' '
else:
params_string += param + ' '
# print(params_string)
if (local is True):
for cmd in list0:
cmd_list.append(cmd)
else:
for cmd in list0:
if (str(cmd).__contains__(' ')):
pycmd = which_command(env_name, str(cmd))
# print(str(cmd))
# print(Fore.RED + "which command:", pycmd)
if (pycmd is not None and os.path.isfile(pycmd)):
cmd_list.append('"' + cmd + '"' + ' ' + params_string)
else:
cmd_list.append(cmd + ' ' + params_string)
else:
cmd_list.append(cmd + ' ' + params_string)
# append exit 0
cmd_list.append(cmd_exit)
# print( cmd_list )
cmd_execute = name + "_exec" + cmd_suffix
with open(cmd_execute, "w", encoding=cmd_codec) as f:
for line in cmd_list:
f.write(line + cmd_return)
# print(cmd_execute)
if (debugswitch == '1'):
print("IN: execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_execute)
cmd_list.clear()
if (plat == "Windows"):
cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("call " + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("call " + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
else:
# cmd_list.append(cmd_header + ' ' + cmd_sep + ' ' + cmd_status)
# cmd_list.append("./" + cmd_execute + cmd_sep + ' ' + cmd_status)
cmd_list.append("./" + cmd_execute + ' ' + params_string + cmd_sep + ' ' + cmd_status)
cmd_list.append(cmd_exit)
# print (cmd_list)
if (debugswitch == '1'):
print("CMD: call execute file: %s" % cmd_execute)
for cmd in cmd_list:
print(cmd)
print("---------------------------")
return cmd_list, name
# use env exec-with-params/execvp/ccvp command
# exec-with-params ccvp execvp
# here [False]
# there [False]
# default [False]
# initialize
# ===============================================================================================
# pydep work flow
# -------------------------
def format_size(size):
if size < 1000:
return '%i' % size + 'size'
elif 1000 <= size < 1000000:
return '%.1f' % float(size / 1000) + 'KB'
elif 1000000 <= size < 1000000000:
return '%.1f' % float(size / 1000000) + 'MB'
elif 1000000000 <= size < 1000000000000:
return '%.1f' % float(size / 1000000000) + 'GB'
elif 1000000000000 <= size:
return '%.1f' % float(size / 1000000000000) + 'TB'
pymaketoolfileroot = pymakefileroot
pymaketoolstartuproot = startupworkdirectory
pydeprequiretxt = 'requirements.txt'
pydep_fileroottxt = ''
#pydep_fileroottxt = os.path.join(pymaketoolfileroot, pydeprequiretxt)
pydep_startuproottxt = ''
#pydep_startuproottxt = os.path.join(pymaketoolstartuproot, pydeprequiretxt)
pydep_sourceroottxt = ''
pydep_sourceroottxt = os.path.join(sourceroot, pydeprequiretxt)
pydep_cmdlinetxt = ''
# if(sys.argv.__len__()>1):
# pydep_cmdlinetxt = os.path.realpath(sys.argv[1])
pydeprequiretxtlist = [
pydep_fileroottxt,
pydep_startuproottxt,
pydep_sourceroottxt,
pydep_cmdlinetxt
]
#print(pydeprequiretxtlist)
pydeprequirepackagelist = []
for file in pydeprequiretxtlist:
if(file == ''):
continue
if(os.path.exists(file) and os.path.isfile(file)):
datas = ""
with open(file, 'r', encoding='utf8') as f:
for line in f.readlines():
datas += line
datas = datas.replace('\r', '')
datalist = datas.split('\n')
for package in datalist:
if(package == ''):
continue
if(pydeprequirepackagelist.__contains__(package)):
continue
pydeprequirepackagelist.append(package)
#print(pydeprequirepackagelist)
pydepjson = os.path.join(sourceroot, 'dep.json')
pydepconfig = {}
d_dep = {
"PyPi": {
"官方源": "https://pypi.python.org/simple",
"清华源": "https://pypi.tuna.tsinghua.edu.cn/simple",
"中科大": "https://mirrors.ustc.edu.cn/pypi/web/simple",
"阿里源": "https://mirrors.aliyun.com/pypi/simple",
"网易源": "https://mirrors.163.com/pypi/simple",
"腾讯源": "https://mirrors.cloud.tencent.com/pypi/simple",
"豆瓣源": "https://pypi.doubanio.com/simple",
"current": "清华源"
},
"Python": {
"Py Launcher": "C:\\Windows\\py.exe",
"-3.7-32": "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe",
"current": "Py Launcher"
}
}
plat = getplatform()
if(plat == 'Windows'):
pass
elif (plat == 'Darwin'):
d_dep['Python'] = {
"3.6": "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3",
"3.7": "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3",
"3.8": "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3",
"current": "3.6"
}
else:
d_dep['Python'] = {
"python 3": "/usr/bin/python3",
"current": "python 3"
}
if(not os.path.exists(pydepjson)):
writeJsonData(pydepjson, d_dep)
if(not os.path.isfile(pydepjson)):
os.removedirs(pydepjson)
writeJsonData(pydepjson, d_dep)
if(os.path.getsize(pydepjson) < 100):
writeJsonData(pydepjson, d_dep)
pydepconfig = readJsonData(pydepjson)
def check_pydepconfig():
# hard
if (pydepconfig.__contains__("PyPi") is False):
pydepconfig['PyPi'] = d_dep['PyPi']
writeJsonData(pydepjson, pydepconfig)
# soft num
order_of_keys = pydepconfig['PyPi'].keys()
list_of_tuples = [key for key in order_of_keys]
if (list_of_tuples.__len__() < 2):
pydepconfig['PyPi'] = d_dep['PyPi']
writeJsonData(pydepjson, pydepconfig)
# soft strip
tempdict = {}
for (k, v) in pydepconfig['PyPi'].items():
current_var = str(k)
current_var_key = current_var.strip()
current_var_value = pydepconfig['PyPi'][current_var].strip()
tempdict[current_var_key] = current_var_value
pydepconfig['PyPi'] = tempdict
# soft current
if (not pydepconfig['PyPi'].__contains__('current')):
''
order_of_keys = pydepconfig['PyPi'].keys()
list_of_tuples = [key for key in order_of_keys]
pydepconfig['PyPi']['current'] = list_of_tuples[0]
if (pydepconfig['PyPi']['current'] == ''):
''
order_of_keys = pydepconfig['PyPi'].keys()
list_of_tuples = [key for key in order_of_keys]
pydepconfig['PyPi']['current'] = list_of_tuples[0]
# move 'current' to be last key
order_of_keys = pydepconfig['PyPi'].keys()
list_of_tuples = [key for key in order_of_keys]
# print(order_of_keys)
# print(list_of_tuples)
# print(list_of_tuples[-1])
if (list_of_tuples[-1] != 'current'):
# print(".....")
current_var = pydepconfig['PyPi']['current']
pydepconfig['PyPi'].__delitem__('current')
pydepconfig['PyPi']['current'] = current_var
writeJsonData(pydepjson, pydepconfig)
# -------------
# hard
if (pydepconfig.__contains__("Python") is False):
pydepconfig['Python'] = d_dep['Python']
writeJsonData(pydepjson, pydepconfig)
# soft num
order_of_keys = pydepconfig['Python'].keys()
list_of_tuples = [key for key in order_of_keys]
if (list_of_tuples.__len__() < 2):
pydepconfig['Python'] = d_dep['Python']
writeJsonData(pydepjson, pydepconfig)
# soft strip
tempdict = {}
for (k, v) in pydepconfig['Python'].items():
current_var = str(k)
current_var_key = current_var.strip()
current_var_value = pydepconfig['Python'][current_var].strip()
tempdict[current_var_key] = current_var_value
pydepconfig['Python'] = tempdict
# soft current
if (not pydepconfig['Python'].__contains__('current')):
''
order_of_keys = pydepconfig['Python'].keys()
list_of_tuples = [key for key in order_of_keys]
pydepconfig['Python']['current'] = list_of_tuples[0]
if (pydepconfig['Python']['current'] == ''):
''
order_of_keys = pydepconfig['Python'].keys()
list_of_tuples = [key for key in order_of_keys]
pydepconfig['Python']['current'] = list_of_tuples[0]
# move 'current' to be last key
order_of_keys = pydepconfig['Python'].keys()
list_of_tuples = [key for key in order_of_keys]
# print(order_of_keys)
# print(list_of_tuples)
# print(list_of_tuples[-1])
if (list_of_tuples[-1] != 'current'):
# print(".....")
current_var = pydepconfig['Python']['current']
pydepconfig['Python'].__delitem__('current')
pydepconfig['Python']['current'] = current_var
writeJsonData(pydepjson, pydepconfig)
check_pydepconfig()
def format_pydepconfig():
# move 'current' to be last key
order_of_keys = pydepconfig['PyPi'].keys()
list_of_tuples = [key for key in order_of_keys]
# print(order_of_keys)
# print(list_of_tuples)
# print(list_of_tuples[-1])
if (list_of_tuples[-1] != 'current'):
# print(".....")
current_var = pydepconfig['PyPi']['current']
pydepconfig['PyPi'].__delitem__('current')
pydepconfig['PyPi']['current'] = current_var
writeJsonData(pydepjson, pydepconfig)
# move 'current' to be last key
order_of_keys = pydepconfig['Python'].keys()
list_of_tuples = [key for key in order_of_keys]
# print(order_of_keys)
# print(list_of_tuples)
# print(list_of_tuples[-1])
if (list_of_tuples[-1] != 'current'):
# print(".....")
current_var = pydepconfig['Python']['current']
pydepconfig['Python'].__delitem__('current')
pydepconfig['Python']['current'] = current_var
writeJsonData(pydepjson, pydepconfig)
format_pydepconfig()
# ===============================================================================================
# pypip work flow
# -------------------------
pipini = ''
plat = getplatform()
if (plat == "Windows"):
piproot = getuserroot() + os.path.sep + 'pip'
if (not os.path.exists(piproot)):
os.mkdir(piproot)
pipini = piproot + os.path.sep + 'pip.ini'
else:
piproot = getuserroot() + os.path.sep + '.pip'
if (not os.path.exists(piproot)):
os.mkdir(piproot)
pipini = piproot + os.path.sep + 'pip.conf'
pipconf = MyConfigParser()
pipconf.read(pipini)
if (not pipconf.has_section('global')):
pipconf.add_section('global')
pipconf.write(open(pipini, 'w'))
if (not pipconf.has_section('install')):
pipconf.add_section('install')
pipconf.write(open(pipini, 'w'))
if (not pipconf.has_option('global', 'index-url')):
pipconf.set('global', 'index-url', 'https://pypi.tuna.tsinghua.edu.cn/simple')
pipconf.write(open(pipini, 'w'))
if (not pipconf.has_option('install', 'trusted-host')):
pipconf.set('install', 'trusted-host', 'mirrors.aliyun.com')
pipconf.write(open(pipini, 'w'))
# ===============================================================================================
# py launcher work flow
# -------------------------
def getlocalconfigroot():
root = ""
sysstr = platform.system()
if (sysstr == "Windows"):
root = os.environ["LOCALAPPDATA"]
else:
root = os.environ["HOME"]
return root
localpyini = ''
plat = getplatform()
if (plat == "Windows"):
localpyini = os.environ["LOCALAPPDATA"] + os.path.sep + 'py.ini'
else:
''
localpyconf = MyConfigParser()
if(plat == 'Windows'):
localpyconf = MyConfigParser()
localpyconf.read(localpyini)
if (not localpyconf.has_section('defaults')):
localpyconf.add_section('defaults')
localpyconf.write(open(localpyini, 'w'))
if (not localpyconf.has_option('defaults', 'python')):
localpyconf.set('defaults', 'python', '')
localpyconf.write(open(localpyini, 'w'))
else:
''
pyini = ''
plat = getplatform()
if (plat == "Windows"):
pyini = os.environ["WINDIR"] + os.path.sep + 'py.ini'
else:
''
pyconf = MyConfigParser()
if(plat == 'Windows'):
pyconf = MyConfigParser()
pyconf.read(pyini)
if (not pyconf.has_section('defaults')):
pyconf.add_section('defaults')
pyconf.write(open(pyini, 'w'))
if (not pyconf.has_option('defaults', 'python')):
pyconf.set('defaults', 'python', '')
pyconf.write(open(pyini, 'w'))
else:
''
# ===============================================================================================
# pydep command work flow
# -------------------------
# print(args)
while (True):
if(args['summary'] is True):
''
def get_pylauncher_python():
plat = getplatform()
if (plat == 'Windows'):
pass
else:
return
cmd_string = str('call "%s" %s' % ('py', '--list-paths'))
plat = getplatform()
if (plat == 'Windows'):
pass
else:
cmd_string = str('"%s" %s' % ('which', 'python3'))
# print("", cmd_string)
result = subprocess.getoutput(cmd_string)
# print("", result)
pylauncher_dict = {}
pylauncher_dict['Py Launcher'] = os.path.join(os.environ['WINDIR'], 'py.exe')
count = 0
for line in result.split('\n'):
# filter line 0
if (count == 0):
count = count + 1
continue
count = count + 1
line = line.strip()
if (line == ''):
continue
# line = line + '\t*'
line = line.replace('\t', ' ')
# default python, named Py Launcher
if (str(line).endswith('*')):
''
# pyname = 'Py Launcher'
key = str(line).split(' ')[0].strip()
value = ' '.join(str(line).split(' ')[1:-1]).strip()
# print('Default:', key, value)
# pylauncher_dict[pyname] = value
pylauncher_dict[key] = value
continue
key = str(line).split(' ')[0].strip()
value = ' '.join(str(line).split(' ')[1:]).strip()
# print(key, value)
pylauncher_dict[key] = value
return pylauncher_dict
def get_where_python3():
cmd_string = str('call "%s" %s' % ('where', 'python3'))
plat = getplatform()
if (plat == 'Windows'):
pass
else:
cmd_string = str('"%s" %s' % ('which', 'python3'))
# print("", cmd_string)
result = subprocess.getoutput(cmd_string)
# print("", result)
pyname = 'Python3-'
if (plat == 'Windows'):
pass
else:
pyname = 'Python3-'
pylauncher_dict = {}
count = 0
for line in result.split('\n'):
count = count + 1
line = line.strip()
if (line == ''):
continue
# line = line + '\t*'
key = pyname + str(count)
value = line
# print(key, value)
pylauncher_dict[key] = value
return pylauncher_dict
def get_where_python():
cmd_string = str('call "%s" %s' % ('where', 'python'))
plat = getplatform()
if (plat == 'Windows'):
pass
else:
cmd_string = str('"%s" %s' % ('which', 'python'))
# print("", cmd_string)
result = subprocess.getoutput(cmd_string)
# print("", result)
pyname = 'Python-'
if (plat == 'Windows'):
pass
else:
pyname = 'Python-'
pylauncher_dict = {}
count = 0
for line in result.split('\n'):
count = count + 1
line = line.strip()
if (line == ''):
continue
# line = line + '\t*'
key = pyname + str(count)
value = line
# print(key, value)
pylauncher_dict[key] = value
return pylauncher_dict
d_pylauncher = get_pylauncher_python()
d_where_python3 = get_where_python3()
d_where_python = get_where_python()
sys_pypi_name = 'Official PyPi'
sys_pypi = 'https://pypi.python.org/simple'
if (pipconf.has_section('global')):
if (pipconf.has_option('global', 'index-url')):
sys_pypi_name = 'Custom PyPi'
sys_pypi = pipconf['global']['index-url']
str_format = ' %-20s : %s'
print('System Python Configure:')
print(' PyPi:')
print(str_format%(sys_pypi_name, sys_pypi))
print(' Python:')
if(plat == 'Windows'):
print(' Py Launcher:')
for (k, v) in d_pylauncher.items():
''
print(str_format%(k, v))
print('')
if (plat == "Windows"):
print(' Where Python3:')
else:
print(' Which Python3:')
for (k, v) in d_where_python3.items():
''
print(str_format%(k, v))
print('')
if (plat == "Windows"):
print(' Where Python:')
else:
print(' Which Python:')
for (k, v) in d_where_python.items():
''
print(str_format % (k, v))
current_var = pydepconfig['PyPi']['current']
current_python = pydepconfig['PyPi'][current_var]
current_pypi_name = current_var
current_pypi = current_python
current_var = pydepconfig['Python']['current']
current_python = pydepconfig['Python'][current_var]
current_python_name = current_var
current_python = current_python
print('')
print('PyDependent Python Configure:')
print(' PyPi:')
print(str(str_format+' [%s]')%('Custom PyPi', current_pypi, current_pypi_name))
print(' Python:')
print(str_format%(current_python_name, current_python))
current_env = rawconfig['environ']['current']
real_python = 'python'
real_python3 = 'python3'
real_python = which_command(current_env, 'python')
real_python3 = which_command(current_env, 'python3')
def lower_command(command = None):
if(command is None):
return command
command = command.replace('\\', '/')
bigexe = command.split('/')[-1]
smallexe = command.split('/')[-1].lower()
command = command.replace(bigexe, smallexe)
if (plat == 'Windows'):
command = command.replace('/', '\\')
else:
command = command.replace('\\', '/')
return command
real_python = lower_command(real_python)
real_python3 = lower_command(real_python3)
print('')
print('Environ Python Configure:')
print(str_format % ('python', real_python))
print(str_format % ('python3', real_python3))
print('')
print('Python Summary: list python and pypi summary success.')
break
while (True):
if(args['save'] is True):
''
if(args['pypi'] is True):
''
if(args['<pypi-name>'] is None):
print('System PyPi Setting:')
print(' Configure:', pipini)
print(' PyPi:', pipconf['global']['index-url'])
print('')
print('Please input PyPi name.')
return
current_item_key = args['<pypi-name>']
current_item_key = current_item_key.strip('"')
current_item_key = current_item_key.strip('\\')
current_item_key = current_item_key.strip('\'')
if(args['<pypi-name>'] is None):
current_item_key = 'current'
current_var = pydepconfig['PyPi']['current']
if (current_item_key == 'current'):
current_item_key = current_var
if (current_item_key == ''):
print('PyPi: please check your pypi name, it cant be empty.')
return
if (pydepconfig['PyPi'].__contains__(current_item_key) is False):
print('PyPi: please check your pypi name %s, it is not existed.' % (current_item_key))
return
current_item_value = pydepconfig['PyPi'][current_item_key]
pipconf.set('global', 'index-url', current_item_value)
pipconf.write(open(pipini, 'w'))
print('%s: %s' % (current_item_key, current_item_value))
print('Save PyPi for current user success.')
return
elif (args['python'] is True):
''
if(args['<python-name>'] is None):
plat = getplatform()
if(plat == 'Windows'):
print('System Python Setting:')
print(' Configure:', pyini)
print(' Python:', pyconf['defaults']['python'])
print(' Configure:', localpyini)
print(' Python:', localpyconf['defaults']['python'])
else:
''
print('')
print('Please input Python name.')
return
current_item_key = args['<python-name>']
current_item_key = current_item_key.strip('"')
current_item_key = current_item_key.strip('\\')
current_item_key = current_item_key.strip('\'')
if (args['<python-name>'] is None):
current_item_key = 'current'
current_var = pydepconfig['Python']['current']
if (current_item_key == 'current'):
current_item_key = current_var
if (current_item_key == ''):
print('Python: please check your python name, it cant be empty.')
return
if (pydepconfig['Python'].__contains__(current_item_key) is False):
print('Python: please check your python name %s, it is not existed.' % (current_item_key))
return
current_item_value = pydepconfig['Python'][current_item_key]
plat = getplatform()
if (plat == 'Windows'):
if (args['for'] and args['current'] and args['user'] is True):
''
current_item_key_pylauncher = current_item_key.strip('-')
localpyconf.set('defaults', 'python', current_item_key_pylauncher)
localpyconf.write(open(localpyini, 'w'))
print('%s: %s' % (current_item_key, current_item_value))
print('Save Python for current user success. [%s]' % (current_item_key_pylauncher))
return
current_item_key_pylauncher = current_item_key.strip('-')
pyconf.set('defaults', 'python', current_item_key_pylauncher)
pyconf.write(open(pyini, 'w'))
print('%s: %s' % (current_item_key, current_item_value))
print('Save Python for system success. [%s]' % (current_item_key_pylauncher))
else:
''
return
break
while (True):
if(args['get'] is True):
''
if(args['pypi'] is True):
''
current_item_key = args['<pypi-name>']
if(args['<pypi-name>'] is None):
''
current_item_key = 'current'
current_var = pydepconfig['PyPi']['current']
if (current_item_key == 'current'):
current_item_key = current_var
if (current_item_key == 'current'):
print('PyPi: please check your dep.json configure, the pypi key for value cant be current.')
return
if (current_item_key == ''):
print('PyPi: please check your pypi name, it cant be empty.')
return
if (pydepconfig['PyPi'].__contains__(current_item_key) is False):
print('PyPi: please check your pypi name %s, it is not existed.' % (current_item_key))
return
current_item_value = pydepconfig['PyPi'][current_item_key]
print('%s: %s' % (current_item_key, current_item_value))
return
elif(args['python'] is True):
''
current_item_key = args['<python-name>']
if(args['<python-name>'] is None):
''
current_item_key = 'current'
current_var = pydepconfig['Python']['current']
if (current_item_key == 'current'):
current_item_key = current_var
if (current_item_key == 'current'):
print('Python: please check your dep.json configure, the python key for value cant be current.')
return
if (current_item_key == ''):
print('Python: please check your python name, it cant be empty.')
return
if (pydepconfig['Python'].__contains__(current_item_key) is False):
print('Python: please check your python name %s, it is not existed.' % (current_item_key))
return
current_item_value = pydepconfig['Python'][current_item_key]
print('%s: %s' % (current_item_key, current_item_value))
return
else:
''
return
elif(args['set'] is True):
''
if(args['pypi'] is True):
''
if(args['<pypi-name>'] is None):
print('PyPi: please input a pypi name.')
return
current_item_key = args['<pypi-name>']
current_item_key = current_item_key.strip('"')
current_item_key = current_item_key.strip('\\')
current_item_key = current_item_key.strip('\'')
if (current_item_key == 'current'):
print('PyPi: please check your pypi name, it cant be current.')
return
if (current_item_key == ''):
print('PyPi: please check your pypi name, it cant be empty.')
return
if (pydepconfig['PyPi'].__contains__(current_item_key) is False):
print('PyPi: please check your pypi name %s, it is not existed.' % (current_item_key))
return
current_item_value = pydepconfig['PyPi'][current_item_key]
pydepconfig['PyPi']['current'] = current_item_key
check_pydepconfig()
writeJsonData(pydepjson, pydepconfig)
print('PyPi: set current pypi source success, %s: %s' % (current_item_key, current_item_value))
return
elif(args['python'] is True):
''
if(args['<python-name>'] is None):
print('Python: please input a python name.')
return
current_item_key = args['<python-name>']
current_item_key = current_item_key.strip('"')
current_item_key = current_item_key.strip('\\')
current_item_key = current_item_key.strip('\'')
if (current_item_key == 'current'):
print('Python: please check your python name, it cant be current.')
return
if (current_item_key == ''):
print('Python: please check your python name, it cant be empty.')
return
if (pydepconfig['Python'].__contains__(current_item_key) is False):
print('Python: please check your python name %s, it is not existed.' % (current_item_key))
return
current_item_value = pydepconfig['Python'][current_item_key]
pydepconfig['Python']['current'] = current_item_key
check_pydepconfig()
writeJsonData(pydepjson, pydepconfig)
print('Python: set current python success, %s: %s' % (current_item_key, current_item_value))
return
else:
''
return
break
while (True):
if (args['collect'] and args['pypi'] is True):
''
current_item_value = pipconf['global']['index-url']
pypi_list = [ v for (k, v) in pydepconfig['PyPi'].items() ]
# print(pypi_list)
if( not pypi_list.__contains__(current_item_value) ):
''
if (current_item_value == ''):
continue
count = 0
current_item_key = 'UserPyPi-'+str(count)
while (True):
count = count + 1
current_item_key = 'UserPyPi-' + str(count)
if(pydepconfig['PyPi'].__contains__(current_item_key)):
continue
pydepconfig['PyPi'][current_item_key] = current_item_value
check_pydepconfig()
writeJsonData(pydepjson, pydepconfig)
break
print('PyPi List:')
str_format = ' %-24s %s'
current_var = pydepconfig['PyPi']['current']
for (k, v) in pydepconfig['PyPi'].items():
if(str(k) == 'current'):
continue
if(str(k) == current_var):
print(Fore.GREEN + str_format % (str(k), str(v)))
continue
print(str_format % (str(k), str(v)))
print('Current PyPi:')
print(str_format % ('Configure:', pipini))
print(str_format % (current_var, pydepconfig['PyPi'][current_var]))
return
break
while(True):
if (args['collect'] and args['python'] and args['py'] and args['launcher'] is True):
''
plat = getplatform()
if (plat == 'Windows'):
pass
else:
return
cmd_string = str('call "%s" %s' % ('py', '--list-paths'))
plat = getplatform()
if (plat == 'Windows'):
pass
else:
cmd_string = str('"%s" %s' % ('which', 'python3'))
# print("", cmd_string)
result = subprocess.getoutput(cmd_string)
# print("", result)
pylauncher_dict = {}
pylauncher_dict['Py Launcher'] = os.path.join(os.environ['WINDIR'], 'py.exe')
count = 0
for line in result.split('\n'):
# filter line 0
if (count == 0):
count = count + 1
continue
count = count + 1
line = line.strip()
if (line == ''):
continue
# line = line + '\t*'
line = line.replace('\t', ' ')
# default python, named Py Launcher
if (str(line).endswith('*')):
''
# pyname = 'Py Launcher'
key = str(line).split(' ')[0].strip()
value = ' '.join(str(line).split(' ')[1:-1]).strip()
# print('Default:', key, value)
# pylauncher_dict[pyname] = value
pylauncher_dict[key] = value
continue
key = str(line).split(' ')[0].strip()
value = ' '.join(str(line).split(' ')[1:]).strip()
# print(key, value)
pylauncher_dict[key] = value
for (k, v) in pylauncher_dict.items():
''
current_item_key = str(k)
current_item_value = str(v)
if (current_item_key == 'current'):
continue
if (current_item_key == ''):
continue
if (current_item_value == ''):
continue
pydepconfig['Python'][current_item_key] = current_item_value
check_pydepconfig()
writeJsonData(pydepjson, pydepconfig)
print('Python List:')
str_format = ' %-24s %s'
current_var = pydepconfig['Python']['current']
for (k, v) in pydepconfig['Python'].items():
if (str(k) == 'current'):
continue
if (str(k) == current_var):
print(Fore.GREEN + str_format % (str(k), str(v)))
continue
print(str_format % (str(k), str(v)))
print('Current Python:')
print(str_format % (current_var, pydepconfig['Python'][current_var]))
print('')
print('PyDep: refresh py launcher success.')
return
break
while (True):
if (args['collect'] and args['python'] is True):
''
cmd_string = str('call "%s" %s' % ('where', 'python'))
plat = getplatform()
if (plat == 'Windows'):
pass
else:
cmd_string = str('"%s" %s' % ('which', 'python'))
# print("", cmd_string)
result = subprocess.getoutput(cmd_string)
# print("", result)
pyname = 'Python-'
if (plat == 'Windows'):
pass
else:
pyname = 'Python-'
pylauncher_dict = {}
count = 0
for line in result.split('\n'):
count = count + 1
line = line.strip()
if (line == ''):
continue
# line = line + '\t*'
key = pyname + str(count)
value = line
# print(key, value)
pylauncher_dict[key] = value
for (k, v) in pylauncher_dict.items():
''
current_item_key = str(k)
current_item_value = str(v)
if (current_item_key == 'current'):
continue
if (current_item_key == ''):
continue
if (current_item_value == ''):
continue
pydepconfig['Python'][current_item_key] = current_item_value
check_pydepconfig()
writeJsonData(pydepjson, pydepconfig)
print('Python List:')
str_format = ' %-24s %s'
current_var = pydepconfig['Python']['current']
for (k, v) in pydepconfig['Python'].items():
if (str(k) == 'current'):
continue
if (str(k) == current_var):
print(Fore.GREEN + str_format % (str(k), str(v)))
continue
print(str_format % (str(k), str(v)))
print('Current Python:')
print(str_format % (current_var, pydepconfig['Python'][current_var]))
print('')
print('PyDep: refresh python success.')
return
break
while (True):
if (args['pip'] is True):
''
if (args['here'] or args['hh'] is True):
os.chdir(startupworkdirectory)
elif (args['there'] or args['tt'] is True):
os.chdir(customshellroot)
elif (args['default'] or args['dd'] is True):
os.chdir(defaultshellroot)
# print(args['--workroot'])
if (args['--workroot'] is not None):
if (os.path.isdir(args['--workroot'])
and os.path.isabs(args['--workroot'])):
os.chdir(args['--workroot'])
else:
print('please input an existed and legal work root.')
return
if(args['<pip-command>'] == ['']):
args['<pip-command>'] = []
if(args['<pip-command>'] != []):
current_env = rawconfig['environ']['current']
if (current_env == 'current'
or rawconfig['environ'].__contains__(current_env) is False):
print(".json file is broken, environ section current env config is lost, please use set command fix it.")
return
current_var = pydepconfig['Python']['current']
current_item_key = current_var
current_item_value = pydepconfig['Python'][current_var]
if(args['for'] is True and args['<python-name>'] is not None):
''
current_item_key = args['<python-name>']
current_item_key = current_item_key.strip('"')
current_item_key = current_item_key.strip('\\')
current_item_key = current_item_key.strip('\'')
if (args['<python-name>'] is None):
current_item_key = 'current'
current_var = pydepconfig['Python']['current']
if (current_item_key == 'current'):
current_item_key = current_var
if (current_item_key == ''):
print('Python: please check your python name, it cant be empty.')
return
if (pydepconfig['Python'].__contains__(current_item_key) is False):
print('Python: please check your python name %s, it is not existed.' % (current_item_key))
return
current_item_value = pydepconfig['Python'][current_item_key]
current_python = current_item_value
current_var = pydepconfig['Python']['current']
current_item_key = current_var
current_item_value = pydepconfig['Python'][current_var]
current_item_value = ''
if (args['use'] is True and args['<pypi-name>'] is not None):
''
current_item_key = args['<pypi-name>']
current_item_key = current_item_key.strip('"')
current_item_key = current_item_key.strip('\\')
current_item_key = current_item_key.strip('\'')
if (args['<pypi-name>'] is None):
current_item_key = 'current'
current_var = pydepconfig['PyPi']['current']
if (current_item_key == 'current'):
current_item_key = current_var
if (current_item_key == ''):
print('PyPi: please check your pypi name, it cant be empty.')
return
if (pydepconfig['PyPi'].__contains__(current_item_key) is False):
print('PyPi: please check your pypi name %s, it is not existed.' % (current_item_key))
return
current_item_value = pydepconfig['PyPi'][current_item_key]
current_pypi = current_item_value
# create cmd_list
list0 = []
local = True
params0 = []
# print(args['--params'])
# print(args['<command-params>'])
for current_var in args['<pip-command>']:
for item in current_var.split(' '):
item = item.strip('"')
item = item.strip('\\')
item = item.strip('\'')
params0.append(item)
cmd_line = current_python + ' -m pip ' + ' '.join(params0)
if(current_pypi != ''):
cmd_line = current_python + ' -m pip ' + ' '.join(params0) + ' -i ' + current_pypi
list0.append(cmd_line)
local = False
params0 = []
# print(args['--params'])
# print(args['<command-params>'])
for current_var in args['<pip-command>']:
for item in current_var.split(' '):
params0.append(item)
params0 = []
cmd_list = []
temp_file_name = ""
# if (getplatform() == "Windows"):
# cmd_list, temp_file_name = createCmdList0(list0)
# else:
# cmd_list, temp_file_name = createCmdList01(list0)
# good compatibility
cmd_list, temp_file_name = createCmdList02(current_env, local, list0, params0)
# export env
current_var = current_env
# print (current_var, temp_file_name)
env_export(current_var, temp_file_name)
ret = communicateWithCommandLine(cmd_list)
# delete env file and cmd file
if (getplatform() == "Windows"):
temp_file = temp_file_name + "_exec.bat"
if (os.path.exists(temp_file)):
os.remove(temp_file)
temp_file = temp_file_name + "_effect.bat"
if (os.path.exists(temp_file)):
os.remove(temp_file)
temp_file = temp_file_name + "_unset.bat"
if (os.path.exists(temp_file)):
os.remove(temp_file)
else:
temp_file = temp_file_name + "_exec.sh"
if (os.path.exists(temp_file)):
os.remove(temp_file)
temp_file = temp_file_name + "_effect.sh"
if (os.path.exists(temp_file)):
os.remove(temp_file)
temp_file = temp_file_name + "_unset.sh"
if (os.path.exists(temp_file)):
os.remove(temp_file)
os._exit(ret)
return
# print('Pip Information:')
# str_format = ' %-24s %s'
cmd_string = str('call "%s" %s' % ('py', '-m pip --help'))
plat = getplatform()
if (plat == 'Windows'):
pass
else:
cmd_string = str('"%s" %s' % ('python3', '-m pip --help'))
# print(cmd_string)
result = subprocess.getoutput(cmd_string)
# print(result)
help_string = result
cmd_string = str('call "%s" %s' % ('py', '-m pip --version'))
plat = getplatform()
if (plat == 'Windows'):
pass
else:
cmd_string = str('"%s" %s' % ('python3', '-m pip --version'))
# print(cmd_string)
result = subprocess.getoutput(cmd_string)
# print(result)
version_string = result
print(help_string)
print('')
print('Version:')
print(" ", version_string)
return
break
while (True):
if (args['pypi'] is True):
''
if(args['add'] is True):
if(args['<pypi-name>'] is not None and args['<pypi-source-url>'] is not None):
''
current_item_key = args['<pypi-name>']
current_item_value = args['<pypi-source-url>']
current_item_key = current_item_key.strip('"')
current_item_key = current_item_key.strip('\\')
current_item_key = current_item_key.strip('\'')
if (current_item_key == 'current'):
print('PyPi: please check your pypi name, it cant be current.')
return
if (current_item_key == ''):
print('PyPi: please check your pypi name, it cant be empty.')
return
if (current_item_value == ''):
print('PyPi: please check your pypi source url, it cant be empty.')
return
pydepconfig['PyPi'][current_item_key] = current_item_value
check_pydepconfig()
writeJsonData(pydepjson, pydepconfig)
print('PyPi: add pypi source success, %s: %s' % (current_item_key, current_item_value))
return
if(args['del'] is True):
if(args['<pypi-name>'] is not None):
''
current_item_key = args['<pypi-name>']
current_item_key = current_item_key.strip('"')
current_item_key = current_item_key.strip('\\')
current_item_key = current_item_key.strip('\'')
if (current_item_key == 'current'):
print('PyPi: please check your pypi name, it cant be current.')
return
if (current_item_key == ''):
print('PyPi: please check your pypi name, it cant be empty.')
return
if (pydepconfig['PyPi'].__contains__(current_item_key) is False):
print('PyPi: please check your pypi name %s, it is not existed.' % (current_item_key))
return
current_var = pydepconfig['PyPi']['current']
if ( current_var == current_item_key):
print('PyPi: please check your pypi name, you cant remove current using item.')
return
current_item_value = pydepconfig['PyPi'][current_item_key]
pydepconfig['PyPi'].__delitem__(current_item_key)
check_pydepconfig()
writeJsonData(pydepjson, pydepconfig)
print('PyPi: remove pypi source success, %s: %s' % (current_item_key, current_item_value))
return
print('PyPi List:')
str_format = ' %-24s %s'
current_var = pydepconfig['PyPi']['current']
for (k, v) in pydepconfig['PyPi'].items():
if(str(k) == 'current'):
continue
if(str(k) == current_var):
print(Fore.GREEN + str_format % (str(k), str(v)))
continue
print(str_format % (str(k), str(v)))
print('Current PyPi:')
# print(str_format % ('Configure:', pipini))
print(str_format % (current_var, pydepconfig['PyPi'][current_var]))
return
break
while (True):
if (args['python'] is True):
''
if(args['add'] is True):
if(args['<python-name>'] is not None and args['<python-path>'] is not None):
''
current_item_key = args['<python-name>']
current_item_value = args['<python-path>']
current_item_key = current_item_key.strip('"')
current_item_key = current_item_key.strip('\\')
current_item_key = current_item_key.strip('\'')
if (current_item_key == 'current'):
print('Python: please check your python name, it cant be current.')
return
if (current_item_key == ''):
print('Python: please check your python name, it cant be empty.')
return
if (current_item_value == ''):
print('Python: please check your python source url, it cant be empty.')
return
pydepconfig['Python'][current_item_key] = current_item_value
check_pydepconfig()
writeJsonData(pydepjson, pydepconfig)
print('Python: add python item success, %s: %s' % (current_item_key, current_item_value))
return
if(args['del'] is True):
if(args['<python-name>'] is not None):
''
current_item_key = args['<python-name>']
current_item_key = current_item_key.strip('"')
current_item_key = current_item_key.strip('\\')
current_item_key = current_item_key.strip('\'')
if (current_item_key == 'current'):
print('Python: please check your python name, it cant be current.')
return
if (current_item_key == ''):
print('Python: please check your python name, it cant be empty.')
return
if (pydepconfig['Python'].__contains__(current_item_key) is False):
print('Python: please check your python name %s, it is not existed.' % (current_item_key))
return
current_var = pydepconfig['Python']['current']
if ( current_var == current_item_key):
print('Python: please check your python name, you cant remove current using item.')
return
current_item_value = pydepconfig['Python'][current_item_key]
pydepconfig['Python'].__delitem__(current_item_key)
check_pydepconfig()
writeJsonData(pydepjson, pydepconfig)
print('Python: remove python item success, %s: %s' % (current_item_key, current_item_value))
return
print('Python List:')
str_format = ' %-24s %s'
current_var = pydepconfig['Python']['current']
for (k, v) in pydepconfig['Python'].items():
if (str(k) == 'current'):
continue
if (str(k) == current_var):
print(Fore.GREEN + str_format % (str(k), str(v)))
continue
print(str_format % (str(k), str(v)))
print('Current Python:')
print(str_format % (current_var, pydepconfig['Python'][current_var]))
return
break
return
if __name__ == '__main__':
ret = main_function()
if (ret == None):
ret = 0
os._exit(ret)
Python
1
https://gitee.com/drabel/PyMake.git
git@gitee.com:drabel/PyMake.git
drabel
PyMake
Multi-environ Technology(PyMake)
master

搜索帮助