def execute_script(self, script=None, ast=None, sourced=False, scriptpath=None): """If script is not None, parse the input. Otherwise takes the supplied AST. Then execute the AST. Return the script exit status. """ try: if scriptpath is not None: self._env['0'] = os.path.abspath(scriptpath) if script is not None: debug_parsing = ('debug-parsing' in self._debugflags) cmds, script = pyshyacc.parse(script, True, debug_parsing) if 'debug-tree' in self._debugflags: pyshyacc.print_commands(cmds, self._logfile) self._logfile.flush() else: cmds, script = ast, '' status = 0 for cmd in cmds: try: status = self.execute(cmd) except ExitSignal, e: if sourced: raise status = int(e.args[0]) return status except ShellError: self._env['?'] = 1 raise if 'debug-utility' in self._debugflags or 'debug-cmd' in self._debugflags: self.log('returncode ' + str(status)+ '\n')
def execute_script(self, script=None, ast=None, sourced=False, scriptpath=None): """If script is not None, parse the input. Otherwise takes the supplied AST. Then execute the AST. Return the script exit status. """ try: if scriptpath is not None: self._env['0'] = os.path.abspath(scriptpath) if script is not None: debug_parsing = ('debug-parsing' in self._debugflags) cmds, script = pyshyacc.parse(script, True, debug_parsing) if 'debug-tree' in self._debugflags: pyshyacc.print_commands(cmds, self._logfile) self._logfile.flush() else: cmds, script = ast, '' status = 0 for cmd in cmds: try: status = self.execute(cmd) except ExitSignal as e: if sourced: raise status = int(e.args[0]) return status except ShellError: self._env['?'] = 1 raise if 'debug-utility' in self._debugflags or 'debug-cmd' in self._debugflags: self.log('returncode ' + str(status) + '\n') return status except CommandNotFound as e: print >> self._redirs.stderr, str(e) self._redirs.stderr.flush() # Command not found by non-interactive shell # return 127 raise except RedirectionError as e: # TODO: should be handled depending on the utility status print >> self._redirs.stderr, str(e) self._redirs.stderr.flush() # Command not found by non-interactive shell # return 127 raise
def execute_script(self, script=None, ast=None, sourced=False, scriptpath=None): """If script is not None, parse the input. Otherwise takes the supplied AST. Then execute the AST. Return the script exit status. """ try: if scriptpath is not None: self._env['0'] = os.path.abspath(scriptpath) if script is not None: debug_parsing = ('debug-parsing' in self._debugflags) cmds, script = pyshyacc.parse(script, True, debug_parsing) if 'debug-tree' in self._debugflags: pyshyacc.print_commands(cmds, self._logfile) self._logfile.flush() else: cmds, script = ast, '' status = 0 for cmd in cmds: try: status = self.execute(cmd) except ExitSignal as e: if sourced: raise status = int(e.args[0]) return status except ShellError: self._env['?'] = 1 raise if 'debug-utility' in self._debugflags or 'debug-cmd' in self._debugflags: self.log('returncode ' + str(status)+ '\n') return status except CommandNotFound as e: print >>self._redirs.stderr, str(e) self._redirs.stderr.flush() # Command not found by non-interactive shell # return 127 raise except RedirectionError as e: # TODO: should be handled depending on the utility status print >>self._redirs.stderr, str(e) self._redirs.stderr.flush() # Command not found by non-interactive shell # return 127 raise