예제 #1
0
    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')
예제 #2
0
    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
예제 #3
0
파일: interp.py 프로젝트: 117111302/poky
    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