commit 14ddf7331ad0bf5b7c766090b869055448accaba Author: Sambuddha Basu sambuddhabasu1@gmail.com Date: Sun Jun 5 20:35:47 2016 -0700
Updated --log commandline argument and startup.events --- nyx/arguments.py | 26 ++++++++++++++++++++++++-- nyx/panel/log.py | 4 ++-- test/arguments.py | 8 ++++---- 3 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/nyx/arguments.py b/nyx/arguments.py index ad8ea4a..6627eb1 100644 --- a/nyx/arguments.py +++ b/nyx/arguments.py @@ -24,7 +24,7 @@ DEFAULT_ARGS = { 'user_provided_socket': False, 'config': os.path.join(DATA_DIR, 'nyxrc'), 'debug_path': None, - 'logged_events': 'N3', + 'logged_events': 'NOTICE,NYX_NOTICE', 'print_version': False, 'print_help': False, } @@ -135,7 +135,7 @@ def parse(argv): args['debug_path'] = os.path.expanduser(arg) elif opt in ('-l', '--log'): try: - expand_events(arg) + validate_events(arg) except ValueError as exc: raise ValueError(msg('usage.unrecognized_log_flags', flags = exc))
@@ -183,6 +183,28 @@ def get_version(): )
+def validate_events(events): + """ + Check whether the events are any one of Tor runlevels, Nyx runlevels or + Tor events. + """ + + valid_events = set(TOR_EVENT_TYPES.values() + nyx.log.NYX_RUNLEVELS) + accepted_events, invalid_events = set(), set() + + events = events.split(',') + for event in events: + if event in valid_events: + accepted_events.update([event]) + else: + invalid_events.update([event]) + + if invalid_events: + raise ValueError(','.join(invalid_events)) + else: + return accepted_events + + def expand_events(flags): """ Expands event abbreviations to their full names. Beside mappings provided in diff --git a/nyx/panel/log.py b/nyx/panel/log.py index d7b4ede..9c2eb68 100644 --- a/nyx/panel/log.py +++ b/nyx/panel/log.py @@ -39,7 +39,7 @@ CONFIG = conf.config_dict('nyx', { 'features.log.prepopulate': True, 'features.log.prepopulateReadLimit': 5000, 'features.log.regex': [], - 'startup.events': 'N3', + 'startup.events': 'NOTICE,NYX_NOTICE', }, conf_handler)
UPDATE_RATE = 0.3 @@ -68,7 +68,7 @@ class LogPanel(nyx.panel.DaemonPanel): def __init__(self): nyx.panel.DaemonPanel.__init__(self, 'log', UPDATE_RATE)
- logged_events = nyx.arguments.expand_events(CONFIG['startup.events']) + logged_events = nyx.arguments.validate_events(CONFIG['startup.events']) self._event_log = nyx.log.LogGroup(CONFIG['cache.log_panel.size'], group_by_day = True) self._event_log_paused = None self._event_types = nyx.log.listen_for_events(self._register_tor_event, logged_events) diff --git a/test/arguments.py b/test/arguments.py index 76c6d38..a0f678e 100644 --- a/test/arguments.py +++ b/test/arguments.py @@ -28,8 +28,8 @@ class TestArgumentParsing(unittest.TestCase): args = parse(['--debug', '/tmp/dump']) self.assertEqual('/tmp/dump', args.debug_path)
- args = parse(['--log', 'D1']) - self.assertEqual('D1', args.logged_events) + args = parse(['--log', 'DEBUG,NYX_DEBUG']) + self.assertEqual('DEBUG,NYX_DEBUG', args.logged_events)
args = parse(['--version']) self.assertEqual(True, args.print_version) @@ -41,8 +41,8 @@ class TestArgumentParsing(unittest.TestCase): args = parse(['-i', '1643']) self.assertEqual(1643, args.control_port)
- args = parse(['-l', 'we', '-c', '/tmp/cfg']) - self.assertEqual('we', args.logged_events) + args = parse(['-l', 'WARN,ERR', '-c', '/tmp/cfg']) + self.assertEqual('WARN,ERR', args.logged_events) self.assertEqual('/tmp/cfg', args.config)
def test_that_we_reject_unrecognized_arguments(self):
tor-commits@lists.torproject.org