commit 5da109287e7f4f46fd9c5a3fd6d92ab3f2ce419f Author: Damian Johnson atagar@torproject.org Date: Fri Oct 18 11:19:44 2013 -0700
Merging start_arm() into starter module
Now that we've shortened start_arm() to just the curses.wrapper() call and exception handling we can move this into the starter module. --- arm/controller.py | 27 +-------------------------- arm/starter.py | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/arm/controller.py b/arm/controller.py index 247f6a5..0b6b383 100644 --- a/arm/controller.py +++ b/arm/controller.py @@ -546,32 +546,7 @@ def connResetListener(controller, eventType, _): except ValueError: pass
-def start_arm(): - """ - Initializes the interface and starts the main draw loop. - """ - - try: - curses.wrapper(drawTorMonitor) - except UnboundLocalError as exc: - if os.environ['TERM'] != 'xterm': - shutdownDaemons() - print 'Unknown $TERM: (%s)' % os.environ['TERM'] - print 'Either update your terminfo database or run arm using "TERM=xterm arm".' - print - else: - raise exc - except KeyboardInterrupt: - # Skip printing stack trace in case of keyboard interrupt. The - # HALT_ACTIVITY attempts to prevent daemons from triggering a curses redraw - # (which would leave the user's terminal in a screwed up state). There is - # still a tiny timing issue here (after the exception but before the flag - # is set) but I've never seen it happen in practice. - - panel.HALT_ACTIVITY = True - shutdownDaemons() - -def drawTorMonitor(stdscr): +def start_arm(stdscr): """ Main draw loop context.
diff --git a/arm/starter.py b/arm/starter.py index 435ae95..d53f611 100644 --- a/arm/starter.py +++ b/arm/starter.py @@ -5,6 +5,7 @@ arguments. """
import collections +import curses import getopt import getpass import locale @@ -17,6 +18,7 @@ import time import arm import arm.controller import arm.logPanel +import arm.util.panel import arm.util.torConfig import arm.util.torTools import arm.util.uiTools @@ -396,7 +398,25 @@ def main(): plural_label = "s" if len(missing_event_types) > 1 else "" stem.util.log.info("arm doesn't recognize the following event type%s: %s (log 'UNKNOWN' events to see them)" % (plural_label, ", ".join(missing_event_types)))
- arm.controller.start_arm() + try: + curses.wrapper(arm.controller.start_arm) + except UnboundLocalError as exc: + if os.environ['TERM'] != 'xterm': + shutdownDaemons() + print 'Unknown $TERM: (%s)' % os.environ['TERM'] + print 'Either update your terminfo database or run arm using "TERM=xterm arm".' + print + else: + raise exc + except KeyboardInterrupt: + # Skip printing stack trace in case of keyboard interrupt. The + # HALT_ACTIVITY attempts to prevent daemons from triggering a curses redraw + # (which would leave the user's terminal in a screwed up state). There is + # still a tiny timing issue here (after the exception but before the flag + # is set) but I've never seen it happen in practice. + + arm.util.panel.HALT_ACTIVITY = True + arm.controller.shutdownDaemons()
if __name__ == '__main__': main()
tor-commits@lists.torproject.org