def wipe(self): for path in self.files: try: sys_path = pathtools.tosys(path) # If exiting early, the file may not have been created yet. if os.path.exists(sys_path): os.remove(sys_path) except OSError as err: Log.Error( "TempFileHandler: Unable to wipe file %s w/ error %s", pathtools.touser(path), err.strerror) self.files = []
def ParseArgs(argv, patternlist, driver_patternlist=DriverArgPatterns, driver_patternlist_not_inherited=DriverArgPatternsNotInherited): """Parse argv using the patterns in patternlist Also apply the built-in DriverArgPatterns unless instructed otherwise. This function must be called by all (real) drivers. """ if driver_patternlist: driver_args, argv = ParseArgsBase(argv, driver_patternlist) # TODO(robertm): think about a less obscure mechanism to # replace the inherited args feature assert not env.get('INHERITED_DRIVER_ARGS') env.append('INHERITED_DRIVER_ARGS', *driver_args) _, argv = ParseArgsBase(argv, driver_patternlist_not_inherited) _, unmatched = ParseArgsBase(argv, patternlist) if unmatched: for u in unmatched: Log.Error('Unrecognized argument: ' + u) Log.Fatal('unknown arguments')
def ParseError(s, leftpos, rightpos, msg): Log.Error("Parse Error: %s", msg) Log.Error(' ' + s) Log.Error(' ' + (' ' * leftpos) + ('^' * (rightpos - leftpos + 1))) DriverExit(1)
p = subprocess.Popen(actual_args, stdin=redirect_stdin, stdout=redirect_stdout, stderr=redirect_stderr) result_stdout, result_stderr = p.communicate(input=stdin_contents) except Exception, e: msg = '%s\nCommand was: %s' % (str(e), StringifyCommand(args, stdin_contents)) print msg DriverExit(1) Log.Info('Return Code: ' + str(p.returncode)) if errexit and p.returncode != 0: if redirect_stdout == subprocess.PIPE: Log.Error('--------------stdout: begin') Log.Error(result_stdout) Log.Error('--------------stdout: end') if redirect_stderr == subprocess.PIPE: Log.Error('--------------stderr: begin') Log.Error(result_stderr) Log.Error('--------------stderr: end') DriverExit(p.returncode) return p.returncode, result_stdout, result_stderr def IsWindowsPython(): return 'windows' in platform.system().lower()