def _subprocPYC(strCmd, cmpfile, dotExt='.dll'): clr = None # keep out global clr try: import clr sys.path.append(oprel(compiler.pycpath)) import pyc except Exception as exi: pass args = None if clr: args = strCmd[2:] try: pyc.Main(args) except Exception as ex: if ex: print('type', type(ex)) try: print(ex) print(ex.message) except Exception: pass log.warn('pyc.Main err:\n' + ex.ToString()) else: log.warn('pyc.Main err:\n') return False else: po = subprocess.Popen(strCmd, stdout=PIPE, stderr=PIPE) stdout, stderr = po.communicate() po.wait() if stderr: log.warn('ERR\n {}:\n\t compiling with {}'.format(stderr, cmpfile)) po.kill() return False else: if gsBuild.Verbose or not gsBuild.INFO: log.info('\n - STDOUT - \n{}'.format(stdout)) po.kill() if dotExt and opex( opj(opd(compiler.mainoutdir), opb(cmpfile).replace('.py', dotExt))): log.FILE('Build Created: {}'.format(cmpfile.replace('.py', dotExt))) elif opex(cmpfile): log.FILE('Build Created: {}'.format(cmpfile)) else: return False return True
def uniqueZips(zips, zipsExisting): zipex = list(zipsExisting) zips = list(set(zips)) #unique addZips = list(zips) for zfile in zips: for zex in zipex: if zex: zf = oprel(zfile).replace('\\', '/').replace('../', '') zx = zex if zf == zx: try: addZips.remove(zfile) except ValueError as ex: log.warn('\nUnable to trim duplicate zip additions' + \ '\nzip: {}\narchive {}'.format(zf, zx)) msg = '\nUnable to trim duplicate zip additions' + \ '\nzip: {}\narchive {}'.format(zf, zx) partialError(ex, msg) continue continue # if addZips and gsBuild.Verbose or not gsBuild.INFO: # log.info(('\n addZips:\n' + '{}\n'*len(addZips)).format(*addZips)) return addZips
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 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 _subprocPYC(strCmd, cmpfile, dotExt='.dll'): clr = None # keep out global clr try: import clr except Exception as ex: pass if clr: try: sys.path.append(oprel(compiler.pycpath)) import pyc except Exception as ex: pass try: clr.AddReference("StdLib") except System.IO.IOException as ex: print('StdLib.dll reference error:\n\t' + \ 'check file | filepath') try: clr.AddReference("IronPython") except System.IO.IOException as ex: print('IronPython reference error:\n\t' + \ 'check file | filepath') f_ipy = False try: import ipyver rs = ipyver.ReferenceStatus() f_ipy = rs.RefStatusIPMS()['ipy']['isLocal'] except System.IO.IOException as ex: pass try: clr.AddReference("ipybuild") except System.IO.IOException as ex: try: clr.AddReference("ipybuilder") except System.IO.IOException as ex: if f_ipy: print('IF .exe: ipybuild(er) reference error:\n\t' + \ 'check file | filepath') args = None rslt = None args = strCmd[2:] try: rslt = pyc.Main(args) except Exception as ex: errtyp = '' gsBuild.OK = False try: errtyp = ex.GetType().ToString() except Exception as exf: pass if ex: log.warn('pyc.Main err:\n' + ex.ToString()) log.warn('type {} or System Type {}'.format(type(ex), errtyp)) log.warn('Error: {}'.format(ex)) print 'ex-err' return False if rslt: return True else: po = subprocess.Popen(strCmd, stdout=PIPE, stderr=PIPE) stdout, stderr = po.communicate() po.wait() if stderr: log.warn('ERR\n {}:\n\t compiling with {}'.format(stderr, cmpfile)) po.kill() gsBuild.OK=False return False else: if gsBuild.Verbose or not gsBuild.INFO: log.info('\n - STDOUT - \n{}'.format(stdout)) po.kill() if dotExt and opex(opj(opd(compiler.mainoutdir), opb(cmpfile).replace('.py', dotExt))): log.FILE('Build Created: {}'.format(cmpfile.replace('.py', dotExt))) return True elif opex(cmpfile): log.FILE('Build Created: {}'.format(cmpfile)) return True else: gsBuild.OK = False return False