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

asdlei / Multi-environ Technology
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pymake2.py 20.66 KB
一键复制 编辑 原始数据 按行查看 历史
tianduanrui 提交于 2017-09-24 17:49 . pymake3.py add more $\{\} parser
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
"""PyMake 2.0.
Usage:
pymake2.py source [ --add | --del | --switch ] [ <config-file-name> ]
pymake2.py source --mod <config-file-name> <new-config-file-name>
pymake2.py source [ --show | --restore ]
pymake2.py list [ --vars | --pathes | --commands | --task ]
pymake2.py set ( env-var | env-path | cmd ) ( --add | --del | --mod ) <name> [ <value> ]
pymake2.py stream (--add | --del | --mod ) <name> [ <values> ... ]
pymake2.py exec <stream-names> ...
pymake2.py (-h | --help)
pymake2.py --version
Command:
source switch to another source file
set env-path config work directory
set env-var
set exec-dir config execute directory
list list configed values
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
--vars
--pathes
--commands
--task list info params
--show display haved task config files
--restore reset to pymake.json task config file
"""
# -*- coding: utf-8 -*-
import os
import re
import sys
import pwd
import shutil
import time
import json
import locale
import codecs
import threading
import subprocess
import collections
from pycore.pycore import *
from pycore.docopt import docopt
def main_function():
d = {
"add-path-to-env": {
"cmake-bin-path": "/Users/abel/Develop/b0-toolskits/compliers/CMake.app/Contents/bin",
"macosx-sdk-xcode": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks",
"make-and-toolchain-path": "/usr/bin",
"qt5.9-clang64": "/Users/abel/Develop/b0-toolskits/Libraries/QtLibraries/5.9.1/clang_64/bin"
},
"env-variables": {
"PYCMD_MYNAME": "T.D.R"
},
"store-named-command": {
"mk-buildpath": "mkdir -p /Users/abel/Develop/c0-buildstation/mac-qqt",
"cd-buildpath": "cd /Users/abel/Develop/c0-buildstation/mac-qqt",
"cd-productpath": "cd /Users/abel/Develop/b1-Product/a0-qqtbased/Application",
"gen": "cmake -G\"Unix Makefiles\" -DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}../../b1-Product/a0-qqtbased/Application ../../a0-Developworkspace/a0-qqtpruduct-qqtfoundation/",
"gen-xcode": "cmake -GXCode -DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}../../b1-Product/a0-qqtbased/Application ../../a0-Developworkspace/a0-qqtpruduct-qqtfoundation/",
"install": "make install",
"make": "make -j4",
"msg": "echo 'work completed!'",
"pwd": "pwd",
"rmcache": "rm -f CMakeCache.txt"
},
"execute-stream": {
"buildqqt": [
"mk-buildpath",
"cd-buildpath",
"rmcache",
"gen",
"make",
"install",
"msg"
],
"genqqt": [
"mk-buildpath",
"cd-buildpath",
"gen",
"msg"
],
"packageqqt": [
"cd-productpath",
"pwd"
]
}
}
# python's transfer parameters is a unordered dict,
# these data will be unordered, you should copy them into pymake.json
if (not os.path.exists('pymake.json')):
writeJsonData('pymake.json', d)
"""
[pymake]
config = pymake.json
"""
file = 'pymake.json'
conf = MyConfigParser()
conf.read('pymake.ini')
if(conf.has_section('pymake') ):
if(conf.has_option('pymake', 'config')):
if(conf.get('pymake', 'config')):
file = conf.get('pymake', 'config')
print("use source config: %s" % file)
else:
conf.set('pymake', 'config', 'pymake.json')
conf.write(open('pymake.ini', 'w'))
print('initial pymake.ini')
else:
conf.set('pymake', 'config', 'pymake.json')
conf.write(open('pymake.ini', 'w'))
print('initial pymake.ini')
else:
conf.add_section('pymake')
conf.set('pymake', 'config', 'pymake.json')
conf.write(open('pymake.ini', 'w'))
print ( 'initial pymake.ini')
args = docopt(__doc__, version='pymake2.py v2.0')
#print(args)
exceptFile = ( 'pymake.ini', 'pymake.py', '.gitignore', '.git', 'pycore', 'README.md', '.idea')
while (True):
if(args['source'] is True):
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 not exceptFile.__contains__(args['<config-file-name>']) ):
os.remove(args['<config-file-name>'])
conf.set('pymake', 'config', 'pymake.json')
conf.write(open('pymake.ini', 'w'))
else:
print ( 'You can\'t remove pymake\'s file...')
elif(args['--add'] is True):
if (args['<config-file-name>'] is not None and not exceptFile.__contains__(args['<config-file-name>']) ):
if(file != args['<config-file-name>']):
shutil.copyfile(file, args['<config-file-name>'])
conf.set('pymake', 'config', args['<config-file-name>'])
conf.write(open('pymake.ini', 'w'))
else:
print('You can\'t add same named file...')
else:
print ( 'You can\'t add pymake\'s file...')
elif (args['--mod'] is True):
if ( ( args['<config-file-name>'] and args[
'<new-config-file-name>']) is not None and not \
exceptFile.__contains__(
args['<config-file-name>'])):
os.rename(args['<config-file-name>'],
args['<new-config-file-name>'])
if (file == args['<config-file-name>']):
conf.set('pymake', 'config',
args['<new-config-file-name>'])
conf.write(open('pymake.ini', 'w'))
else:
print ('You can\'t mod pymake\'s file...')
elif(args['--show'] is True):
files = os.listdir(os.getcwd())
for f in files:
if (not exceptFile.__contains__(f)):
print(f)
elif(args['--restore'] is True):
conf.set('pymake', 'config', 'pymake.json')
conf.write(open('pymake.ini', 'w'))
elif (args['--switch'] is True
or ( args['<config-file-name>'] is not None and args[\
'<config-file-name>'] != '' )):
if (args['<config-file-name>'] is not None and not exceptFile.__contains__(args['<config-file-name>']) ):
if (os.path.exists(args['<config-file-name>'])):
conf.set('pymake', 'config', args['<config-file-name>'])
conf.write(open('pymake.ini', 'w'))
print("switch to source config: %s" % args[
'<config-file-name>'])
else:
print("source file %s isn't exists" % args[
'<config-file-name>'])
else:
print('You can\'t switch pymake\'s file...')
else:
print(file)
return
else:
''
break
config = readJsonData(file)
#print(config)
while (True):
if (args['list'] == True):
if( args['--vars'] == True):
dict0 = config['env-variables'].copy()
for (k, v) in dict0.items():
print("%-24s %s" % (k, v) )
elif( args['--pathes'] == True):
dict0 = config['add-path-to-env'].copy()
for (k, v) in dict0.items():
print("%-24s %s" % (k, v) )
elif( args['--commands'] == True):
dict0 = config['store-named-command'].copy()
for (k, v) in dict0.items():
print("%-24s %s" % (k, v) )
elif( args['--task'] == True):
dict0 = config['execute-stream'].copy()
for (k,v) in dict0.items():
print("%-24s %s" % (k,v) )
else:
''
break
while (True):
if (args['set'] == True):
if (args['env-var'] is True):
if (args['--add'] == True):
if (args['<name>'] and args["<value>"] is not None):
config["env-variables"][args['<name>']] = args[
"<value>"]
print ( "successed %s:%s" % (args['<name>'],
args[ "<value>"]))
else:
''
elif (args['--del'] == True):
if (args["<name>"] is not None):
if (config['env-variables'].__contains__(
args['<name>'])):
config["env-variables"].__delitem__(
args['<name>'])
print ("successed %s" % (args['<name>']))
else:
''
else:
''
elif (args['--mod'] == True):
if (args['<name>'] and args["<value>"] is not None):
if (config['env-variables'].__contains__(
args['<name>'])):
config["env-variables"][args['<name>']] = \
args["<value>"]
print ("successed %s:%s" % (args['<name>'],
args["<value>"]))
else:
''
else:
''
else:
''
elif (args['env-path'] is True):
if (args['--add'] == True):
if (args['<name>'] and args["<value>"] is not None):
config["add-path-to-env"][args['<name>']] = args[
"<value>"]
print ( "successed %s:%s" % (args['<name>'],
args[ "<value>"]))
else:
''
elif (args['--del'] == True):
if (args["<name>"] is not None):
if (config['add-path-to-env'].__contains__(
args['<name>'])):
config["add-path-to-env"].__delitem__(
args['<name>'])
print ("successed %s" % (args['<name>']))
else:
''
else:
''
elif (args['--mod'] == True):
if (args['<name>'] and args["<value>"] is not None):
if (config['add-path-to-env'].__contains__(
args['<name>'])):
config["add-path-to-env"][args['<name>']] = \
args["<value>"]
print ("successed %s:%s" % (args['<name>'],
args["<value>"]))
else:
''
else:
''
else:
''
elif (args['cmd'] is True):
if (args['--add'] == True):
if (args['<name>'] and args["<value>"] is not None):
config["store-named-command"][args['<name>']] = args[
"<value>"]
print ( "successed %s:%s" % (args['<name>'],
args[ "<value>"]))
else:
''
elif (args['--del'] == True):
if (args["<name>"] is not None):
if (config['store-named-command'].__contains__(
args['<name>'])):
config["store-named-command"].__delitem__(
args['<name>'])
print ("successed %s" % (args['<name>']))
else:
''
else:
''
elif (args['--mod'] == True):
if (args['<name>'] and args["<value>"] is not None):
if (config['store-named-command'].__contains__(
args['<name>'])):
config["store-named-command"][args['<name>']] = \
args["<value>"]
print ("successed %s:%s" % (args['<name>'],
args["<value>"]))
else:
''
else:
''
else:
''
else:
''
elif (args['stream'] is True):
if (args['--add'] == True):
if (args['<name>'] and args["<values>"] is not None):
config["execute-stream"][args['<name>']] = args[
"<values>"]
print ("successed %s:%s" % (args['<name>'],
args["<values>"]))
else:
''
elif (args['--del'] == True):
if (args["<name>"] is not None):
if (config['execute-stream'].__contains__(
args['<name>'])):
config["execute-stream"].__delitem__(
args['<name>'])
print ("successed %s" % (args['<name>']))
else:
''
else:
''
elif (args['--mod'] == True):
if (args['<name>'] and args["<values>"] is not None):
config["execute-stream"][args['<name>']] = args[
"<values>"]
print ("successed %s:%s" % (args['<name>'],
args["<values>"]))
else:
''
else:
''
else:
''
#print(config)
writeJsonData(file, config)
break
def read_thread_function(p):
''
code = (codecs.lookup(locale.getpreferredencoding()).name)
while(True):
l = p.stdout.readline().rstrip().decode(code)
if (l is None):
#print ('ddd')
break
if(p.poll() is not None):
#print("eee")
break
print (l)
#print (l)
#stdout.flush()
def read_stderr_thread_function(p):
''
code = (codecs.lookup(locale.getpreferredencoding()).name)
while(True):
l = p.stderr.readline().rstrip().decode(code)
if (l is None):
#print ('ddd')
break
if(p.poll() is not None):
#print("eee")
break
print (l)
#print (l)
#stdout.flush()
def write_thread_function(list0):
''
### config -> raw config
rawconfig = config.copy()
#print ( rawconfig )
env = os.environ
for (key, value) in rawconfig["env-variables"].items():
#print (key) #...
startpos = 0
while (True):
#print (startpos)
index = value.find('${', startpos)
if (index == -1):
break
index2 = value.find('}', index)
startpos = index2
key0 = value[index:index2 + 1]
#print ( key0 ) #${...}
key1 = key0.split('{')[1].split('}')[0].strip()
#print ( key1 ) #...
if (env.has_key(key1)):
rawconfig["env-variables"][key] = rawconfig["env-variables"][key].replace(key0, env[key1])
else:
for (key2, value2) in config["env-variables"].items():
if (key2 == key1):
rawconfig["env-variables"][key] = rawconfig["env-variables"][key].replace(key0, rawconfig["env-variables"][key1])
#print ("%s:%s" % (key, rawconfig["env-variables"][key]))
else:
''
for (key, value) in rawconfig["store-named-command"].items():
#print (key) #...
startpos = 0
while (True):
#print (startpos)
index = value.find('${', startpos)
if (index == -1):
break
index2 = value.find('}', index)
startpos = index2
key0 = value[index:index2 + 1]
#print ( key0 ) #${...}
key1 = key0.split('{')[1].split('}')[0].strip()
#print ( key1 ) #...
if (env.has_key(key1)):
rawconfig["store-named-command"][key] = rawconfig["store-named-command"][key].replace(key0, env[key1])
else:
for (key2, value2) in rawconfig["env-variables"].items():
if (key2 == key1):
rawconfig["store-named-command"][key] = rawconfig["store-named-command"][key].replace(key0, rawconfig["env-variables"][key1])
#print ("%s:%s" % (key, rawconfig["store-named-command"][key]))
else:
''
while ( True ):
if( args['exec'] == True):
if(args['<stream-names>'] is not None):
env = os.environ
for (key, value) in rawconfig["env-variables"].items():
env[key] = value
for (key, value) in env.items():
#print ("%-24s %s" % (key, value) )
''
for (name, path) in rawconfig["add-path-to-env"].items():
env["PATH"] = path + os.path.pathsep + env["PATH"]
#print(env["PATH"].replace(os.path.pathsep, '\n'))
list0 = []
for stream in args['<stream-names>']:
if (rawconfig["execute-stream"].__contains__(stream)):
for cmd in rawconfig["execute-stream"][stream]:
if (rawconfig['store-named-command'].__contains__(cmd)):
# print("execute %s %s %s" % (stream, cmd, rawconfig['store-named-command'][cmd]))
list0.append( rawconfig['store-named-command'][cmd] )
else:
print ("can't find command %s" % cmd)
else:
print ("can't find stream %s" % stream)
list0.append("exit 0")
#print (list0)
shell = pwd.getpwuid(os.getuid()).pw_shell
if shell is None: shell = os.environ.get( 'SHELL' )
if shell is None: shell = os.environ.get( 'COMSPEC' )
#print ( 'Running under', shell )
p = subprocess.Popen(shell, shell = True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
read_thread = threading.Thread(target=read_thread_function, args=(p,))
read_thread.start()
read_err_thread = threading.Thread(target=read_stderr_thread_function, args=(p,))
read_err_thread.start()
write_thread = threading.Thread(target=write_thread_function, args=(list0,))
#write_thread.start()
time.sleep(1)
for cmd in list0:
#print ("command:%s" % cmd)
p.stdin.write(cmd + '\n')
p.stdin.flush()
#p.stdin.write("ping 127.0.0.1 -c 2 \n")
#p.stdin.flush()
p.wait()
#read_thread.close()
time.sleep(1)
#return
else:
print ("stream-names is none")
else:
''
break
return
if __name__ == '__main__':
main_function()
Python
1
https://gitee.com/asdlei/PyMake.git
git@gitee.com:asdlei/PyMake.git
asdlei
PyMake
Multi-environ Technology
master

搜索帮助