[tor-commits] [arm/master] Moving our stem.connection.connect() call into init_controller()

atagar at torproject.org atagar at torproject.org
Mon Jun 23 15:00:33 UTC 2014


commit 7539cca058a4b1795ac5a9fc92f192c7fbbd1c29
Author: Damian Johnson <atagar at torproject.org>
Date:   Sat Jun 21 12:38:59 2014 -0700

    Moving our stem.connection.connect() call into init_controller()
    
    Might as well move our connect() call in. They're separate for legacy reasons
    that no longer exist. Also a bit of other minor util cleanup.
---
 arm/starter.py       |    4 +---
 arm/util/__init__.py |   26 ++++++++++++--------------
 run_tests.py         |    3 +--
 3 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/arm/starter.py b/arm/starter.py
index 8d27024..1f6692f 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -22,7 +22,6 @@ import arm.util.tracker
 import arm.util.ui_tools
 
 import stem
-import stem.connection
 import stem.util.conf
 import stem.util.log
 import stem.util.system
@@ -63,7 +62,7 @@ def main():
   control_port = None if args.user_provided_socket else (args.control_address, args.control_port)
   control_socket = None if args.user_provided_port else args.control_socket
 
-  controller = stem.connection.connect(
+  controller = init_controller(
     control_port = control_port,
     control_socket = control_socket,
     password = CONFIG.get('tor.password', None),
@@ -74,7 +73,6 @@ def main():
   if controller is None:
     exit(1)
 
-  init_controller(controller)
   _warn_if_root(controller)
   _warn_if_unable_to_get_pid(controller)
   _setup_freebsd_chroot(controller)
diff --git a/arm/util/__init__.py b/arm/util/__init__.py
index 3d3f725..3853b3d 100644
--- a/arm/util/__init__.py
+++ b/arm/util/__init__.py
@@ -1,7 +1,6 @@
 """
-General purpose utilities for a variety of tasks including logging the
-application's status, making cross platform system calls, parsing tor data,
-and safely working with curses (hiding some of the gory details).
+General purpose utilities for a variety of tasks supporting arm features and
+safely working with curses (hiding some of the gory details).
 """
 
 __all__ = [
@@ -15,9 +14,7 @@ __all__ = [
 import os
 import sys
 
-import stem
 import stem.connection
-import stem.control
 import stem.util.conf
 import stem.util.log
 
@@ -27,7 +24,7 @@ BASE_DIR = os.path.sep.join(__file__.split(os.path.sep)[:-2])
 try:
   uses_settings = stem.util.conf.uses_settings('arm', os.path.join(BASE_DIR, 'config'), lazy_load = False)
 except IOError as exc:
-  print "Unable to load arm's internal configurations: {error}".format(error = exc)
+  print "Unable to load arm's internal configurations: %s" % exc
   sys.exit(1)
 
 
@@ -41,18 +38,21 @@ def tor_controller():
   return TOR_CONTROLLER
 
 
-def init_controller(controller):
+def init_controller(*args, **kwargs):
   """
-  Sets the Controller used by arm.
+  Sets the Controller used by arm. This is a passthrough for Stem's
+  :func:`~stem.connection.connect` function.
 
-  :param Controller controller: control connection to be used by arm
+  :returns: :class:`~stem.control.Controller` arm is using
   """
 
   global TOR_CONTROLLER
-  TOR_CONTROLLER = controller
+  TOR_CONTROLLER = stem.connection.connect(*args, **kwargs)
+  return TOR_CONTROLLER
 
 
-def msg(message, **attr):
+ at uses_settings
+def msg(message, config, **attr):
   """
   Provides the given message.
 
@@ -62,12 +62,10 @@ def msg(message, **attr):
   :returns: **str** that was requested
   """
 
-  config = stem.util.conf.get_config('arm')
-
   try:
     return config.get('msg.%s' % message).format(**attr)
   except:
-    stem.util.log.notice('BUG: We attempted to use an undefined string resource (%s)' % message)
+    notice('BUG: We attempted to use an undefined string resource (%s)' % message)
     return ''
 
 
diff --git a/run_tests.py b/run_tests.py
index 63de9be..c7482d3 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -70,8 +70,7 @@ def main():
       print '* %s' % file_path
 
       for line_number, msg in static_check_issues[file_path]:
-        line_count = '%-4s' % line_number
-        print '  line %s - %s' % (line_count, msg)
+        print '  line %-4s - %s' % (line_number, msg)
 
       print
 





More information about the tor-commits mailing list