Пример #1
0
    def execute(self, command):

        self.update()
    
        # Execute the command
        if use_highlight:
            self.message('<p><nobr>%s %s</nobr></p>' % (self.session.prompt, highlight(command)))
        else:
            self.message(tags.p(tags.nobr(self.session.prompt, command)))

        exception = None
        result = None
        try:

            # Capture stdout so we can exec print commands
            redirector = StdoutRedirector()
            try:
            
                try:
                    result = eval(command, self.globals, self.locals)
                except SyntaxError:
                    exec command in self.locals

            finally:

                # release stdout
                redirector.close()

                # print the standard output
                self.message(html_repr(redirector.get()).xml)

        except Exception, exception:
            pass
Пример #2
0
    def command(self, command):

        # todo: integrate swil parsing matter

        # a command parsing stand in, for now
        # TODO replace this parser with something worthy
        pos = command.find(" ")
        if pos != -1:
            args = command[pos+1:].split(" ")
            command = command[:pos]
        else:
            args = []

        # command dispatch
        if command in self.commands:
            function = self.commands[command]
            try:
                function(self, *args)
            except TypeError, exception:
                self.message(
                    """
                        <p>That is not the <b>proper usage</b>
                        for the <tt>%s</tt> command.</p>
                    """ % inoculate(repr(command))
                )
                print_exc()
            except Exception, exception:
                if hasattr(self, 'message'):
                    self.message(tags.hr().xml)
                    self.message(html_repr(exception))
                    self.message(tags.hr().xml)
Пример #3
0
 def update(self):
     self.depth = None
     if self.globals.has_key('DEPTH'):
         self.depth = int(self.globals['DEPTH'])
     prompt = '>>> '
     if self.globals.has_key('PROMPT'):
         prompt = self.globals['PROMPT']
     if isinstance(prompt, FunctionType):
         prompt = prompt()
     self.session.prompt = html_repr(prompt, host = self.host, depth = self.depth).xml
Пример #4
0
        try:

            if result is not None:
                # print the value of the expression
                self.message(html_repr(result, host = self.host, depth = self.depth).xml)
                self.globals['_'] = result
                self.globals['__'].append(result)

        except Exception, exception:
            pass

        if exception is not None:
            # print the exception
            self.message(tags.hr().xml)
            self.message(html_repr(exception).xml)
            self.message(tags.hr().xml)

        self.update()

Init.commands.load(
    module_path(__file__, 'commands.py'),
    module_path(__file__, '..', 'sh', 'general_commands.py'),
)

class StdoutRedirector(object):
    """
    Captures stdout from instantiation until close() is called.
    This is not really thread safe! It should be fine as long as
    we stay single threadded.
    """