Exemple #1
0
 def setvar(self, name, value):
     if name == 'timezone':
         tz = dateutil.tz.gettz(value)
         if tz != None:
             self.tz = tz
             self.redraw()
             logger.debug("set %s = %s" % (name, value))
         else:
             console.error("Unknown timezone '%s'" % value)
     if name == 'scrollback':
         try:
             self._results.resize(int(value))
             self.redraw()
             logger.debug("set %s = %s" % (name, value))
         except:
             console.error("Invalid scrollback value '%s'" % value)
Exemple #2
0
 def setvar(self, name, value):
     if name == 'timezone':
         tz = dateutil.tz.gettz(value)
         if tz != None:
             self.tz = tz
             self.redraw()
             logger.debug("set %s = %s" % (name, value))
         else:
             console.error("Unknown timezone '%s'" % value)
     if name == 'scrollback':
         try:
             self._results.resize(int(value))
             self.redraw()
             logger.debug("set %s = %s" % (name, value))
         except:
             console.error("Invalid scrollback value '%s'" % value)
Exemple #3
0
 def startService(self):
     logger.debug("startService")
     try:
         # load data from path
         with file(self._path, 'r') as f:
             logger.debug("opened outfile %s" % self._path)
             reader = DictReader(f)
             for row in reader:
                 self._results.append(row)
             console.redraw()
     except BaseException, e:
         # close the search window
         console.switcher.closeWindow(console.switcher.findWindow(self))
         # display the error on screen
         errtext = "Load failed: %s" % str(e)
         console.error(errtext)
         logger.debug(errtext)
Exemple #4
0
 def command(self, cmd, args):
     from terane.commands.console.console import console
     # window management commands
     if cmd == 'windows':
         return self.showWindowlist()
     if cmd == 'prev':
         return self.prevWindow()
     if cmd == 'next':
         return self.nextWindow()
     if cmd == 'jump':
         try:
             return self.jumpToWindow(self.findWindow(int(args)))
         except IndexError:
             console.error(Exception("No such window '%s'" % args))
         except BaseException, e:
             console.error(e)
         return None
Exemple #5
0
 def command(self, cmd, args):
     from terane.commands.console.console import console
     # window management commands
     if cmd == 'windows':
         return self.showWindowlist()
     if cmd == 'prev':
         return self.prevWindow()
     if cmd == 'next':
         return self.nextWindow()
     if cmd == 'jump':
         try:
             return self.jumpToWindow(self.findWindow(int(args)))
         except IndexError:
             console.error(Exception("No such window '%s'" % args))
         except BaseException, e:
             console.error(e)
         return None
Exemple #6
0
        Display the error popup.
        """
        try:
            self._delayed = None
            # close the window
            console.switcher.closeWindow(console.switcher.findWindow(self))
            # display the error on screen
            raise failure.value
        except Fault, e:
            errtext = "Tail failed: %s (code %i)" % (e.faultString,
                                                     e.faultCode)
        except ValueError, e:
            errtext = "Tail failed: remote server returned HTTP status %s: %s" % e.args
        except BaseException, e:
            errtext = "Tail failed: %s" % str(e)
        console.error(errtext)
        logger.debug(errtext)

    def pause(self):
        if self._delayed == None and self._deferred == None:
            return
        if self._delayed != None:
            self._delayed.cancel()
        self._delayed = None
        if self._deferred != None:
            self._deferred.cancel()
        self._deferred = None
        logger.debug("paused tail")

    def resume(self):
        if self._delayed != None or self._deferred != None:
Exemple #7
0
    def _getError(self, failure):
        """
        Display the error popup.
        """
        try:
            # close the search window
            console.switcher.closeWindow(console.switcher.findWindow(self))
            # display the error on screen
            raise failure.value
        except Fault, e:
            errtext = "Search failed: %s (code %i)" % (e.faultString,e.faultCode)
        except ValueError, e:
            errtext = "Search failed: remote server returned HTTP status %s: %s" % e.args
        except BaseException, e:
            errtext = "Search failed: %s" % str(e)
        console.error(errtext)
        logger.debug(errtext)

    def reload(self):
        if self._deferred != None:
            self._deferred.cancel()
        self._results.clear()
        proxy = Proxy(self._url, user=self._user, password=self._pass, allowNone=True)
        self._deferred = proxy.callRemote('iter', self._query)
        self._deferred.addCallback(self._getResult)
        self._deferred.addErrback(self._getError)
        logger.debug("searching with query '%s'" % self._query)

    def command(self, cmd, args):
        if cmd == 'reload':
            return self.reload()
Exemple #8
0
class WindowSwitcher(MultiService, urwid.WidgetWrap, urwid.ListWalker):
    def __init__(self, frame):
        MultiService.__init__(self)
        self._frame = frame
        self._blank = urwid.SolidFill()
        self._windows = None
        self._nwindows = 0
        self._curr = None
        self._nextwid = 1
        self._focus = None
        self._windowlist = urwid.ListBox(self)
        urwid.WidgetWrap.__init__(self, self._windowlist)

    def startService(self):
        MultiService.startService(self)
        logger.debug("started window management service")

    def stopService(self):
        MultiService.stopService(self)
        logger.debug("stopped window management service")

    def keypress(self, size, key):
        if self._frame.get_body() == self and len(self) > 0:
            if key == 'up' or key == 'k':
                self._windowlist.keypress(size, 'up')
                self._windowlist.set_focus(self._focus - 1, 'below')
            if key == 'down' or key == 'j':
                self._windowlist.keypress(size, 'down')
                self._windowlist.set_focus(self._focus + 1, 'above')
            if key == 'enter':
                self.jumpToWindow(self[self._focus])
            return None
        if self._curr != None:
            return self._curr.keypress(size, key)
        return key

    def command(self, cmd, args):
        from terane.commands.console.console import console
        # window management commands
        if cmd == 'windows':
            return self.showWindowlist()
        if cmd == 'prev':
            return self.prevWindow()
        if cmd == 'next':
            return self.nextWindow()
        if cmd == 'jump':
            try:
                return self.jumpToWindow(self.findWindow(int(args)))
            except IndexError:
                console.error(Exception("No such window '%s'" % args))
            except BaseException, e:
                console.error(e)
            return None
        if cmd == 'close':
            if args == '':
                window = self._frame.get_body()
                if window == self:
                    return self._hideWindowList()
                if self._curr != None:
                    return self.closeWindow(self._curr)
            else:
                try:
                    return self.closeWindow(self.findWindow(int(args)))
                except IndexError:
                    console.error(Exception("No such window '%s'" % args))
                except BaseException, e:
                    console.error(e)
            return None