[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r23783: {arm} Providing an option to use the same ordering as the man page (in arm/trunk: . src/interface src/util)
Author: atagar
Date: 2010-11-11 03:43:02 +0000 (Thu, 11 Nov 2010)
New Revision: 23783
Modified:
arm/trunk/armrc.sample
arm/trunk/src/interface/configStatePanel.py
arm/trunk/src/interface/controller.py
arm/trunk/src/util/torConfig.py
Log:
Providing an option to use the same ordering as the man page.
fix: miscategorizing the first config option in each category
Modified: arm/trunk/armrc.sample
===================================================================
--- arm/trunk/armrc.sample 2010-11-10 18:55:47 UTC (rev 23782)
+++ arm/trunk/armrc.sample 2010-11-11 03:43:02 UTC (rev 23783)
@@ -61,7 +61,7 @@
# order
# three comma separated configuration attributes, options including:
# 0 -> Category, 1 -> Option Name, 2 -> Value, 3 -> Arg Type,
-# 4 -> Arg Usage, 5 -> Description, 6 -> Is Default
+# 4 -> Arg Usage, 5 -> Description, 6 -> Man Entry, 7 -> Is Default
# colWidth.*
# maximum column content width
# showScrollbars
@@ -76,7 +76,7 @@
# values or being setable themselves
features.config.type 0
-features.config.order 0, 1, 6
+features.config.order 0, 6, 7
features.config.state.colWidth.option 25
features.config.state.colWidth.value 15
features.config.file.showScrollbars true
Modified: arm/trunk/src/interface/configStatePanel.py
===================================================================
--- arm/trunk/src/interface/configStatePanel.py 2010-11-10 18:55:47 UTC (rev 23782)
+++ arm/trunk/src/interface/configStatePanel.py 2010-11-11 03:43:02 UTC (rev 23783)
@@ -26,14 +26,15 @@
torConfig.UNKNOWN: "black"}
# attributes of a ConfigEntry
-FIELD_CATEGORY, FIELD_OPTION, FIELD_VALUE, FIELD_TYPE, FIELD_ARG_USAGE, FIELD_DESCRIPTION, FIELD_IS_DEFAULT = range(7)
-DEFAULT_SORT_ORDER = (FIELD_CATEGORY, FIELD_OPTION, FIELD_IS_DEFAULT)
+FIELD_CATEGORY, FIELD_OPTION, FIELD_VALUE, FIELD_TYPE, FIELD_ARG_USAGE, FIELD_DESCRIPTION, FIELD_MAN_ENTRY, FIELD_IS_DEFAULT = range(8)
+DEFAULT_SORT_ORDER = (FIELD_CATEGORY, FIELD_MAN_ENTRY, FIELD_IS_DEFAULT)
FIELD_ATTR = {FIELD_CATEGORY: ("Category", "red"),
FIELD_OPTION: ("Option Name", "blue"),
FIELD_VALUE: ("Value", "cyan"),
FIELD_TYPE: ("Arg Type", "green"),
FIELD_ARG_USAGE: ("Arg Usage", "yellow"),
FIELD_DESCRIPTION: ("Description", "white"),
+ FIELD_MAN_ENTRY: ("Man Page Entry", "blue"),
FIELD_IS_DEFAULT: ("Is Default", "magenta")}
class ConfigEntry():
@@ -41,14 +42,22 @@
Configuration option in the panel.
"""
- def __init__(self, category, option, type, argumentUsage, description, isDefault):
+ def __init__(self, option, type, isDefault, manEntry):
self.fields = {}
- self.fields[FIELD_CATEGORY] = category
self.fields[FIELD_OPTION] = option
self.fields[FIELD_TYPE] = type
- self.fields[FIELD_ARG_USAGE] = argumentUsage
- self.fields[FIELD_DESCRIPTION] = description
self.fields[FIELD_IS_DEFAULT] = isDefault
+
+ if manEntry:
+ self.fields[FIELD_MAN_ENTRY] = manEntry.index
+ self.fields[FIELD_CATEGORY] = manEntry.category
+ self.fields[FIELD_ARG_USAGE] = manEntry.argUsage
+ self.fields[FIELD_DESCRIPTION] = manEntry.description
+ else:
+ self.fields[FIELD_MAN_ENTRY] = 99999 # sorts non-man entries last
+ self.fields[FIELD_CATEGORY] = torConfig.UNKNOWN
+ self.fields[FIELD_ARG_USAGE] = ""
+ self.fields[FIELD_DESCRIPTION] = ""
def get(self, field):
"""
@@ -139,11 +148,8 @@
elif not self._config["features.config.showVirtualOptions"] and confType == "Virtual":
continue
- cat, arg, desc = None, "", ""
- descriptionComp = torConfig.getConfigDescription(confOption)
- if descriptionComp: cat, arg, desc = descriptionComp
-
- self.confContents.append(ConfigEntry(cat, confOption, confType, arg, desc, not confOption in setOptions))
+ manEntry = torConfig.getConfigDescription(confOption)
+ self.confContents.append(ConfigEntry(confOption, confType, not confOption in setOptions, manEntry))
self.setSortOrder() # initial sorting of the contents
Modified: arm/trunk/src/interface/controller.py
===================================================================
--- arm/trunk/src/interface/controller.py 2010-11-10 18:55:47 UTC (rev 23782)
+++ arm/trunk/src/interface/controller.py 2010-11-11 03:43:02 UTC (rev 23783)
@@ -1529,9 +1529,9 @@
elif page == 2 and (key == ord('s') or key == ord('S')):
# set ordering for config options
titleLabel = "Config Option Ordering:"
- options = [configStatePanel.FIELD_ATTR[i][0] for i in range(7)]
+ options = [configStatePanel.FIELD_ATTR[i][0] for i in range(8)]
oldSelection = [configStatePanel.FIELD_ATTR[entry][0] for entry in panels["torrc"].sortOrdering]
- optionColors = dict([configStatePanel.FIELD_ATTR[i] for i in range(7)])
+ optionColors = dict([configStatePanel.FIELD_ATTR[i] for i in range(8)])
results = showSortDialog(stdscr, panels, isPaused, page, titleLabel, options, oldSelection, optionColors)
if results:
Modified: arm/trunk/src/util/torConfig.py
===================================================================
--- arm/trunk/src/util/torConfig.py 2010-11-10 18:55:47 UTC (rev 23782)
+++ arm/trunk/src/util/torConfig.py 2010-11-11 03:43:02 UTC (rev 23783)
@@ -58,6 +58,17 @@
configValues = config.get(configKey, "").split(",")
if configValues: CONFIG[configKey] = [val.strip() for val in configValues]
+class ManPageEntry:
+ """
+ Information provided about a tor configuration option in its man page entry.
+ """
+
+ def __init__(self, index, category, argUsage, description):
+ self.index = index
+ self.category = category
+ self.argUsage = argUsage
+ self.description = description
+
def getTorrc():
"""
Singleton constructor for a Controller. Be aware that this starts as being
@@ -111,6 +122,16 @@
baseMsg = "invalid category in input file: '%s'"
raise IOError(baseMsg % categoryStr)
+ # gets the position in the man page
+ indexArg, indexStr = -1, inputFileContents.pop(0).rstrip()
+
+ if indexStr.startswith("index: "):
+ indexStr = indexStr[7:]
+
+ if indexStr.isdigit(): indexArg = int(indexStr)
+ else: raise IOError("non-numeric index value: %s" % indexStr)
+ else: raise IOError("malformed index argument: %s"% indexStr)
+
option = inputFileContents.pop(0).rstrip()
argument = inputFileContents.pop(0).rstrip()
@@ -121,7 +142,7 @@
if inputFileContents: loadedLine = inputFileContents.pop(0)
else: break
- CONFIG_DESCRIPTIONS[option.lower()] = (category, argument, description.rstrip())
+ CONFIG_DESCRIPTIONS[option.lower()] = ManPageEntry(indexArg, category, argument, description.rstrip())
except IndexError:
CONFIG_DESCRIPTIONS.clear()
raise IOError("input file format is invalid")
@@ -135,37 +156,30 @@
if configOptionQuery:
validOptions = [line[:line.find(" ")].lower() for line in configOptionQuery]
- lastOption, lastArg = None, None
+ optionCount, lastOption, lastArg = 0, None, None
lastCategory, lastDescription = GENERAL, ""
for line in manCallResults:
strippedLine = line.strip()
- # checks if this is a category header
- if not line.startswith(" ") and "OPTIONS" in line:
- if line.startswith("CLIENT"): lastCategory = CLIENT
- elif line.startswith("SERVER"): lastCategory = SERVER
- elif line.startswith("DIRECTORY SERVER"): lastCategory = DIRECTORY
- elif line.startswith("DIRECTORY AUTHORITY SERVER"): lastCategory = AUTHORITY
- elif line.startswith("HIDDEN SERVICE"): lastCategory = HIDDEN_SERVICE
- elif line.startswith("TESTING NETWORK"): lastCategory = TESTING
- else:
- msg = "Unrecognized category in the man page: %s" % line.strip()
- log.log(CONFIG["log.configDescriptions.unrecognizedCategory"], msg)
-
# we have content, but an indent less than an option (ignore line)
- if strippedLine and not line.startswith(" " * MAN_OPT_INDENT): continue
+ #if strippedLine and not line.startswith(" " * MAN_OPT_INDENT): continue
# line starts with an indent equivilant to a new config option
isOptIndent = line.startswith(" " * MAN_OPT_INDENT) and line[MAN_OPT_INDENT] != " "
- if isOptIndent:
+ isCategoryLine = not line.startswith(" ") and "OPTIONS" in line
+
+ # if this is a category header or a new option, add an entry using the
+ # buffered results
+ if isOptIndent or isCategoryLine:
# Filters the line based on if the option is recognized by tor or
# not. This isn't necessary for arm, so if unable to make the check
# then we skip filtering (no loss, the map will just have some extra
# noise).
strippedDescription = lastDescription.strip()
if lastOption and (not validOptions or lastOption.lower() in validOptions):
- CONFIG_DESCRIPTIONS[lastOption.lower()] = (lastCategory, lastArg, strippedDescription)
+ CONFIG_DESCRIPTIONS[lastOption.lower()] = ManPageEntry(optionCount, lastCategory, lastArg, strippedDescription)
+ optionCount += 1
lastDescription = ""
# parses the option and argument
@@ -173,6 +187,18 @@
divIndex = line.find(" ")
if divIndex != -1:
lastOption, lastArg = line[:divIndex], line[divIndex + 1:]
+
+ # if this is a category header then switch it
+ if isCategoryLine:
+ if line.startswith("CLIENT"): lastCategory = CLIENT
+ elif line.startswith("SERVER"): lastCategory = SERVER
+ elif line.startswith("DIRECTORY SERVER"): lastCategory = DIRECTORY
+ elif line.startswith("DIRECTORY AUTHORITY SERVER"): lastCategory = AUTHORITY
+ elif line.startswith("HIDDEN SERVICE"): lastCategory = HIDDEN_SERVICE
+ elif line.startswith("TESTING NETWORK"): lastCategory = TESTING
+ else:
+ msg = "Unrecognized category in the man page: %s" % line.strip()
+ log.log(CONFIG["log.configDescriptions.unrecognizedCategory"], msg)
else:
# Appends the text to the running description. Empty lines and lines
# starting with a specific indentation are used for formatting, for
@@ -211,8 +237,8 @@
for i in range(len(sortedOptions)):
option = sortedOptions[i]
- category, argument, description = getConfigDescription(option)
- outputFile.write("%s\n%s\n%s\n%s\n" % (OPTION_CATEGORY_STR[category], option, argument, description))
+ manEntry = getConfigDescription(option)
+ outputFile.write("%s\nindex: %i\n%s\n%s\n%s\n" % (OPTION_CATEGORY_STR[manEntry.category], manEntry.index, option, manEntry.argUsage, manEntry.description))
if i != len(sortedOptions) - 1: outputFile.write(PERSIST_ENTRY_DIVIDER)
outputFile.close()
@@ -220,14 +246,11 @@
def getConfigDescription(option):
"""
- Provides a tuple of the form:
- (category, argument usage, description)
+ Provides ManPageEntry instances populated with information fetched from the
+ tor man page. This provides None if no such option has been loaded. If the
+ man page is in the process of being loaded then this call blocks until it
+ finishes.
- with information for the tor tor configuration option fetched from its man
- page. This provides a type of UKNOWN if no such option has been loaded. If
- the man page is in the process of being loaded then this call blocks until
- it finishes.
-
Arguments:
option - tor config option
"""
@@ -236,7 +259,7 @@
if option.lower() in CONFIG_DESCRIPTIONS:
returnVal = CONFIG_DESCRIPTIONS[option.lower()]
- else: returnVal = (UNKNOWN, "", "")
+ else: returnVal = None
CONFIG_DESCRIPTIONS_LOCK.release()
return returnVal