[tor-commits] [arm/master] Moving missing_event_types() to the arguments module

atagar at torproject.org atagar at torproject.org
Sat Dec 28 19:36:28 UTC 2013


commit 4e30b8ceece30343a13f61790eb8758b7987a0b1
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Dec 28 11:34:05 2013 -0800

    Moving missing_event_types() to the arguments module
    
    Moving a revised version of the logPanel's getMissingEventTypes() function to
    the argument. This compliments expand_events() and finally allows us to axe the
    logPanel import from the starter (which has irked me for a while). Still need
    to add tests, though.
---
 arm/arguments.py |   21 ++++++++++++++++++++-
 arm/logPanel.py  |   17 +----------------
 arm/starter.py   |    3 +--
 3 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/arm/arguments.py b/arm/arguments.py
index 95069e1..6ce102e 100644
--- a/arm/arguments.py
+++ b/arm/arguments.py
@@ -10,7 +10,7 @@ import arm
 
 import stem.connection
 
-from arm.util import msg
+from arm.util import tor_controller, msg
 
 DEFAULT_ARGS = {
   'control_address': '127.0.0.1',
@@ -206,3 +206,22 @@ def expand_events(flags):
     raise ValueError(''.join(set(invalid_flags)))
   else:
     return expanded_events
+
+
+def missing_event_types():
+  """
+  Provides the event types the current tor connection supports but arm
+  doesn't. This provides an empty list if no event types are missing or the
+  GETINFO query fails.
+
+  :returns: **list** of missing event types
+  """
+
+  response = tor_controller().get_info('events/names', None)
+
+  if response is None:
+    return []  # GETINFO query failed
+
+  tor_event_types = response.split(' ')
+  recognized_types = TOR_EVENT_TYPES.values()
+  return filter(lambda x: x not in recognized_types, tor_event_types)
diff --git a/arm/logPanel.py b/arm/logPanel.py
index cdb2081..16c1464 100644
--- a/arm/logPanel.py
+++ b/arm/logPanel.py
@@ -90,21 +90,6 @@ def daysSince(timestamp=None):
   if timestamp == None: timestamp = time.time()
   return int((timestamp - TIMEZONE_OFFSET) / 86400)
 
-def getMissingEventTypes():
-  """
-  Provides the event types the current tor connection supports but arm
-  doesn't. This provides an empty list if no event types are missing, and None
-  if the GETINFO query fails.
-  """
-
-  torEventTypes = torTools.getConn().getInfo("events/names", None)
-
-  if torEventTypes:
-    torEventTypes = torEventTypes.split(" ")
-    armEventTypes = arm.arguments.TOR_EVENT_TYPES.values()
-    return [event for event in torEventTypes if not event in armEventTypes]
-  else: return None # GETINFO call failed
-
 def loadLogMessages():
   """
   Fetches a mapping of common log messages to their runlevels from the config.
@@ -1051,7 +1036,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
 
     # adds events unrecognized by arm if we're listening to the 'UNKNOWN' type
     if "UNKNOWN" in events:
-      torEvents.update(set(getMissingEventTypes()))
+      torEvents.update(set(arm.arguments.missing_event_types()))
 
     torConn = torTools.getConn()
     torConn.removeEventListener(self.registerTorEvent)
diff --git a/arm/starter.py b/arm/starter.py
index 021ed68..87db2b4 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -18,7 +18,6 @@ import threading
 import arm
 import arm.arguments
 import arm.controller
-import arm.logPanel
 import arm.util.panel
 import arm.util.torConfig
 import arm.util.tracker
@@ -124,7 +123,7 @@ def main():
 
   # provides a notice about any event types tor supports but arm doesn't
 
-  missing_event_types = arm.logPanel.getMissingEventTypes()
+  missing_event_types = arm.arguments.missing_event_types()
 
   if missing_event_types:
     info('setup.unknown_event_types', event_types = ', '.join(missing_event_types))



More information about the tor-commits mailing list