[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Dropping CONFIG global from starter



commit fb1e63d5e80cee8c3b9ca71d75c824c471d83986
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Jun 21 12:56:15 2014 -0700

    Dropping CONFIG global from starter
    
    Now that we have our nice @uses_settings annotation there's no longer any point
    to have a CONFIG global. I only had it there because I hated passing the config
    around by hand all the time. :)
---
 arm/starter.py |   41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/arm/starter.py b/arm/starter.py
index 1f6692f..e6db5cf 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -22,22 +22,19 @@ import arm.util.tracker
 import arm.util.ui_tools
 
 import stem
-import stem.util.conf
 import stem.util.log
 import stem.util.system
 
 from arm.util import BASE_DIR, init_controller, msg, trace, info, notice, warn, uses_settings
 
-CONFIG = stem.util.conf.get_config('arm')
-
 
 @uses_settings
-def main():
-  CONFIG.set('start_time', str(int(time.time())))
+def main(config):
+  config.set('start_time', str(int(time.time())))
 
   try:
     args = arm.arguments.parse(sys.argv[1:])
-    CONFIG.set('startup.events', args.logged_events)
+    config.set('startup.events', args.logged_events)
   except ValueError as exc:
     print exc
     sys.exit(1)
@@ -65,9 +62,9 @@ def main():
   controller = init_controller(
     control_port = control_port,
     control_socket = control_socket,
-    password = CONFIG.get('tor.password', None),
+    password = config.get('tor.password', None),
     password_prompt = True,
-    chroot_path = CONFIG.get('tor.chroot', ''),
+    chroot_path = config.get('tor.chroot', ''),
   )
 
   if controller is None:
@@ -139,25 +136,26 @@ def _setup_debug_logging(args):
   )
 
 
-def _load_user_armrc(path):
+@uses_settings
+def _load_user_armrc(path, config):
   """
   Loads user's personal armrc if it's available.
   """
 
   if os.path.exists(path):
     try:
-      CONFIG.load(path)
+      config.load(path)
 
       # If the user provided us with a chroot then validate and normalize the
       # path.
 
-      chroot = CONFIG.get('tor.chroot', '').strip().rstrip(os.path.sep)
+      chroot = config.get('tor.chroot', '').strip().rstrip(os.path.sep)
 
       if chroot and not os.path.exists(chroot):
         notice('setup.chroot_doesnt_exist', path = chroot)
-        CONFIG.set('tor.chroot', '')
+        config.set('tor.chroot', '')
       else:
-        CONFIG.set('tor.chroot', chroot)  # use the normalized path
+        config.set('tor.chroot', chroot)  # use the normalized path
     except IOError as exc:
       warn('config.unable_to_read_file', error = exc.strerror)
   else:
@@ -190,17 +188,18 @@ def _warn_if_unable_to_get_pid(controller):
     warn('setup.unable_to_determine_pid')
 
 
-def _setup_freebsd_chroot(controller):
+@uses_settings
+def _setup_freebsd_chroot(controller, config):
   """
   If we're running under FreeBSD then check the system for a chroot path.
   """
 
-  if not CONFIG.get('tor.chroot', None) and platform.system() == 'FreeBSD':
+  if not config.get('tor.chroot', None) and platform.system() == 'FreeBSD':
     jail_chroot = stem.util.system.get_bsd_jail_path(controller.get_pid(0))
 
     if jail_chroot and os.path.exists(jail_chroot):
       info('setup.set_freebsd_chroot', path = jail_chroot)
-      CONFIG.set('tor.chroot', jail_chroot)
+      config.set('tor.chroot', jail_chroot)
 
 
 def _notify_of_unknown_events():
@@ -214,13 +213,14 @@ def _notify_of_unknown_events():
     info('setup.unknown_event_types', event_types = ', '.join(missing_events))
 
 
-def _clear_password():
+@uses_settings
+def _clear_password(config):
   """
   Removing the reference to our controller password so the memory can be freed.
   Without direct memory access this is about the best we can do to clear it.
   """
 
-  CONFIG.set('tor.password', '')
+  config.set('tor.password', '')
 
 
 def _load_tor_config_descriptions():
@@ -240,14 +240,15 @@ def _use_english_subcommands():
   os.putenv('LANG', 'C')
 
 
-def _use_unicode():
+@uses_settings
+def _use_unicode(config):
   """
   If using our LANG variable for rendering multi-byte characters lets us
   get unicode support then then use it. This needs to be done before
   initializing curses.
   """
 
-  if not CONFIG.get('features.printUnicode', True):
+  if not config.get('features.printUnicode', True):
     return
 
   is_lang_unicode = "utf-" in os.getenv("LANG", "").lower()



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits