def getTrueFilePath(fnpath): ''' Find absolute file path if exists. :param: fnpath [str] - file path to check. :return: absolute path to existing file [str]. :raise: [IOError] if can't find or read. ''' fpath = fnpath.strip() resolvedPath = None assert isinstance(fpath, (str, unicode)), \ 'Error type not str: send str file path' if os.getcwd() not in fpath: fpath = opab(fpath) dfn = opb(opn(fpath)) dfdir = opd(opn(opab(fpath))) dfpath = None dirfs = os.listdir(opd(opn(opab(fpath)))) dfpath = opn(op.join(dfdir, dfn)) if dfn in dirfs and op.isfile(dfpath): # log.warn('\n dfpath {}'.format(dfpath)) resolvedPath = dfpath return resolvedPath elif _validateFileIsPath(dfpath): # log.warn('\n signle filepath return {}'.format(dfpath)) return dfpath raise IOError('file | filepath not resolved: {}'.format(fpath))
def setMain(configPath, mainName, jsonarg, argc, argm, argj): ''' path json with assembly >> main >> if config None reset mainName path to outDir if no arg "outDir" ''' basem = None basec = None basej = None mainp = None jsonp = None configp = None if argc: configp, basec, typc, isFilec, isdefaultc = argc if argm: mainp, basem, typm, isFilem, isdefaultm = argm # json with assembly >> main >> if config None if isdefaultm: name = 'No mainName' if mainName: name = mainName raise IOError('file | filepath not resolved:\n\t' + \ 'Python type "main" .py file: {}'.format(name)) if basem and '.' in basem and '.py' in basem: mainp = opn(opj(mainp, basem)) elif basem and '.' in basem and basec: mainp = opn(opj(mainp, ('.').join(basec.split('.')[:-1])) \ .replace('_config', '') + '.py') elif basem and basem != op.basename(os.getcwd()): mainp = opn(opj(mainp, basem) + '.py') elif jsonarg: jsonp, basej, typj, isFilej, isdefaultj = argj mainp = opn(opj(jsonp, ('.').join(basej \ .split('.')[:-1])) + '.py') elif configPath: configp, basec, typc, isFilec, isdefaultc = argc if basec and '.' in basec: basec = ('.').join(basec \ .split('.')[:-1]) \ .replace('_config', '') + '.py' elif basec and basec != op.basename(os.getcwd()): mainp = opn(opj(configp, basec.replace('_config', '')) + '.py') if mainp: return mainp raise IOError('file | filepath not resolved:' + '\n\t - No main python.py file')
def checkRequiredIP(): if gsBuild.IPATH: return gsBuild.HAVELIB gsBuild.HAVELIBDLL ironPythonPath = FindIronPython() if opex(ironPythonPath): gsBuild.IPATH = ironPythonPath userReqBaseLst = os.listdir(ironPythonPath) userReqLst = [ opn(opj(ironPythonPath, urf)) for urf in os.listdir(ironPythonPath) ] if opex(opj(ironPythonPath, 'Lib')): log.FILE('Exists: {}'.format(opj(ironPythonPath, 'Lib'))) gsBuild.HAVELIB = True # TODO check for downloaded StdLib if op.isfile(opn(opj(ironPythonPath, 'StdLib.dll'))): gsBuild.HAVELIBDLL = True if not all(rf in userReqBaseLst for rf in DefaultReqList): try: raise NotImplementedError except NotImplementedError as ex: msg = 'Failed to find all required IronPython Distribution files' partialError(ex, msg) log.FILE('\n Exists required path {}'.format( opj(os.getcwd(), gsBuild.requiredPath))) WD = os.getcwd() if 'Tests' in WD: WD = opd(WD) with open(opj(os.getcwd(), gsBuild.requiredPath), 'w') as tw: for f in userReqLst: relp = opn(op.relpath(f)) # skip dirs if op.isfile(relp): tw.write(opn(os.path.relpath(f)) + '\n') log.FILE('Exists {}'.format(gsBuild.requiredPath)) return
def FindIronPython(): ''' Walk directories to find IronPython Install :return: IronPython install path [str] - or - if not main sets gsBuild.IPATH :raise: NotImplementedError ''' SEARCHUSER = opn(os.path.expanduser('~')) SEARCHCWD = opd(os.getcwd()) if 'Tests' in os.getcwd(): SEARCHCWD = opd(SEARCHCWD) SEARCHMODSRC = opn(opd(opd(os.__file__))) SEARCHROOT = os.path.splitdrive(SEARCHCWD)[0] searchList = [SEARCHCWD, SEARCHUSER, SEARCHMODSRC, SEARCHROOT] for direct in searchList: for root, dirs, files in os.walk(direct, topdown=False): for name in files: if gsBuild.IRONPYTHON in name: with open( opn(opab(opj(os.getcwd(), 'defaults\\ipath.txt'))), 'w') as tw: tw.write(opd(opn(opj(root, name)))) return opd(opn(opj(root, name))) if __name__ == '__main__': raise NotImplementedError('Failed to Find/*Access' + \ ' loadable IronPython Distribution') log.warn(('\nFailed to find loadable IronPython Distribution:\n Used "{}"' + \ ' name to search for directory.\n\n' + ' Searched ordered from base:\n {}\n {}\n {}\n {}\n') \ .format(gsBuild.IRONPYTHON, *searchList)) log.info('\nCheck Access and/or install IronPython to loadable path.') raise FatalError('NotImplementedError', 'Failed to Find/*Access' + \ ' loadable IronPython Distribution')
def setMkdir(argc, argm, argj): if argm: mkdirp = argm[0] elif argj: mkdirp = argj[0] elif argc: mkdirp = argc[0] else: mkdirp = opn(opj(os.getcwd(), 'UserDefaulted')) return mkdirp
def registerStatic(_file_, staticDir='static'): """ Add a directory of static files to the web server. In __init__.py: registerStatic(__file__) registerStatic(__file__, 'static') """ path = opn(opj(opd(_file_), staticDir)) staticPaths.append(path) print "static:", path
def registerTemplates(_file_, templateDir='templates'): """ Add a template directory to the template search path. In __init__.py: registerTemplates(__file__) registerTemplates(__file__, 'templates') """ path = opn(opj(opd(_file_), templateDir)) templatePaths.append(path) print "templates:", path
def _createStdLib(): if gsBuild.Verbose or not gsBuild.INFO: log.info('\nNew StdLib compile: {}'.format(compiler.stdlibsource)) gb0 = glob.glob(opn(opj(compiler.libpath, '*.py'))) gb1 = glob.glob(opn(opj(compiler.libpath, '\*.py'))) gb2 = glob.glob(opn(opj(compiler.libpath, '*\*.py'))) gb3 = glob.glob(opn(opj(compiler.libpath, '*\*\*.py'))) gb = list(gb0 + gb1 + gb2 + gb3) gb.append("/out:" + compiler.stdlibsource.replace('.dll', '')) gb.append("/target:dll") ipystr = [compiler.ipath + '/ipy'] + [compiler.pycpath] + gb if _subprocPYC(ipystr, opabs(compiler.stdlibsource), dotExt=None): if op.isfile(opabs(compiler.stdlibsource)): log.FILE('Build Created: {}' \ .format(opabs(compiler.stdlibsource))) compiler.isStdLib = op.isfile(opabs(compiler.stdlibsource))
def relative(request, path="", hash="", **kwargs): """url helper, curry with the request to something like request.relative: given example.com/1/2 as the current URL: request.relative('../foo') example.com/1/foo request.relative('bar', foo=123) example.com/1/2/bar?foo=123 request.relative('bar', hash='b', foo=123) example.com/1/2/bar?foo=123#b """ path = opn(opj(request.path, path)).replace("\\", "/") path = quote_path(path) # percent escape, handle unicode. if kwargs: path = "%s?%s" % (path, url_encode(kwargs)) if hash: path = "%s#%s" % (path, quote(hash)) return path
def relative(request, path="", hash="", **kwargs): """url helper, curry with the request to something like request.relative: given example.com/1/2 as the current URL: request.relative('../foo') example.com/1/foo request.relative('bar', foo=123) example.com/1/2/bar?foo=123 request.relative('bar', hash='b', foo=123) example.com/1/2/bar?foo=123#b """ path = opn(opj(request.path, path)).replace("\\","/") path = quote_path(path) # percent escape, handle unicode. if kwargs: path = "%s?%s" % (path, url_encode(kwargs)) if hash: path = "%s#%s" % (path, quote(hash)) return path
def _getRelativeZipName(zips, zfile): roots = dict(zipDirGCA(zips)) zfiledrv = os.path.splitdrive(zfile)[0] RelDirsFilePath = None reldir = roots[zfiledrv]['GCA'] reldir = roots[zfiledrv]['GCA'] if roots[zfiledrv]['baseroot']: RelDirsFilePath = oprel(zfile, reldir) else: RelDirsFilePath = opn(opj(reldir, opb(zfile))) if RelDirsFilePath: return RelDirsFilePath return
def setConfig(configPath, mainName, jsonarg, argc, argm, argj): ''' Path json with assembly >> main >> if config None ''' basem = None basec = None basej = None mainp = None jsonp = None configp = None if argc: configp, basec, typc, isFilec, isdefaultc = argc if basec and '.' in basec and '.config' in basec: configp = opn(opj(configp, basec)) elif basec and '.' in basec: if isdefaultc: configp = opn(opj(configp, ('.').join(basec.split('.')[:-1])) + \ 'default_config.config') else: configp = opn(opj(configp, ('.').join(basec.split('.')[:-1])) + \ '_config.config') elif basec and basec != op.basename(os.getcwd()): configp = opn(opj(configp, basec) + 'default_config.config') elif jsonarg: argj = BasePathDir(jsonarg) jsonp, basej, typj, isFilej, isdefaultj = argj configp = opn(opj(jsonp, ('.').join(basej \ .split('.')[:-1])) + '_config.config') elif mainName: mainp, basem, typm, isFilem, isdefaultm = argm if basem and '.' in basem: basem = ('.').join(basem.split('.')[:-1]) + '_config.config' elif basem and basem != op.basename(os.getcwd()): configp = opn(opj(mainp, basem) + '_config.config') else: configp = opn(mainp + 'default_config.config') if not configp: configp = opj(os.getcwd(), 'UserDefaulted', 'default_config.config') return configp
def checkRequired(path): ''' Read file list of required files and check they if exist or partial error. :param: - path [str] - of file to read list - tag= [opt][str] - writelog tag for filtering :return: list of files **not** found - should be empty [list] :raise: partialError - sink errors for stdout in PartialErrors [list] ''' tag = 'Exists' reqpath = getTrueFilePath(path) amsg = 'need {} file'.format(reqpath) assert os.path.isfile(reqpath), amsg with open(reqpath, 'r') as txtr: reqfiles = txtr.readlines() log.FILE('{} {}'.format(tag, path)) reqfs = list(reqfiles) if gsBuild.Verbose: log.info('\ngsBuild.IPATH:\n {}'.format(gsBuild.IPATH)) if gsBuild.IPATH != 'clr': for f in reqfiles: if gsBuild.IPATH and gsBuild.IPATH not in f: fr = opn(opj(gsBuild.IPATH, opb(f))) else: fr = f try: fp = getTrueFilePath(fr.strip()) log.FILE('{} {}'.format(tag, fp)) reqfs.remove(f) except IOError as ex: log.debug('raise partial') partialError(ex, ex.message) continue return reqfs elif gsBuild.IPATH == 'clr': return []
def _fmt_str(strfile): ''' Clean a str like path and return or Error ''' csep = ',' assert len(csep) == 1, 'bad format in csep' sfile = opn(strfile) if ',' in strfile: sfile = strfile.replace(',', '') if '\\n' in strfile: sfile = strfile.replace('\\n', '') sfile = sfile.lstrip() #invalid list file assume source file if not _validateFileIsPath(sfile.strip()): sys.stdout.flush() raise IOError('file | filepath {} '.format(sfile)) return sfile.strip()
def makeBuild(config): ''' Compile the exe or dll files based on: - user args - user assembly flags (f_embed, f_libembed, f_standalone) ''' gsBuild.OK = True _setCompilerClass(config) if gsBuild.Verbose: log.info('\n compiler {}'.format(json.dumps(compiler, default=lambda x: x.__dict__, indent=4))) _fetchLib() if compiler.f_parerr: return False gbm = [] dllNames = [] if compiler.lstdll: dllNames = list(createUserLibs(config)) # std stub useless unless just an exe way to run a few single python modules if compiler.ext.replace('.', '') == 'exe': gbm = gbm + _setupBaseExe(config, dllNames) if gsBuild.Verbose: gbm = gbm + ['-v'] # pass verbose to pyc ipystr = [compiler.ipath + '/ipy '] + [compiler.pycpath] + gbm _subprocPYC(ipystr, compiler.mainfile, dotExt='.exe') # ADD, SO DELETED if compiler.f_embed or compiler.f_standalone: dllNames.append(compiler.mainoutdir + '.dll') # THIS IS OK if os.path.isfile(compiler.mainoutdir + '.IPDLL'): # log.error('\n trying to remove {}'.format(compiler.mainoutdir + '.IPDLL')) try: os.remove(compiler.mainoutdir + '.IPDLL') except (IOError, Exception) as ex: log.error('\n Failed to del/remove:\n {}'.format(compiler.mainoutdir + '.IPDLL')) if ex == IOError: print(ex)#pass elif ex == System.IO.IOException: print(ex)#pass elif ex == WindowsError: print 'Type Err: {}'.format(type(ex)) print(ex)#pass else: print 'Type Err: {}'.format(type(ex)) print(ex) #raise ex #TODO checkjust use compiler.f_libembed if (compiler.f_embed or compiler.f_standalone) and compiler.f_libembed: if os.path.isfile(opd(compiler.mainoutdir) + 'StdLib.dll'): try: os.remove(opd(compiler.mainoutdir) + 'StdLib.dll') except IOError as ex: pass if gsBuild.Verbose or not gsBuild.INFO: pycInfo() #pyc does not send .exe to mainoutdir if 'dll' not in compiler.ext: movestr = ['cmd', '/C', 'move', compiler.pycdir, opn(opd(compiler.mainoutdir) + '\\')] _subprocMove(movestr, compiler.pycdir, compiler.mainoutdir, compiler.ext) if compiler.f_embed or compiler.f_standalone: notDelDll = [] for dll in dllNames: if os.path.isfile(dll) and dll.find('.dll') != -1 and \ dll.find('IronPython') == -1: #some ver deleted probably not needed # log.error('\n trying to remove {}'.format(dll)) try: os.remove(dll) # log.error('\n successfully removed {}'.format(dll)) except (IOError, Exception) as ex: if ex == IOError: print(ex)#pass elif ex == System.IO.IOException: print(ex)#pass elif ex == WindowsError: print 'Type Err: {}'.format(type(ex)) print(ex)#pass else: print 'Type Err: {}'.format(type(ex)) print(ex) #raise ex notDelDll.append(dll) if notDelDll: gsBuild.DELDLLS = notDelDll elif compiler.ext.replace('.', '') == 'dll': gbm = [] gbm = gbm + _setupBaseDll(config, dllNames) if gsBuild.Verbose: gbm = gbm + ['-v'] # pass verbose to pyc ipystr = [compiler.ipath + '/ipy '] + [compiler.pycpath] + gbm _subprocPYC(ipystr, compiler.mainfile)
from os.path import basename as opb from os.path import exists as opex from os.path import isdir as opisd import re from copy import deepcopy from collections import OrderedDict import json import unittest from regt import SlashContrl from buildlogs import dynfile from globalstate import gsBuild log = dynfile(__name__) log.debug('\n---------------- ' + str(__name__) + \ ' loaded --------------') if not opex(opn(opab(opj(os.getcwd(), 'defaults\\')))): print('no exist {}'.format(opn(opab(opj(os.getcwd(), 'defaults\\'))))) #opn is key to run in clr? defaultcfg = opn(opj(os.getcwd(), 'defaults\\default_config.config')) defaultjson = opn(opj(os.getcwd(), 'defaults\\default_assembly.json')) if 'Tests' in os.getcwd(): defaultjson = opj(opd(os.getcwd()), 'defaults\\default_assembly.json') defaultcfg = opj(opd(os.getcwd()), 'defaults\\default_config.config') defaultconfig = { 'MAKEEXE': False, 'MAKEDIR': None, 'OUTDIR': None, 'MAINFILE': None,
def AssignMakeZip(uconfig, args): config = ndcDict(uconfig) outzipPath = None cfz = config['ZIPPATH'] if args['listzip']: zfiles = [] # missing zipfiles in listzip.txt or input zips = loadRes(getTrueFilePath(args['listzip'])) uzips = None # unique zips nuzips = [] #full path uniques # zip exists with cur name if have zipped before isautozip = False try: import zlib mode = zipfile.ZIP_DEFLATED except ImportError: mode = zipfile.ZIP_STORED config['LISTFILES']['zip'] = [] if isinstance(zips, list): config['LISTFILES']['zip'].extend(zips) else: config['LISTFILES']['zip'].append(zips) # set outzip path manf = 'default.zip' if config['MAINFILE']: manf = ('.').join(opb(config['MAINFILE']).split('.')[:-1]) + '.zip' outzipPath = opj(config['OUTDIR'], manf) # stop trying to overwrite same file # current zip path cfzp = None if cfz: try: cfzp = getTrueFilePath(cfz) if opex(cfzp): isautozip = True except IOError: pass # auto zip path elif outzipPath: try: cfzp = getTrueFilePath(outzipPath) if opex(cfzp): isautozip = True except IOError: pass # update zip path config['ZIPPATH'] = cfzp cfz = cfzp # -- zipping --- # uzips if isautozip: infoExistZip(cfz, outzipPath) log.FILE('Confirmed: {}'.format(cfzp)) zipsRelative = [] for zipname in zips: relname = None relname = _getRelativeZipName(zips, zipname) if relname: zipsRelative.append(relname) else: zipsRelative.append(zipname) with zipfile.ZipFile(cfzp, 'a', mode) as ziprd: uzips = list(uniqueZips(zipsRelative, list(ziprd.namelist()))) #getting back full path from relative for zfile in uzips: if 'from' in zfile: drv = zfile[5] zfile = opn(zfile.replace('from_' + drv, drv + ':')) else: cwdlst = os.getcwd().split(os.sep) cnt = 0 while cwdlst[-1] and not opex( opab(opj((os.sep).join(cwdlst), zfile))): cnt += 1 if cnt > 25: break cwdlst.pop() zfile = opab(opj((os.sep).join(cwdlst), zfile)) nuzips.append(zfile) if not os.path.isfile(zfile): log.error("can't find {}".format(zfile)) zfiles.append(zfile) continue arcname = _getRelativeZipName(nuzips, zfile) if not arcname: log.error("can't find arcname using {}".format( oprel(zfile))) zfiles.append(zfile) continue ziprd.write(zfile, arcname) ziprd.close() # changed if uzips if nuzips: if gsBuild.Verbose or not gsBuild.INFO: log.info(('\nSome Files already zipped in:\n{}\n\t' + \ '- delete to replace existing' + \ '\nadding zip files to existing archive:\n' + \ '{}\n'*len(nuzips)) \ .format(cfz, *nuzips)) # Need new zip with ZIPPATH/outzipPath as name elif not isautozip: warnZip(outzipPath) if isinstance(zips, list): with zipfile.ZipFile(cfz, 'a', mode) as zipr: for zfile in list(set(zips)): if not os.path.isfile(zfile): zfiles.append(zfile) continue arcname = _getRelativeZipName(zips, zfile) if not arcname: arcname = oprel(zfile) zipr.write(zfile, arcname) log.FILE('{}'.format(config['ZIPPATH'])) zipr.close() if isinstance(zips, (str, unicode)): with zipfile.ZipFile(cfz, 'w', mode) as zipr: arcname = oprel(zips) zipr.write(zips, arcname) zipr.close() log.FILE('{}'.format(cfz)) if zfiles: if gsBuild.Verbose or not gsBuild.INFO: log.warn(('\nFile | path does not exist - ' +\ 'skipped adding zip files:\n\t' + \ '{} \n\t'*len(zfiles)).format(*zfiles)) log.FILE(('*Missing zip: {}\n' * len(zfiles)).format(*zfiles)) partialError('ValueError', ('*Missing zip: {}\n' * len(zfiles)).format(*zfiles)) return ndcDict(config)
def _setCompilerClass(rconfig): config = ndcDict(rconfig) f_standalone = None f_embed = None f_libembed = None f_parerr = None # f_parerr - Stop build on partialError that is Fatal to Compile # Let makeBuild finish so that user can fix partialErrs with open(config['CONFIGPATH'], 'r') as jbcr: config = ndcDict(json.load(jbcr)) if gsBuild.Verbose or not gsBuild.INFO: log.info('\n Building from CONFIG:\n {}\n'.format( json.dumps(config, indent=4))) if not opex(config['MAINFILE']): try: raise IOError except IOError as ex: msg = 'File Filepath does Not exist:\n "{}"' \ .format(config['MAINFILE']) partialError(ex, msg) f_parerr = True if not f_parerr: log.FILE('Build Loaded: {}'.format(config['MAINFILE'])) assemInfo = config['ASSEMBLY'] if isinstance(assemInfo['standalone'], bool) or \ str(assemInfo['standalone']).upper() in ['TRUE', 'FALSE']: f_standalone = True if str(assemInfo['standalone']).upper() == \ 'TRUE' else False if isinstance(assemInfo['embed'], bool) or \ str(assemInfo['embed']).upper() in ['TRUE', 'FALSE']: f_embed = True if str(assemInfo['embed']).upper() == 'TRUE' else False if isinstance(assemInfo['libembed'], bool) or \ str(assemInfo['libembed']).upper() in ['TRUE', 'FALSE']: f_libembed = True if str(assemInfo['libembed']).upper() \ == 'TRUE' else False ext = '.dll' if config['MAKEEXE'] == True or \ str(config['MAKEEXE']).upper() == 'TRUE': ext = '.exe' if f_standalone and not config['MAKEEXE']: log.warn('\n** Switching to exe /stanalone == true in Assembly:' + \ '\n {}\n Overrides default or makeEXE input arg == False' \ .format(config['JSONPATH'])) MAINOUT = opn(opj(config['OUTDIR'], ('.').join(opb(config['MAINFILE']) \ .split('.')[:-1])) + ext) IPATH = gsBuild.IPATH STDLIBSOURCE = opabs(opj(IPATH, 'StdLib.dll')) LIBPATH = opabs(opj(IPATH, 'Lib')) compiler.pycpath = (opn(opd(opabs(gsBuild.IPYBLDPATH)))) + '\pyc.py' compiler.stdlibsource = STDLIBSOURCE compiler.ipath = IPATH compiler.libpath = LIBPATH if not op.isfile(STDLIBSOURCE): _createStdLib() MAINOUTDIR = ('.').join(MAINOUT.split('.')[:-1]) PYCDIR = opn(opj(os.getcwd(), opb(MAINOUTDIR)) + ext) STDLIBRELEASE = opj(opd(MAINOUTDIR), 'StdLib.dll') MAINFILE = config['MAINFILE'] isLib = opex(LIBPATH) isStdLib = op.isfile(STDLIBSOURCE) haveStdLib = op.isfile(opj(os.getcwd(), 'StdLib.dll')) isReleasedStdLib = op.isfile(STDLIBRELEASE) lstdll = [] if config['LISTFILES']['dll']: if isinstance(config['LISTFILES']['dll'], list): for lfile in config['LISTFILES']['dll']: if lfile and '__init__' not in lfile: lstdll.append(lfile) else: lstdll.append(config['LISTFILES']['dll']) lstexe = [] if config['LISTFILES']['exe']: if isinstance(config['LISTFILES']['exe'], list): for xfile in config['LISTFILES']['exe']: if xfile and '__init__' not in xfile: lstexe.append(xfile) else: lstexe.append(config['LISTFILES']['exe']) lstexe = nullList(lstexe) compiler.f_standalone = f_standalone compiler.f_embed = f_embed compiler.f_libembed = f_libembed compiler.f_parerr = f_parerr compiler.mainout = MAINOUT compiler.ipath = IPATH compiler.mainoutdir = MAINOUTDIR compiler.pycdir = PYCDIR compiler.stdlibrelease = STDLIBRELEASE compiler.stdlibsource = STDLIBSOURCE compiler.libpath = LIBPATH compiler.mainfile = MAINFILE compiler.isLib = isLib compiler.isStdLib = isStdLib compiler.haveStdLib = haveStdLib compiler.isReleasedStdLib = isReleasedStdLib compiler.lstdll = lstdll compiler.lstexe = lstexe compiler.ext = ext compiler.lstexedlls = None if not opex(opd(compiler.pycdir)): raise IOError('FilePath {}:\t Use absolute or relative to:\n\t {}' \ .format(opd(compiler.pycdir), os.getcwd())) if compiler.f_standalone: if gsBuild.Verbose or not gsBuild.INFO: log.info('\nNew {} compile standalone from:\n {}' \ .format(ext.upper().replace('.', ''), config['MAINFILE'])) else: mfn = 'application/lib' if config['MAINFILE']: mfn = opb(config['MAINFILE']) if gsBuild.Verbose or not gsBuild.INFO: log.info(("\nNew {} compile from: \n {}" + \ "\n\tAs Required: add your {}, project, and ironpython"+ \ "\n\tdll(s) to path:\n\t{}\n\n") .format(ext.upper().replace('.', ''), config['MAINFILE'], mfn, config['OUTDIR'])) if gsBuild.Verbose or not gsBuild.INFO: log.info('\n Lib source path {}'.format(LIBPATH)) log.info('\n "IF" set "True", f_libembed adds ~23mb to file:' + \ 'now set as {}'.format(compiler.f_libembed)) if compiler.f_libembed and compiler.isStdLib: if gsBuild.Verbose or not gsBuild.INFO: if compiler.isReleasedStdLib: log.info('\nOK - "StdLib.dll" exists delete'+ \ ' or move to update:\n{}'.format(STDLIBRELEASE)) else: log.info('\nOK - "StdLib.dll" exists delete'+ \ ' or move to update:\n{}'.format(STDLIBSOURCE)) elif not compiler.isStdLib and compiler.f_libembed and \ not compiler.isReleasedStdLib and compiler.isLib: _createStdLib() if not compiler.isStdLib: raise NotImplementedError('StdLib: Need ironpython2.7 distribution' + \ ' in something like ../ironpython path')
def makeBuild(config): ''' Compile the exe or dll files based on: - user args - user assembly flags (f_embed, f_libembed, f_standalone) ''' _setCompilerClass(config) if gsBuild.Verbose: log.info('\n compiler {}'.format( json.dumps(compiler, default=lambda x: x.__dict__, indent=4))) _fetchLib() if compiler.f_parerr: return False gbm = [] dllNames = list(createUserLibs(config)) exedllName = opn( opj(compiler.mainoutdir, compiler.mainout).replace('.exe', '.dll')) # if dllNames: # log.error(('\n dllNames:\n ' + '{}\n'*len(dllNames)).format(*dllNames)) # log.error('\n exedllName:{}'.format(exedllName)) # std stub useless unless just an exe way to run a few single python modules if compiler.ext.replace('.', '') == 'exe': gbm = gbm + _setupBaseExe(config, dllNames) if gsBuild.Verbose: gbm = gbm + ['-v'] # pass verbose to pyc ipystr = [compiler.ipath + '/ipy '] + [compiler.pycpath] + gbm _subprocPYC(ipystr, compiler.mainfile, dotExt='.exe') # ADD, SO DELETED if compiler.f_embed or compiler.f_standalone: dllNames.append(compiler.mainoutdir + '.dll') if os.path.isfile(compiler.mainoutdir + '.IPDLL'): try: os.remove(compiler.mainoutdir + '.IPDLL') except (IOError, Exception) as ex: if ex == IOError: pass elif ex == System.IO.IOException: pass else: raise ex if (compiler.f_embed or compiler.f_standalone) and compiler.f_libembed: if os.path.isfile(opd(compiler.mainoutdir) + 'StdLib.dll'): try: os.remove(opd(compiler.mainoutdir) + 'StdLib.dll') except IOError as ex: pass if gsBuild.Verbose or not gsBuild.INFO: pycInfo() #pyc does not send .exe to mainoutdir if 'dll' not in compiler.ext: movestr = [ 'cmd', '/C', 'move', compiler.pycdir, opn(opd(compiler.mainoutdir) + '\\') ] _subprocMove(movestr, compiler.pycdir, compiler.mainoutdir, compiler.ext) if compiler.f_embed or compiler.f_standalone: for dll in dllNames: if os.path.isfile(dll) and '.dll' in dll and\ 'IronPython' not in dll: #some ver deleted probably not needed try: os.remove(dll) except (IOError, Exception) as ex: if ex == IOError: pass elif ex == System.IO.IOException: pass else: raise ex #TODO debug simple dll compile elif compiler.ext.replace('.', '') == 'dll': _setupBaseDll(config, dllNames, exedllName)
def setPath(configPath, mainName, jsonarg, argout, f_type='json'): ''' Well this doesn't end - way too complex ''' #TODO auto-fix file re-naming on err fix basem = None basec = None basej = None mainp = None jsonp = None configp = None odir = None argc, argm, argj, argo = SlashArgs(configPath, mainName, jsonarg, argout) if f_type == 'mkdir': return setMkdir(argc, argm, argj) odir = opn(opj(argo[0], argo[1])) if f_type == 'odir': return odir if argc: configp, basec, typc, isFilec, isdefaultc = argc if configPath and f_type == 'config': return setConfig(configPath, mainName, jsonarg, argc, argm, argj) if argm: mainp, basem, typm, isFilem, isdefaultm = argm if mainName and f_type == 'name': return setMain(configPath, mainName, jsonarg, argc, argm, argj) if argj: jsonp, basej, typj, isFilej, isdefaultj = argj if mainName and f_type == 'json': if basec and '.' in basec: basec = ('.').join(basec.split('.')[:-1]).replace('_config', '') if basem and '.' in basem: basem = ('.').join(basem.split('.')[:-1]) mainName = opn(opj(mainp, basem)) if configp and not op.exists(mainp): mainName = opn(opj(configp.replace('_config', ''), basem)) if jsonarg and f_type == 'json' and \ op.basename(jsonarg) != 'default_assembly.json': if typj != 'json' and '.' in basej: basej = ('.').join(basej.split('.')[:-1]) #+ '_assembly.json' elif typj != 'json': basej = basej + '_assembly.json' if isFilej: jsonp = opn(opj(jsonp, basej)) elif basej and not isdefaultj: jsonp = opn(opj(jsonp, basej)) elif basej and mainp and not isdefaultm: jsonp = opn(opj(mainp, basej)) elif basej and configp and not isdefaultc: jsonp = opn(opj(configp, basej)) elif basej and mainp: jsonp = opn(opj(mainp, basej)) elif basej and jsonp: jsonp = opn(opj(jsonp, basej)) elif basej and configp: jsonp = opn(opj(mainp, basej)) if jsonp: return jsonp else: jsonp = None if f_type == 'json': #falling backwards fallp = None if basem: basem = basem + '_assembly.json' defbase = 'default_assembly.json' if basem and mainp and op.exists(mainp) and not isdefaultm: fallp = opn(opj(mainp, basem)) elif basem and configp and op.exists(configp): fallp = opn(opab(opj(configp.replace('_config', ''), basem))) elif basem and not configp and mainp: fallp = opn(opj(mainp, basem)) elif configp and op.exists(configp): fallp = opn(opj(configp.replace('_config', ''), defbase)) else: fallp = opn(opab(opj('./UserDefaulted', defbase))) return fallp
from os.path import exists as opex from os.path import isdir as opisd from ipyrequirements import REQUIREMENTS as ipyreq import re from copy import deepcopy from collections import OrderedDict import json import unittest from regt import SlashContrl from buildlogs import dynfile from globalstate import gsBuild log = dynfile(__name__) log.debug('\n---------------- ' + str(__name__) + \ ' loaded --------------') if not opex(opn(opab(opj(os.getcwd(), 'defaults')))): print('no exist {}'.format(opn(opab(opj(os.getcwd(), 'defaults\\'))))) try: os.mkdir(opn(opab(opj(os.getcwd(), 'defaults')))) except Exception as ex: print(ex) #opn is key to run in clr? defaultcfg = opn(opj(os.getcwd(), 'defaults\\default_config.config')) defaultjson = opn(opj(os.getcwd(), 'defaults\\default_assembly.json')) if 'Tests' in os.getcwd(): defaultjson = opj(opd(os.getcwd()), 'defaults\\default_assembly.json') defaultcfg = opj(opd(os.getcwd()), 'defaults\\default_config.config') defaultconfig = {
def BasePathDir(dp): ''' Parse a file path and return dict of info about path :param: dp [str] - user arg path :return: - (main, base, basetype, isFile, isdefault) [tuple] - main [str] - fullpath parent - base [str] - base of path dir or file path - basetype [basetype [python, json, config, None]] - isFile [bool] - isdefault [ bool] - True if output is going to UserDefaulted/ ''' dp = dp.strip() base = None main = None dpex = op.exists(opab(dp)) main = opd(dp) mainex = op.exists(main) base = opb(dp) hasdot = '.' in base basetype = None isFile = False isdefault = False if dpex: isFile = op.isfile(opab(dp)) if hasdot: if '.py' in base: basetype = 'python' elif '.json' in base: basetype = 'json' elif '.config' in base: basetype = 'config' if (opb(main)) == 'builder': main = opn(opj(main, 'UserDefaulted')) isdefault = True if not hasdot and base == opd(main): return (main, None, None, isFile, isdefault) elif not hasdot and base in os.getcwd(): if base == 'builder': base = opn(opj(base, 'UserDefaulted')) isdefault = True return (opn(opj(opab(main), base)), None, None, isFile, isdefault) elif not mainex: if op.exists(opn(opab(opd(main)))): isdefault = True return (opn(opj(opab(opd(main)), 'UserDefaulted')), base, basetype, isFile, isdefault) isdefault = True return (opn(opab(opj(opd(main), 'UserDefaulted'))), base, basetype, isFile, isdefault) return (main.strip(), base.strip(), basetype, isFile, isdefault)