def PrependPath(curpath, path): if not curpath: curpath = [] elif atmake.IsString(curpath): curpath = curpath.split(os.pathsep) elif atmake.IsList(curpath): pass else: atmake.Error('Invalid current PATH type !') if not path: path = [] elif atmake.IsString(path): path = path.split(os.pathsep) elif atmake.IsList(path): pass else: atmake.Error('Invalid PATH type !') for p in path: if p and not p in curpath: curpath.insert(0, str(p)) return string.join(curpath, os.pathsep)
def ToListPath(path, sep=None): """ ['A','B','C','D'] -> ['A','B','C','D'] 'A/B/C/D' -> ['A','B','C','D'] 'A B C D' -> ['A','B','C','D'] """ if sep is None: sep = os.sep if atmake.IsList(path): return path if not atmake.IsString(path): atmake.Error("Invalid path : %s !" % str(path)) if path.find(os.sep) >= 0: # 'A/B/C/D' -> ['A','B','C','D'] drive, path = os.path.splitdrive(path) p = [] while len(path): path, base = os.path.split(path) if len(base): p = [base] + p # prevent os.path.split('\\\') looping if len(path) and path[-1] == sep: break if len(drive): p = [drive] + p return p # 'A B C D' return path.split()
def Spawn ( cmdline, cwd=None, env=None, showcl=None ) : """ returns : ( exec_success, exit_code, stdout lines, stderr lines ) """ def __readlines( ilines ) : olines = [] ol = '' for il in ilines : if il==ord('\r') : continue if il==ord('\n') : olines.append( ol+'\r\n' ) ol = '' else : ol += chr(il) return olines if atmake.IsString(cmdline) : cmdlist = cmdline_to_list( cmdline ) elif atmake.IsList(cmdline) : cmdlist = cmdline else : atmake.Error( "Command-line must be a string or a list of strings !" ) if showcl : print(cmdlist) # disable cl.exe direct redirection to visual IDE output window ! if env and 'VS_UNICODE_OUTPUT' in env : env['VS_UNICODE_OUTPUT'] = '' oo = ee = '' try : p = subprocess.Popen( cmdlist, stdout = subprocess.PIPE, stderr = subprocess.PIPE, cwd = cwd, env = env) oo, ee = p.communicate() oo = __readlines( oo ) ee = __readlines( ee ) retcode = p.returncode return ( True, retcode, oo, ee ) except OSError as e : print(oo) print(ee) return ( False, 0, None, None )
def ToStringPath(path, sep=None): """ 'A/B/C/D' -> 'A/B/C/D' 'A B C D' -> 'A/B/C/D' ['A','B','C','D'] -> 'A/B/C/D' """ if sep is None: sep = os.sep if atmake.IsString(path): if path.find(sep) >= 0: return path path = str(path).split() if not atmake.IsList(path) or len(path) == 0: atmake.Error("Invalid path : %s !" % str(path)) j = '' for p in path: if len(str(p)): j += sep + str(p) return j[1:]
def _get(sym, arg=None): # get variable try: s = env[sym] except KeyError: if warn: SIDL_Error("Undefined symbol <%s> !" % sym, loc, donotexit=True) return '' # get result if atmake.IsCallable(s): r = s(env=env, loc=loc, arg=arg) else: r = s # check result if r is None: return '' elif atmake.IsCallable(r): return r elif atmake.IsList(r): return string.join(r, ';') else: return str(r)