当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 9

zijunma/Multi-environ Manager
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pymake6.py 52.03 KB
一键复制 编辑 原始数据 按行查看 历史
T.D.R. 提交于 2018-06-03 12:40 . update here command
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
# -*- coding: utf-8 -*-
#!/usr/bin/env python
"""PyMake 6.2.
Usage:
pymake6.py source
pymake6.py source root [ <source-root-path> ]
pymake6.py source config [ --add | --del | --mod | --switch | --restore | --show ] [ <config-file-name> ] [<new-config-file-name>]
pymake6.py set path ( --add | --del | --mod ) <name> [ <value> ]
pymake6.py set env [ path ] ( --add | --del | --mod ) <group> <name> [ <value> ]
pymake6.py set cmd (--add | --del | --mod ) <name> [ <values> ... ]
pymake6.py set cur env <name>
pymake6.py list [ path | env | cmd ] [<name>] [-r | --raw] [-a | --all]
pymake6.py here clean
pymake6.py here exec [ <command-names> ... ]
pymake6.py here use <env-name> exec [ <command-names> ... ]
pymake6.py export [ <env-name> ] [ to <file-name> ]
pymake6.py type [ <cmd-name> ] [ to <file-name> ]
pymake6.py clean [here]
pymake6.py use <env-name> exec [ here ] [ <command-names> ... ]
pymake6.py exec [ here ] [ <command-names> ... ]
pymake6.py (-h | --help)
pymake6.py --version
Command:
source switch to another source file
source root config root directory
source config config source conf file
set path path assessblage
set env set env variable
set cmd set cmd stream
export output private env variable to a bat file or sh file [default:current, env]
list list configed values
set cur env set default env
use use selected env exec commands
here at here exec commands
exec exec commands list
clean clean *_effect.sh *_unset.sh
Options:
-h --help Show this screen.
--version Show version.
--add
--del
--mod add or delete or modify a config or path
--switch switch to another source
--show display haved stream config files
--restore reset to pymake.json stream config file
-r, --raw expand editing config values
"""
import os
import re
import sys
import uuid
import shutil
import time
import json
import copy
import types
from pycore.pycore import *
from pycore.docopt import docopt
def main_function():
d = {
"path-assemblage": {
"root": "/Users/abel/Develop",
"root.src": "${root}/a0-develop",
"root.prod": "${root}/b1-product",
"root.tool": "${root}/b0-toolskits",
"root.build": "${root}/c0-buildstation",
"root.test": "${root}/c2-test",
"root.webrc": "${root}/c1-webrc",
"cc": "${root.tool}/compiler",
"cmake.bin": "${cc}/CMake.app/Contents/bin",
"qt": "${root.tool}/macLibraries/Qt",
"qt5.9.clang": "${qt}/5.9.1/clang_64",
"qt5.8.android_x86": "${qt}/5.8/android_x86",
"qt5.8.android_arm": "${qt}/5.8/android_armv7",
"qt5.8.clang": "${qt}/5.8/clang_64",
"qt5.8.ios": "${qt}/5.8/ios",
"qt4.8.clang": "${qt}/4.8.7/clang_64",
"qt5.9.clang.bin": "${qt}/5.9.1/clang_64/bin",
"qt5.8.android_x86.bin": "${qt}/5.8/android_x86/bin",
"qt5.8.android_arm.bin": "${qt}/5.8/android_armv7/bin",
"qt5.8.clang.bin": "${qt}/5.8/clang_64/bin",
"qt5.8.ios.bin": "${qt}/5.8/ios/bin",
"qt4.8.clang.bin": "${qt}/4.8.7/clang_64/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",
"mac.sdk": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
},
"environ": {
"android.mobile": {
"path+": [
"${cmake.bin}",
"${qt5.8.android_arm.bin}",
"${java1.8.bin}",
"${android.sdk}",
"${sdk.plat.tool}",
"${sdk.build.tool}",
"${sdk.tool}",
"${ant.bin}",
"${ndk.arm.bin}"
],
"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",
"PYMAKE_MYNAME": "T.D.R",
"a_special_var_const": "hello world",
"QKIT": "Android",
"QTDIR": "${qt5.8.android_arm}",
"QTSPEC": "android-g++",
"QTCONFIG": "arm",
"JAVA_HOME": "${java1.8.home}",
"CLASSPATH": ".:${JAVA_HOME}/lib/dt/jar:${JAVA_HOME}/lib/tools.jar"
},
"android.x86": {
"path+": [
"${cmake.bin}",
"${qt5.8.android_x86.bin}",
"${java1.8.bin}",
"${android.sdk}",
"${sdk.plat.tool}",
"${sdk.build.tool}",
"${sdk.tool}",
"${ant.bin}",
"${ndk.x86.bin}"
],
"CLICOLOR": "1",
"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": "x86",
"ANDROID_NDK_TOOLCHAIN_VERSION": "4.9",
"ANDROID_NDK_PLATFORM": "android-23",
"NDK_TOOLCHAIN_PATH": "${ndk.x86.bin}",
"NDK_TOOLS_PREFIX": "i686-linux-android",
"QKIT": "Android",
"QTDIR": "${qt5.8.android_x86}",
"QTSPEC": "android-g++",
"QTCONFIG": "arm",
"JAVA_HOME": "${java1.8.home}",
"CLASSPATH": ".:${JAVA_HOME}/lib/dt/jar:${JAVA_HOME}/lib/tools.jar"
},
"qt.mac": {
"path+": [
"${cmake.bin}",
"${qt5.9.clang.bin}",
"${java1.8.bin}",
"${android.sdk}",
"${sdk.plat.tool}",
"${sdk.build.tool}",
"${sdk.tool}",
"${ant.bin}",
"${ndk.arm.bin}"
],
"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": "i686-linux-android",
"ANDROID_NDK_TOOLCHAIN_VERSION": "4.9",
"ANDROID_NDK_PLATFORM": "android-23",
"NDK_TOOLCHAIN_PATH": "${ndk.arm.bin}",
"NDK_TOOLS_PREFIX": "i686-linux-android",
"QKIT": "macOS",
"QTDIR": "${qt5.9.clang}",
"QTSPEC": "macx-clang",
"QTCONFIG": "x86_64",
"JAVA_HOME": "${java1.8.home}",
"CLASSPATH": ".:${JAVA_HOME}/lib/dt/jar:${JAVA_HOME}/lib/tools.jar"
},
"current": "qt.mac"
},
"variable-assemblage": [
"QQt",
"a0-qqtfoundation",
"${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-assemblage": [
"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"
],
"command": {
"qqt.build": [
"mkdir -p ${app.path.build}",
"cd ${app.path.build}",
"qmake ${app.path.qmake} -spec ${QTSPEC} CONFIG+=${QTCONFIG} && make qmake_all",
"make -j4"
],
"qqt.rebuild": [
"cd ${app.path.build}",
"make clean",
"qmake ${app.path.qmake} -spec ${QTSPEC} CONFIG+=${QTCONFIG} && make qmake_all",
"make -j4"
],
"qqt.clean": [
"cd ${app.path.build}",
"make clean"
],
"qqt.install": [
"cd ${app.path.build}",
"make install"
],
"qqt.deploy": [
"cd ${app.path.build}",
"${app.deploy}"
],
"buildqt5android": [
"mkdir -p ${qt5.path.build}",
"cd ${qt5.path.build}",
"${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"
],
"qt": [
"cd ${root.build}",
"open \"/Applications/Qt Creator.app\""
],
"adb": [
"adb devices"
],
"android": [
"/Users/abel/Develop/b0-toolskits/macAndroidLibraries/android-sdk-macosx/tools/android"
]
}
}
"""
[pymake]
[source]
root = ~/.pymake
config = pymake.json
"""
userroot = getuserroot()
configroot = getconfigroot()
plat = getplatform()
if( plat == "Windows"):
pymakeroot = configroot + os.path.sep + 'pymake'
else:
pymakeroot = userroot + os.path.sep + '.pymake'
if (not os.path.exists(pymakeroot)):
os.makedirs(pymakeroot)
#initial pymake.ini
pymakeini = pymakeroot + os.path.sep + 'pymake.ini'
conf = MyConfigParser()
conf.read(pymakeini)
if( not conf.has_section('pymake') ):
conf.add_section('pymake')
conf.write(open(pymakeini, 'w'))
if( not conf.has_section('source') ):
conf.add_section('source')
conf.write(open(pymakeini, 'w'))
if( not conf.has_option('source', 'root') ):
conf.set('source', 'root', pymakeroot)
conf.write(open(pymakeini, 'w'))
if(not conf.has_option('source', 'config')):
conf.set('source', 'config', 'pymake.json')
conf.write(open(pymakeini, 'w'))
args = docopt(__doc__, version='pymake6.py v6.2')
#print(args)
pymakesuffix = '.json'
while (True):
if(args['source'] is True):
if(args['root'] is True):
if ( args['<source-root-path>'] is not None):
conf.set('source', 'root', args['<source-root-path>'])
conf.write(open(pymakeini, 'w'))
print ("success root: %s" % args['<source-root-path>'])
else:
print ("%s" % conf.get('source', 'root'))
elif(args['config'] is True):
sourceroot = conf.get('source', 'root')
os.chdir(sourceroot)
if(args['--del'] is True):
if (args['<config-file-name>'] is not None and args['<config-file-name>'] == 'pymake.json'):
print('You can\'t remove pymake\'s file...')
elif (args['<config-file-name>'] is not None and args['<config-file-name>'].endswith(pymakesuffix)):
os.remove(args['<config-file-name>'])
conf.set('source', 'config', 'pymake.json')
conf.write(open(pymakeini, 'w'))
print ("success: %s" % args['<config-file-name>'])
else:
print ('You can\'t remove pymake.json and un.json\'s file...')
elif(args['--add'] is True):
if (args['<config-file-name>'] is not None and args['<config-file-name>'].endswith(pymakesuffix) and args['<config-file-name>'] != 'pymake.json'):
f = conf.get('source', 'config')
if( f != args['<config-file-name>']):
shutil.copyfile(f, args['<config-file-name>'])
conf.set('source', 'config', args['<config-file-name>'])
conf.write(open(pymakeini, 'w'))
print ("success: %s" % args['<config-file-name>'])
else:
print('You can\'t add same named file...')
else:
print ('You can\'t add pymake.json and un.json\'s file...')
elif (args['--mod'] is True):
if ( ( args['<config-file-name>'] and args['<new-config-file-name>']) is not None and args['<config-file-name>'].endswith(pymakesuffix)):
os.rename(args['<config-file-name>'],args['<new-config-file-name>'])
f = conf.get('source', 'config')
if (f == args['<config-file-name>']):
conf.set('source', 'config',args['<new-config-file-name>'])
conf.write(open(pymakeini, 'w'))
print ("success: %s" % args['<new-config-file-name>'])
else:
print ('You can\'t mod pymake.json and un.json\'s file...')
elif(args['--show'] is True):
files = os.listdir(os.getcwd())
for f in files:
if (f.endswith(pymakesuffix)):
print(f)
elif(args['--restore'] is True):
conf.set('source', 'config', 'pymake.json')
conf.write(open(pymakeini, 'w'))
print ("success: %s" % 'pymake.json')
elif (args['--switch'] is True or ( args['<config-file-name>'] is not None )):
if (args['<config-file-name>'] is not None and args['<config-file-name>'].endswith(pymakesuffix) ):
if (os.path.exists(args['<config-file-name>'])):
conf.set('source', 'config', args['<config-file-name>'])
conf.write(open(pymakeini, 'w'))
print("switch to source config: %s" % args['<config-file-name>'])
else:
print("source file %s isn't exists, please --add it" % args['<config-file-name>'])
else:
print ('You can\'t switch pymake.json and un.json\'s file...')
else:
print ("%s" % conf.get("source", "config"))
else:
r = conf.get('source', 'root')
f = conf.get('source', 'config')
print ("%s%s%s" % (r, os.path.sep, f))
return
else:
''
break
sourceroot = conf.get('source', 'root')
file = conf.get('source', 'config')
#print ("root: %s config: %s" % (sourceroot, file))
#print(Fore.LIGHTBLACK_EX + "use source config: %s/%s" % (sourceroot, file) )
#record current directory
initpath = os.getcwd()
if (os.path.exists(sourceroot)):
# chdir to source root
os.chdir(sourceroot)
else:
print("You have changed sourceroot manual, please change it using source command")
return
pymakefilepath = os.path.split(os.path.realpath(__file__))[0]
if (os.path.abspath(sourceroot) == os.path.abspath(pymakeroot) or
os.path.abspath(sourceroot) == os.path.abspath(pymakefilepath)):
print ("I checked you use pymakeroot or pymakefileroot to be sourceroot, suggestting you use source command changing one.")
print ("this progrom can store building env and building command forever, please repleace source root then using me.")
return
elif (os.path.abspath(sourceroot) != os.path.abspath(pymakeroot)):
if (not os.path.exists('pymake.json')):
writeJsonData('pymake.json', d)
print ("initial pymake.json in source root.")
if(not os.path.exists(file)):
print ("source config file is not exist.")
return
config = readJsonData(file)
#print(config)
#set
while (True):
if (args['set'] == True):
if (args['env'] is True):
if (args['cur'] == True):
if (args["<name>"] is not None):
config["environ"]["current"] = args["<name>"]
print("successed %s" % (args['<name>']))
else:
""
elif (args["path"] is True):
if (args['--add'] == True):
if (args['<group>'] and args['<name>'] is not None):
config['environ'][args['<group>']]["path+"].append(args["<name>"])
print ("successed %s:%s" % (args['<group>'], args['<name>']))
else:""
elif (args['--del'] == True):
if (args['<group>'] and args["<name>"] is not None):
if (config['environ'][args['<group>']]["path+"].__contains__(args['<name>'])):
config['environ'][args['<group>']]["path+"].__delitem__(args['<name>'])
print("successed %s:%s" % (args['<group>'], args['<name>']))
else:
print("failed %s:%s" % (args['<group>'], args['<name>']))
else:
''
elif (args['--mod'] == True):
if (args['<group>'] and args['<name>'] and args["<value>"] is not None):
if (config['variable'][args['<group>']]["path+"].__contains__(args['<name>'])):
index = config['variable'][args['<group>']]["path+"].index(args['<name>'])
config['variable'][args['<group>']]["path+"][index] = [args['<value>']]
print ("successed %s:%s:%s" % (args['<group>'], args['<name>'], args["<value>"]))
else:
print("failed %s:%s" % (args['<group>'], args['<name>']))
else:
''
else:
if (args['--add'] == True):
if (args['<group>'] and args['<name>'] and args["<value>"] is not None):
config['environ'][args['<group>']][args['<name>']] = args["<value>"]
print ("successed %s:%s:%s" % (args['<group>'], args['<name>'], args["<value>"]))
else:
print ("failed %s:%s:%s" % (args['<group>'], args['<name>'], args["<value>"]))
elif (args['--del'] == True):
if (args['<group>'] and args["<name>"] is not None):
if (config['variable'][args['<group>']].__contains__(args['<name>'])):
config['variable'][args['<group>']].__delitem__(args['<name>'])
print ("successed %s:%s" % (args['<group>'], args['<name>']))
else:
print ("failed %s:%s" % (args['<group>'], args['<name>']))
else:
''
elif (args['--mod'] == True):
if (args['<group>'] and args['<name>'] and args["<value>"] is not None):
if (config['variable'][args['<group>']].__contains__(args['<name>'])):
config['variable'][args['<group>']][args['<name>']] = args["<value>"]
print ("successed %s:%s:%s" % (args['<group>'], args['<name>'], args["<value>"]))
else:
print ("failed %s:%s:%s" % (args['<group>'], args['<name>'], args["<value>"]))
else:
''
else:
''
elif (args['cmd'] is True):
if (args['--add'] == True):
if (args['<name>'] and args["<values>"] is not None):
config["command"][args['<name>']] = args["<values>"]
print("successed %s:%s" % (args['<name>'], args["<values>"]))
else:
print("failed %s:%s" % (args['<name>'], args["<values>"]))
elif (args['--del'] == True):
if (args["<name>"] is not None):
if (config['command'].__contains__(args['<name>'])):
config["command"].__delitem__(args['<name>'])
print("successed %s" % (args['<name>']))
else:
print("failed %s" % (args['<name>']))
else:
''
elif (args['--mod'] == True):
if (args['<name>'] and args["<values>"] is not None):
config["command"][args['<name>']] = args["<values>"]
print("successed %s:%s" % (args['<name>'], args["<values>"]))
else:
print("failed %s:%s" % (args['<name>'], args["<values>"]))
else:
''
elif (args['path'] is True):
if (args['--add'] == True):
if (args['<name>'] and args["<value>"] is not None):
config['path-assemblage'][args['<name>']] = args["<value>"]
print ("successed %s:%s" % (args['<name>'], args["<value>"]))
else:
print ("failed %s:%s" % (args['<name>'], args["<value>"]))
elif (args['--del'] == True):
if (args["<name>"] is not None):
if (config['path-assemblage'].__contains__(args['<name>'])):
config['path-assemblage'].__delitem__(args['<name>'])
print ("successed %s" % (args['<name>']))
else:
print ("failed %s" % (args['<name>']))
else:
''
elif (args['--mod'] == True):
if (args['<name>'] and args["<value>"] is not None):
if (config['path-assemblage'].__contains__(args['<name>'])):
config['path-assemblage'][args['<name>']] = args["<value>"]
print ("successed %s:%s" % (args['<name>'], args["<value>"]))
else:
print ("failed %s:%s" % (args['<name>'], args["<value>"]))
else:
''
else:
''
else:
''
# print(config)
writeJsonData(file, config)
return
else:
''
break
### 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
#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
#list
while (True):
if (args['list'] == True):
list_config = config
if ( args['--raw'] is True ):
list_config = rawconfig
if( args['path'] == True):
dict0 = copy.deepcopy(list_config['path-assemblage'])
for (k, v) in dict0.items():
print(Fore.BLUE+ "%-24s %s" % (k, v) )
elif( args['env'] == True):
env = os.environ
current_var = list_config['environ']['current']
if(args['<name>'] is not None):
current_var = args['<name>']
dict0 = copy.deepcopy(list_config['environ'][current_var])
print (Fore.CYAN+ "env %s" % current_var)
print(Fore.MAGENTA + "path+:")
for (key) in dict0["path+"]:
print(Fore.BLUE + " %s" % key)
if(args['-a'] or args['--all'] is True):
for path in env["PATH"].split(os.path.pathsep):
print(Fore.BLUE + " %s" % path)
print(Fore.MAGENTA + "variable:")
for (key, value) in dict0.items():
if (key == 'path+'):
continue
print(Fore.GREEN + " %-30s %s" % (key, value))
if (args['-a'] or args['--all'] is True):
for (key, value) in env.items():
if (key == 'PATH'):
continue
print(Fore.GREEN + " %-30s %s" % (key, value))
elif( args['cmd'] == True):
dict0 = copy.deepcopy(list_config['command'])
if (args['<name>'] is not None):
#print(Fore.CYAN + "group: %s" % args['<name>'])
value = dict0[args['<name>']]
step = 1
for cmd in value:
print(Fore.RED + "%-3s %s" % (step, cmd))
step += 1
else:
for (key, value) in dict0.items():
if (args['-a'] is not True and args['--all'] is not True):
print(Fore.CYAN + "%s" % key)
continue
print(Fore.CYAN + "group: %s" % key)
step = 1
for cmd in value:
print(Fore.RED + "%-3s %s" % (step, cmd))
step += 1
else:
current_var = rawconfig['environ']['current']
print(Fore.CYAN + "%s" % current_var)
for key in rawconfig['environ'].keys() :
if(key == 'current'):
continue
if(key == current_var):
continue
print("%s" % key)
return
else:
''
break
# set into env
while(False):
env = os.environ
current_var = rawconfig['environ']['current']
dict0 = copy.deepcopy(rawconfig['environ'][current_var])
for (key) in dict0["path+"]:
env["PATH"] = key + os.path.pathsep + env["PATH"]
for (key, value) in dict0.items():
if (key == 'path+'):
continue
env[key] = value
break
# export
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_header = "@echo off\n"
env_set = 'set '
else:
cmd_suffix = ".sh"
cmd_header = "#!/usr/bin/env bash\n"
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%' + '\n')
else:
lines += (env_set + 'PATH=' + key + os.path.pathsep + '$PATH' + '\n')
#export var
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += (env_set + key + '=' + value + '\n')
else:
lines += (env_set + key + '=\"' + value + '\"\n')
with open(cmd_effect, 'w') 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 + ';=%' + '\n')
else:
lines += (env_set + 'PATH=$(' + 'echo ${PATH//' + key.replace('/', '\/') + ':/})' + '\n')
#export unset env
for (key, value) in dict0.items():
if (key == 'path+'):
continue
if (plat == "Windows"):
lines += ('set ' + key + '=' + '\n')
else:
lines += ('unset ' + key + '\n')
with open(cmd_unset, 'w') as f:
f.write(cmd_header)
f.write(lines)
#return file name
return current_var, cmd_effect, cmd_unset
while (True):
if (args['export'] == True):
current_var, cmd_effect, cmd_unset = env_export(args['<env-name>'], args['<file-name>'])
print("successed: export %s to %s %s" % (current_var, cmd_effect, cmd_unset))
return
else:""
break
while (True):
if (args['type'] == True):
if (args['<cmd-name>'] is None):
for (key, value) in rawconfig['command'].items():
print(Fore.CYAN + "%s" % key)
return
if (rawconfig['command'].__contains__(args['<cmd-name>']) is False):
print ("please check your command name")
return
list0 = copy.deepcopy(rawconfig['command'][args['<cmd-name>']])
for cmd in list0:
print(Fore.RED + "%s" % (cmd))
if (args['<file-name>'] is None):
return
temp_file_name = args['<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') as f:
f.write(cmd_header+'\n')
for cmd in list0:
f.write(cmd + '\n')
if (plat == "Windows"):
""
else:
os.system("chmod +x " + cmd_exec)
print("success type %s to %s" % (args['<cmd-name>'], cmd_exec))
return
else:""
break
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_return = "\r\n"
cmd_exit = 'exit /b 0'
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 0'
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:
if (plat == "Windows"):
"" # cmd = cmd.replace('/', '\\')
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") as f:
for line in cmd_list:
f.write(line + "\n")
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)
# print (cmd_list)
return cmd_list, name
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 0'
# 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 0'
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
while ( True ):
if (args['here'] is True):
os.chdir(initpath)
if (args['clean'] == True):
plat = getplatform()
if (plat == "Windows"):
os.system("@del /s /q *_effect.bat *_unset.bat *_exec.bat")
else:
os.system("rm -f *_effect.sh *_unset.sh *_exec.sh")
return
current_env = ""
if (args['use'] is True):
if (args['<env-name>'] is None):
print("please appoint a environ")
return
if (rawconfig['environ'].__contains__(args['<env-name>']) is False
or args['<env-name>'] == "current"):
print("please ensure the environ is right")
return
current_env = args['<env-name>']
if (args['<command-names>'] is None):
print("please appoint your commands")
return
#print ("group %s" % current_vars)
dict0 = copy.deepcopy(rawconfig['command'])
list0 = []
for current_var in args['<command-names>']:
if (current_var in dict0):
list0.extend(dict0[current_var])
else:
list0.append(current_var)
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 = createCmdList0(list0)
current_var = rawconfig['environ']['current']
if(current_env is not ""):
current_var = current_env
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
else:""
break
# clean
while (True):
if (args['clean'] == True):
if (args['here'] is True):
os.chdir(initpath)
plat = getplatform()
if(plat == "Windows"):
os.system("@del /s /q *_effect.bat *_unset.bat *_exec.bat")
else:
os.system("rm -f *_effect.sh *_unset.sh *_exec.sh")
return
else:
""
break
def exec_command(env_name, cmd_list0):
if (args['<env-name>'] is None):
print("please appoint a environ")
return
if (rawconfig['environ'].__contains__(args['<env-name>']) is False
or args['<env-name>'] == "current"):
print("please ensure the environ is right")
return
if (args['<command-names>'] is None):
print("please appoint your commands")
return
if (args['here'] is True):
os.chdir(initpath)
# create cmd_list
dict0 = copy.deepcopy(rawconfig['command'])
list0 = []
for current_var in args['<command-names>']:
if (current_var in dict0):
list0.extend(dict0[current_var])
else:
list0.append(current_var)
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 = createCmdList0(list0)
# export env
current_var = args['<env-name>']
# 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
#use env exec command
while(True):
if (args['use'] is True):
if(args['<env-name>'] is None):
print("please appoint a environ")
return
if(rawconfig['environ'].__contains__(args['<env-name>']) is False
or args['<env-name>'] == "current"):
print("please ensure the environ is right")
return
if(args['<command-names>'] is None):
print("please appoint your commands")
return
if (args['here'] is True):
os.chdir(initpath)
#create cmd_list
dict0 = copy.deepcopy(rawconfig['command'])
list0 = []
for current_var in args['<command-names>']:
if (current_var in dict0):
list0.extend(dict0[current_var])
else:
list0.append(current_var)
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 = createCmdList0(list0)
#export env
current_var = args['<env-name>']
#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
else :""
break
while ( True ):
if (args['exec'] is True):
if (args['<command-names>'] is None):
print("please appoint your commands")
return
if (args['here'] is True):
os.chdir(initpath)
#print ("group %s" % current_vars)
dict0 = copy.deepcopy(rawconfig['command'])
list0 = []
for current_var in args['<command-names>']:
if (current_var in dict0):
list0.extend(dict0[current_var])
else:
list0.append(current_var)
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 = createCmdList0(list0)
current_var = rawconfig['environ']['current']
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
else:""
break
return
if __name__ == '__main__':
main_function()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zijunma/PyMake.git
git@gitee.com:zijunma/PyMake.git
zijunma
PyMake
Multi-environ Manager
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385