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

[tor-commits] [arm/master] Moving loadConfigurationDescriptions() to torConfig



commit f893c6d18af950c9b61bb2d3f332f2ecd31bb862
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Sep 9 16:59:07 2013 -0700

    Moving loadConfigurationDescriptions() to torConfig
    
    Huh. Haven't a clue why this is in the starter...
---
 arm/starter.py        |   89 +++----------------------------------------------
 arm/util/torConfig.py |   80 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 85 deletions(-)

diff --git a/arm/starter.py b/arm/starter.py
index 96f4f19..834eceb 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -41,24 +41,12 @@ CONFIG = stem.util.conf.config_dict("arm", {
   "startup.controlPassword": None,
   "startup.blindModeEnabled": False,
   "startup.events": "N3",
-  "startup.dataDirectory": "~/.arm",
-  "features.config.descriptions.enabled": True,
-  "features.config.descriptions.persist": True,
   "msg.help": "",
 })
 
-# filename used for cached tor config descriptions
-CONFIG_DESC_FILENAME = "torConfigDesc.txt"
-
-# messages related to loading the tor configuration descriptions
-DESC_LOAD_SUCCESS_MSG = "Loaded configuration descriptions from '%s' (runtime: %0.3f)"
-DESC_LOAD_FAILED_MSG = "Unable to load configuration descriptions (%s)"
-DESC_INTERNAL_LOAD_SUCCESS_MSG = "Falling back to descriptions for Tor %s"
-DESC_INTERNAL_LOAD_FAILED_MSG = "Unable to load fallback descriptions. Categories and help for Tor's configuration options won't be available. (%s)"
-DESC_READ_MAN_SUCCESS_MSG = "Read descriptions for tor's configuration options from its man page (runtime %0.3f)"
-DESC_READ_MAN_FAILED_MSG = "Unable to get the descriptions of Tor's configuration options from its man page (%s)"
-DESC_SAVE_SUCCESS_MSG = "Saved configuration descriptions to '%s' (runtime: %0.3f)"
-DESC_SAVE_FAILED_MSG = "Unable to save configuration descriptions (%s)"
+# notices given if the user is running arm or tor as root
+TOR_ROOT_NOTICE = "Tor is currently running with root permissions. This is not a good idea and shouldn't be necessary. See the 'User UID' option from Tor's man page for an easy method of reducing its permissions after startup."
+ARM_ROOT_NOTICE = "Arm is currently running with root permissions. This is not a good idea, and will still work perfectly well if it's run with the same user as Tor (ie, starting with \"sudo -u %s arm\")."
 
 NO_INTERNAL_CFG_MSG = "Failed to load the parsing configuration. This will be problematic for a few things like torrc validation and log duplication detection (%s)"
 STANDARD_CFG_LOAD_FAILED_MSG = "Failed to load configuration (using defaults): \"%s\""
@@ -67,10 +55,6 @@ STANDARD_CFG_NOT_FOUND_MSG = "No armrc loaded, using defaults. You can customize
 # torrc entries that are scrubbed when dumping
 PRIVATE_TORRC_ENTRIES = ["HashedControlPassword", "Bridge", "HiddenServiceDir"]
 
-# notices given if the user is running arm or tor as root
-TOR_ROOT_NOTICE = "Tor is currently running with root permissions. This is not a good idea and shouldn't be necessary. See the 'User UID' option from Tor's man page for an easy method of reducing its permissions after startup."
-ARM_ROOT_NOTICE = "Arm is currently running with root permissions. This is not a good idea, and will still work perfectly well if it's run with the same user as Tor (ie, starting with \"sudo -u %s arm\")."
-
 # Makes subcommands provide us with English results (this is important so we
 # can properly parse it).
 
@@ -152,71 +136,6 @@ def _get_args(argv):
   return Args(**args)
 
 
-def _loadConfigurationDescriptions(pathPrefix):
-  """
-  Attempts to load descriptions for tor's configuration options, fetching them
-  from the man page and persisting them to a file to speed future startups.
-  """
-  
-  # It is important that this is loaded before entering the curses context,
-  # otherwise the man call pegs the cpu for around a minute (I'm not sure
-  # why... curses must mess the terminal in a way that's important to man).
-  
-  if CONFIG["features.config.descriptions.enabled"]:
-    isConfigDescriptionsLoaded = False
-    
-    # determines the path where cached descriptions should be persisted (left
-    # undefined if caching is disabled)
-    descriptorPath = None
-    if CONFIG["features.config.descriptions.persist"]:
-      dataDir = CONFIG["startup.dataDirectory"]
-      if not dataDir.endswith("/"): dataDir += "/"
-      
-      descriptorPath = os.path.expanduser(dataDir + "cache/") + CONFIG_DESC_FILENAME
-    
-    # attempts to load configuration descriptions cached in the data directory
-    if descriptorPath:
-      try:
-        loadStartTime = time.time()
-        arm.util.torConfig.loadOptionDescriptions(descriptorPath)
-        isConfigDescriptionsLoaded = True
-        
-        stem.util.log.info(DESC_LOAD_SUCCESS_MSG % (descriptorPath, time.time() - loadStartTime))
-      except IOError, exc:
-        stem.util.log.info(DESC_LOAD_FAILED_MSG % arm.util.sysTools.getFileErrorMsg(exc))
-    
-    # fetches configuration options from the man page
-    if not isConfigDescriptionsLoaded:
-      try:
-        loadStartTime = time.time()
-        arm.util.torConfig.loadOptionDescriptions()
-        isConfigDescriptionsLoaded = True
-        
-        stem.util.log.info(DESC_READ_MAN_SUCCESS_MSG % (time.time() - loadStartTime))
-      except IOError, exc:
-        stem.util.log.notice(DESC_READ_MAN_FAILED_MSG % arm.util.sysTools.getFileErrorMsg(exc))
-      
-      # persists configuration descriptions 
-      if isConfigDescriptionsLoaded and descriptorPath:
-        try:
-          loadStartTime = time.time()
-          arm.util.torConfig.saveOptionDescriptions(descriptorPath)
-          stem.util.log.info(DESC_SAVE_SUCCESS_MSG % (descriptorPath, time.time() - loadStartTime))
-        except (IOError, OSError), exc:
-          stem.util.log.notice(DESC_SAVE_FAILED_MSG % arm.util.sysTools.getFileErrorMsg(exc))
-    
-    # finally fall back to the cached descriptors provided with arm (this is
-    # often the case for tbb and manual builds)
-    if not isConfigDescriptionsLoaded:
-      try:
-        loadStartTime = time.time()
-        loadedVersion = arm.util.torConfig.loadOptionDescriptions("%sresources/%s" % (pathPrefix, CONFIG_DESC_FILENAME), False)
-        isConfigDescriptionsLoaded = True
-        stem.util.log.notice(DESC_INTERNAL_LOAD_SUCCESS_MSG % loadedVersion)
-      except IOError, exc:
-        stem.util.log.error(DESC_INTERNAL_LOAD_FAILED_MSG % arm.util.sysTools.getFileErrorMsg(exc))
-
-
 def _get_controller(args):
   """
   Provides a Controller for the endpoint specified in the given arguments.
@@ -432,7 +351,7 @@ def main():
     stem.util.log.notice(ARM_ROOT_NOTICE % torUserLabel)
   
   # fetches descriptions for tor's configuration options
-  _loadConfigurationDescriptions(pathPrefix)
+  arm.util.torConfig.loadConfigurationDescriptions(pathPrefix)
   
   # dump tor and arm configuration when in debug mode
   if args.debug:
diff --git a/arm/util/torConfig.py b/arm/util/torConfig.py
index 955e1c5..34fc989 100644
--- a/arm/util/torConfig.py
+++ b/arm/util/torConfig.py
@@ -13,6 +13,19 @@ from arm.util import sysTools, torTools, uiTools
 
 from stem.util import conf, enum, log, str_tools, system
 
+# filename used for cached tor config descriptions
+CONFIG_DESC_FILENAME = "torConfigDesc.txt"
+
+# messages related to loading the tor configuration descriptions
+DESC_LOAD_SUCCESS_MSG = "Loaded configuration descriptions from '%s' (runtime: %0.3f)"
+DESC_LOAD_FAILED_MSG = "Unable to load configuration descriptions (%s)"
+DESC_INTERNAL_LOAD_SUCCESS_MSG = "Falling back to descriptions for Tor %s"
+DESC_INTERNAL_LOAD_FAILED_MSG = "Unable to load fallback descriptions. Categories and help for Tor's configuration options won't be available. (%s)"
+DESC_READ_MAN_SUCCESS_MSG = "Read descriptions for tor's configuration options from its man page (runtime %0.3f)"
+DESC_READ_MAN_FAILED_MSG = "Unable to get the descriptions of Tor's configuration options from its man page (%s)"
+DESC_SAVE_SUCCESS_MSG = "Saved configuration descriptions to '%s' (runtime: %0.3f)"
+DESC_SAVE_FAILED_MSG = "Unable to save configuration descriptions (%s)"
+
 def conf_handler(key, value):
   if key == "config.important":
     # stores lowercase entries to drop case sensitivity
@@ -32,6 +45,9 @@ CONFIG = conf.config_dict("arm", {
   "torrc.label.time.hour": [],
   "torrc.label.time.day": [],
   "torrc.label.time.week": [],
+  "startup.dataDirectory": "~/.arm",
+  "features.config.descriptions.enabled": True,
+  "features.config.descriptions.persist": True,
 }, conf_handler)
 
 def general_conf_handler(config, key):
@@ -1039,3 +1055,67 @@ def renderTorrc(template, options, commentIndent = 30):
   
   return "\n".join(results)
 
+def loadConfigurationDescriptions(pathPrefix):
+  """
+  Attempts to load descriptions for tor's configuration options, fetching them
+  from the man page and persisting them to a file to speed future startups.
+  """
+  
+  # It is important that this is loaded before entering the curses context,
+  # otherwise the man call pegs the cpu for around a minute (I'm not sure
+  # why... curses must mess the terminal in a way that's important to man).
+  
+  if CONFIG["features.config.descriptions.enabled"]:
+    isConfigDescriptionsLoaded = False
+    
+    # determines the path where cached descriptions should be persisted (left
+    # undefined if caching is disabled)
+    descriptorPath = None
+    if CONFIG["features.config.descriptions.persist"]:
+      dataDir = CONFIG["startup.dataDirectory"]
+      if not dataDir.endswith("/"): dataDir += "/"
+      
+      descriptorPath = os.path.expanduser(dataDir + "cache/") + CONFIG_DESC_FILENAME
+    
+    # attempts to load configuration descriptions cached in the data directory
+    if descriptorPath:
+      try:
+        loadStartTime = time.time()
+        loadOptionDescriptions(descriptorPath)
+        isConfigDescriptionsLoaded = True
+        
+        log.info(DESC_LOAD_SUCCESS_MSG % (descriptorPath, time.time() - loadStartTime))
+      except IOError, exc:
+        log.info(DESC_LOAD_FAILED_MSG % sysTools.getFileErrorMsg(exc))
+    
+    # fetches configuration options from the man page
+    if not isConfigDescriptionsLoaded:
+      try:
+        loadStartTime = time.time()
+        loadOptionDescriptions()
+        isConfigDescriptionsLoaded = True
+        
+        log.info(DESC_READ_MAN_SUCCESS_MSG % (time.time() - loadStartTime))
+      except IOError, exc:
+        log.notice(DESC_READ_MAN_FAILED_MSG % sysTools.getFileErrorMsg(exc))
+      
+      # persists configuration descriptions 
+      if isConfigDescriptionsLoaded and descriptorPath:
+        try:
+          loadStartTime = time.time()
+          saveOptionDescriptions(descriptorPath)
+          log.info(DESC_SAVE_SUCCESS_MSG % (descriptorPath, time.time() - loadStartTime))
+        except (IOError, OSError), exc:
+          log.notice(DESC_SAVE_FAILED_MSG % sysTools.getFileErrorMsg(exc))
+    
+    # finally fall back to the cached descriptors provided with arm (this is
+    # often the case for tbb and manual builds)
+    if not isConfigDescriptionsLoaded:
+      try:
+        loadStartTime = time.time()
+        loadedVersion = loadOptionDescriptions("%sresources/%s" % (pathPrefix, CONFIG_DESC_FILENAME), False)
+        isConfigDescriptionsLoaded = True
+        log.notice(DESC_INTERNAL_LOAD_SUCCESS_MSG % loadedVersion)
+      except IOError, exc:
+        log.error(DESC_INTERNAL_LOAD_FAILED_MSG % sysTools.getFileErrorMsg(exc))
+



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