[or-cvs] r23708: {arm} Minor revisions concerning the config state panel and reques (in arm/trunk: . src src/interface src/util)

Damian Johnson atagar1 at gmail.com
Thu Oct 28 16:10:24 UTC 2010


Author: atagar
Date: 2010-10-28 16:10:24 +0000 (Thu, 28 Oct 2010)
New Revision: 23708

Modified:
   arm/trunk/armrc.sample
   arm/trunk/src/interface/configFilePanel.py
   arm/trunk/src/interface/configStatePanel.py
   arm/trunk/src/settings.cfg
   arm/trunk/src/util/torTools.py
   arm/trunk/src/util/torrc.py
Log:
Minor revisions concerning the config state panel and requesting options fetched specially in tor
change: moved the config option mapping logic to the torTools
change: made column sizes for the config state panel configurable
fix: wasn't properly fetching HiddenServiceOptions when requested directly



Modified: arm/trunk/armrc.sample
===================================================================
--- arm/trunk/armrc.sample	2010-10-28 15:01:23 UTC (rev 23707)
+++ arm/trunk/armrc.sample	2010-10-28 16:10:24 UTC (rev 23708)
@@ -58,14 +58,18 @@
 # ---------------------------
 # type
 #   0 -> tor state, 1 -> torrc, 2 -> arm state, 3 -> armrc
+# colWidth.*
+#   maximum column content width
 # showScrollbars
 #   displays scrollbars when the torrc content is longer than the display
 # maxLinesPerEntry
 #   max number of lines to display for a single entry in the torrc
 
 features.config.type 0
-features.config.showScrollbars true
-features.config.maxLinesPerEntry 8
+features.config.state.colWidth.option 25
+features.config.state.colWidth.value 15
+features.config.file.showScrollbars true
+features.config.file.maxLinesPerEntry 8
 
 # General graph parameters
 # ------------------------

Modified: arm/trunk/src/interface/configFilePanel.py
===================================================================
--- arm/trunk/src/interface/configFilePanel.py	2010-10-28 15:01:23 UTC (rev 23707)
+++ arm/trunk/src/interface/configFilePanel.py	2010-10-28 16:10:24 UTC (rev 23708)
@@ -8,8 +8,8 @@
 
 from util import conf, panel, torrc, uiTools
 
-DEFAULT_CONFIG = {"features.config.showScrollbars": True,
-                  "features.config.maxLinesPerEntry": 8}
+DEFAULT_CONFIG = {"features.config.file.showScrollbars": True,
+                  "features.config.file.maxLinesPerEntry": 8}
 
 TORRC, ARMRC = range(1, 3) # configuration file types that can  be displayed
 
@@ -24,7 +24,7 @@
     
     self._config = dict(DEFAULT_CONFIG)
     if config:
-      config.update(self._config, {"features.config.maxLinesPerEntry": 1})
+      config.update(self._config, {"features.config.file.maxLinesPerEntry": 1})
     
     self.valsLock = threading.RLock()
     self.configType = configType
@@ -99,7 +99,7 @@
     
     # draws left-hand scroll bar if content's longer than the height
     scrollOffset = 0
-    if self._config["features.config.showScrollbars"] and self._lastContentHeight > height - 1:
+    if self._config["features.config.file.showScrollbars"] and self._lastContentHeight > height - 1:
       scrollOffset = 3
       self.addScrollBar(self.scroll, self.scroll + height - 1, self._lastContentHeight, 1)
     
@@ -164,7 +164,7 @@
       
       # draws the rest of the components with line wrap
       cursorLoc, lineOffset = lineNumOffset + scrollOffset, 0
-      maxLinesPerEntry = self._config["features.config.maxLinesPerEntry"]
+      maxLinesPerEntry = self._config["features.config.file.maxLinesPerEntry"]
       displayQueue = [lineComp[entry] for entry in ("option", "argument", "correction", "comment")]
       
       while displayQueue:

Modified: arm/trunk/src/interface/configStatePanel.py
===================================================================
--- arm/trunk/src/interface/configStatePanel.py	2010-10-28 15:01:23 UTC (rev 23707)
+++ arm/trunk/src/interface/configStatePanel.py	2010-10-28 16:10:24 UTC (rev 23708)
@@ -8,7 +8,8 @@
 
 from util import conf, panel, torTools, uiTools
 
-DEFAULT_CONFIG = {"torrc.map": {}}
+DEFAULT_CONFIG = {"features.config.state.colWidth.option": 25,
+                  "features.config.state.colWidth.value": 15}
 
 TOR_STATE, ARM_STATE = range(1, 3) # state to be presented
 
@@ -17,11 +18,32 @@
   Configuration option in the panel.
   """
   
-  def __init__(self, option, value, type, description = ""):
+  def __init__(self, option, type, description = "", isDefault = True):
     self.option = option
-    self.value = value
     self.type = type
     self.description = description
+    self.isDefault = isDefault
+  
+  def getValue(self):
+    """
+    Provides the current value of the configuration entry, taking advantage of
+    the torTools caching to effectively query the accurate value. This uses the
+    value's type to provide a user friendly representation if able.
+    """
+    
+    conn = torTools.getConn()
+    confValue = ", ".join(conn.getOption(self.option, [], True))
+    
+    # provides nicer values for recognized types
+    if not confValue: confValue = "<none>"
+    elif self.type == "Boolean" and confValue in ("0", "1"):
+      confValue = "False" if confValue == "0" else "True"
+    elif self.type == "DataSize" and confValue.isdigit():
+      confValue = uiTools.getSizeLabel(int(confValue))
+    elif self.type == "TimeInterval" and confValue.isdigit():
+      confValue = uiTools.getTimeLabel(int(confValue), isLong = True)
+    
+    return confValue
 
 class ConfigStatePanel(panel.Panel):
   """
@@ -33,7 +55,9 @@
     panel.Panel.__init__(self, stdscr, "confState", 0)
     
     self._config = dict(DEFAULT_CONFIG)
-    if config: config.update(self._config)
+    if config: config.update(self._config, {
+      "features.config.state.colWidth.option": 5,
+      "features.config.state.colWidth.value": 5})
     
     self.configType = configType
     self.confContents = []
@@ -52,25 +76,7 @@
         # UseEntryGuards Boolean
         line = configOptionQuery[lineNum]
         confOption, confType = line.strip().split(" ", 1)
-        
-        confValue = None
-        if confOption in self._config["torrc.map"]:
-          confMappings = conn.getOptionMap(self._config["torrc.map"][confOption], {})
-          if confOption in confMappings: confValue = confMappings[confOption]
-          fetchConfOption = self._config["torrc.map"][confOption]
-        else:
-          confValue = ", ".join(conn.getOption(confOption, [], True))
-        
-        # provides nicer values for recognized types
-        if not confValue: confValue = "<none>"
-        elif confType == "Boolean" and confValue in ("0", "1"):
-          confValue = "False" if confValue == "0" else "True"
-        elif confType == "DataSize" and confValue.isdigit():
-          confValue = uiTools.getSizeLabel(int(confValue))
-        elif confType == "TimeInterval" and confValue.isdigit():
-          confValue = uiTools.getTimeLabel(int(confValue), isLong = True)
-        
-        self.confContents.append(ConfigEntry(confOption, confValue, confType))
+        self.confContents.append(ConfigEntry(confOption, confType))
     elif self.configType == ARM_STATE:
       # loaded via the conf utility
       armConf = conf.getConfig("arm")
@@ -104,21 +110,24 @@
     # determines the width for the columns
     optionColWidth, valueColWidth, typeColWidth = 0, 0, 0
     
+    # constructs a mapping of entries to their current values
+    entryToValues = {}
     for entry in self.confContents:
+      entryToValues[entry] = entry.getValue()
       optionColWidth = max(optionColWidth, len(entry.option))
-      valueColWidth = max(valueColWidth, len(entry.value))
+      valueColWidth = max(valueColWidth, len(entryToValues[entry]))
       typeColWidth = max(typeColWidth, len(entry.type))
     
     # TODO: make the size dynamic between the value and description
-    optionColWidth = min(25, optionColWidth)
-    valueColWidth = min(25, valueColWidth)
+    optionColWidth = min(self._config["features.config.state.colWidth.option"], optionColWidth)
+    valueColWidth = min(self._config["features.config.state.colWidth.value"], valueColWidth)
     
     for lineNum in range(self.scroll, len(self.confContents)):
       entry = self.confContents[lineNum]
       drawLine = lineNum + 1 - self.scroll
       
       optionLabel = uiTools.cropStr(entry.option, optionColWidth)
-      valueLabel = uiTools.cropStr(entry.value, valueColWidth)
+      valueLabel = uiTools.cropStr(entryToValues[entry], valueColWidth)
       
       self.addstr(drawLine, scrollOffset, optionLabel, curses.A_BOLD | uiTools.getColor("green"))
       self.addstr(drawLine, scrollOffset + optionColWidth + 1, valueLabel, curses.A_BOLD | uiTools.getColor("green"))

Modified: arm/trunk/src/settings.cfg
===================================================================
--- arm/trunk/src/settings.cfg	2010-10-28 15:01:23 UTC (rev 23707)
+++ arm/trunk/src/settings.cfg	2010-10-28 16:10:24 UTC (rev 23708)
@@ -76,6 +76,7 @@
 torrc.map HiddenServicePort => HiddenServiceOptions
 torrc.map HiddenServiceVersion => HiddenServiceOptions
 torrc.map HiddenServiceAuthorizeClient => HiddenServiceOptions
+torrc.map HiddenServiceOptions => HiddenServiceOptions
 
 # torrc parameters that can be defined multiple times without overwriting
 # from src/or/config.c (entries with LINELIST or LINELIST_S)

Modified: arm/trunk/src/util/torTools.py
===================================================================
--- arm/trunk/src/util/torTools.py	2010-10-28 15:01:23 UTC (rev 23707)
+++ arm/trunk/src/util/torTools.py	2010-10-28 16:10:24 UTC (rev 23708)
@@ -46,7 +46,8 @@
 
 TOR_CTL_CLOSE_MSG = "Tor closed control connection. Exiting event thread."
 UNKNOWN = "UNKNOWN" # value used by cached information if undefined
-CONFIG = {"features.pathPrefix": "",
+CONFIG = {"torrc.map": {},
+          "features.pathPrefix": "",
           "log.torCtlPortClosed": log.NOTICE,
           "log.torGetInfo": log.DEBUG,
           "log.torGetConf": log.DEBUG,
@@ -336,7 +337,18 @@
     """
     
     fetchType = "list" if multiple else "str"
-    return self._getOption(param, default, fetchType, suppressExc)
+    
+    if param in CONFIG["torrc.map"]:
+      # This is among the options fetched via a special command. The results
+      # are a set of values that (hopefully) contain the one we were
+      # requesting.
+      configMappings = self._getOption(param, default, "map", suppressExc)
+      if param in configMappings:
+        if fetchType == "list": return configMappings[param]
+        else: return configMappings[param][0]
+      else: return default
+    else:
+      return self._getOption(param, default, fetchType, suppressExc)
   
   def getOptionMap(self, param, default = None, suppressExc = True):
     """
@@ -355,6 +367,10 @@
     options that give a set of values this provides back the full response. As
     of tor version 0.2.1.25 HiddenServiceOptions was the only option like this.
     
+    The getOption function accounts for these special mappings, and the only
+    advantage to this funtion is that it provides all related values in a
+    single response.
+    
     Arguments:
       param       - configuration option to be queried
       default     - result if the query fails and exception's suppressed

Modified: arm/trunk/src/util/torrc.py
===================================================================
--- arm/trunk/src/util/torrc.py	2010-10-28 15:01:23 UTC (rev 23707)
+++ arm/trunk/src/util/torrc.py	2010-10-28 16:10:24 UTC (rev 23708)
@@ -8,7 +8,6 @@
 from util import sysTools, torTools, uiTools
 
 CONFIG = {"features.torrc.validate": True,
-          "torrc.map": {},
           "torrc.multiline": [],
           "torrc.alias": {},
           "torrc.label.size.b": [],
@@ -35,7 +34,6 @@
 TORRC = None # singleton torrc instance
 
 def loadConfig(config):
-  CONFIG["torrc.map"] = config.get("torrc.map", {})
   CONFIG["torrc.multiline"] = config.get("torrc.multiline", [])
   CONFIG["torrc.alias"] = config.get("torrc.alias", {})
   
@@ -128,13 +126,7 @@
     value, valueType = _parseConfValue(value)
     
     # issues GETCONF to get the values tor's currently configured to use
-    torValues = []
-    if option in CONFIG["torrc.map"]:
-      # special option that's fetched with special values
-      confMappings = conn.getOptionMap(CONFIG["torrc.map"][option], {})
-      if option in confMappings: torValues = confMappings[option]
-    else:
-      torValues = conn.getOption(option, [], True)
+    torValues = conn.getOption(option, [], True)
     
     # multiline entries can be comma separated values (for both tor and conf)
     valueList = [value]



More information about the tor-commits mailing list