[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r23730: {arm} Color coding config options by their category (clinet, relay (in arm/trunk: . src/interface src/util)
Author: atagar
Date: 2010-11-02 14:45:54 +0000 (Tue, 02 Nov 2010)
New Revision: 23730
Modified:
arm/trunk/armrc.sample
arm/trunk/src/interface/configStatePanel.py
arm/trunk/src/util/torConfig.py
Log:
Color coding config options by their category (clinet, relay, auth, etc).
Modified: arm/trunk/armrc.sample
===================================================================
--- arm/trunk/armrc.sample 2010-11-01 22:02:54 UTC (rev 23729)
+++ arm/trunk/armrc.sample 2010-11-02 14:45:54 UTC (rev 23730)
@@ -191,6 +191,7 @@
log.torrc.validation.torStateDiffers NOTICE
log.configDescriptions.readManPageSuccess INFO
log.configDescriptions.readManPageFailed WARN
+log.configDescriptions.unrecognizedCategory NOTICE
log.configDescriptions.persistance.loadSuccess INFO
log.configDescriptions.persistance.loadFailed INFO
log.configDescriptions.persistance.saveSuccess NOTICE
Modified: arm/trunk/src/interface/configStatePanel.py
===================================================================
--- arm/trunk/src/interface/configStatePanel.py 2010-11-01 22:02:54 UTC (rev 23729)
+++ arm/trunk/src/interface/configStatePanel.py 2010-11-02 14:45:54 UTC (rev 23730)
@@ -13,14 +13,25 @@
TOR_STATE, ARM_STATE = range(1, 3) # state to be presented
+# mappings of option categories to the color for their entries
+CATEGORY_COLOR = {torConfig.GENERAL: "green",
+ torConfig.CLIENT: "blue",
+ torConfig.SERVER: "yellow",
+ torConfig.DIRECTORY: "magenta",
+ torConfig.AUTHORITY: "red",
+ torConfig.HIDDEN_SERVICE: "cyan",
+ torConfig.TESTING: "white"}
+
class ConfigEntry():
"""
Configuration option in the panel.
"""
- def __init__(self, option, type, description = "", isDefault = True):
+ def __init__(self, category, option, type, argumentUsage, description, isDefault):
+ self.category = category
self.option = option
self.type = type
+ self.argumentUsage = argumentUsage
self.description = description
self.isDefault = isDefault
@@ -82,16 +93,16 @@
line = configOptionQuery[lineNum]
confOption, confType = line.strip().split(" ", 1)
- confDescription = ""
+ cat, arg, desc = None, "", ""
descriptionComp = torConfig.getConfigDescription(confOption)
- if descriptionComp: confDescription = descriptionComp[1]
+ if descriptionComp: cat, arg, desc = descriptionComp
- self.confContents.append(ConfigEntry(confOption, confType, confDescription, not confOption in setOptions))
+ self.confContents.append(ConfigEntry(cat, confOption, confType, arg, desc, not confOption in setOptions))
elif self.configType == ARM_STATE:
# loaded via the conf utility
armConf = conf.getConfig("arm")
for key in armConf.getKeys():
- self.confContents.append(ConfigEntry(key, ", ".join(armConf.getValue(key, [], True)), ""))
+ self.confContents.append(ConfigEntry("", key, ", ".join(armConf.getValue(key, [], True)), "", "", True))
#self.confContents.sort() # TODO: make contents sortable?
def handleKey(self, key):
@@ -141,7 +152,9 @@
valueLabel = uiTools.cropStr(entryToValues[entry], valueColWidth)
descriptionLabel = uiTools.cropStr(entry.description, descriptionColWidth, None)
- lineFormat = uiTools.getColor("green") if entry.isDefault else curses.A_BOLD | uiTools.getColor("yellow")
+ lineFormat = curses.A_NORMAL if entry.isDefault else curses.A_BOLD
+ if entry.category: lineFormat |= uiTools.getColor(CATEGORY_COLOR[entry.category])
+ #lineFormat = uiTools.getColor("green") if entry.isDefault else curses.A_BOLD | uiTools.getColor("yellow")
if entry == cursorSelection: lineFormat |= curses.A_STANDOUT
lineTextLayout = "%%-%is %%-%is %%-%is %%-%is" % (optionColWidth, valueColWidth, typeColWidth, descriptionColWidth)
Modified: arm/trunk/src/util/torConfig.py
===================================================================
--- arm/trunk/src/util/torConfig.py 2010-11-01 22:02:54 UTC (rev 23729)
+++ arm/trunk/src/util/torConfig.py 2010-11-02 14:45:54 UTC (rev 23730)
@@ -6,7 +6,7 @@
import curses
import threading
-from util import sysTools, torTools, uiTools
+from util import log, sysTools, torTools, uiTools
CONFIG = {"features.torrc.validate": True,
"torrc.multiline": [],
@@ -20,7 +20,8 @@
"torrc.label.time.min": [],
"torrc.label.time.hour": [],
"torrc.label.time.day": [],
- "torrc.label.time.week": []}
+ "torrc.label.time.week": [],
+ "log.configDescriptions.unrecognizedCategory": log.NOTICE}
# enums and values for numeric torrc entries
UNRECOGNIZED, SIZE_VALUE, TIME_VALUE = range(1, 4)
@@ -36,6 +37,13 @@
CONFIG_DESCRIPTIONS_LOCK = threading.RLock()
CONFIG_DESCRIPTIONS = {}
+# categories for tor configuration options
+GENERAL, CLIENT, SERVER, DIRECTORY, AUTHORITY, HIDDEN_SERVICE, TESTING = range(1, 8)
+OPTION_CATEGORY_STR = {GENERAL: "General", CLIENT: "Client",
+ SERVER: "Relay", DIRECTORY: "Directory",
+ AUTHORITY: "Authority", HIDDEN_SERVICE: "Hidden Service",
+ TESTING: "Testing"}
+
TORRC = None # singleton torrc instance
MAN_OPT_INDENT = 7 # indentation before options in the man page
MAN_EX_INDENT = 15 # indentation used for man page examples
@@ -91,8 +99,19 @@
inputFileContents = inputFile.readlines()
inputFile.close()
+ # constructs a reverse mapping for categories
+ strToCat = dict([(OPTION_CATEGORY_STR[cat], cat) for cat in OPTION_CATEGORY_STR])
+
try:
while inputFileContents:
+ # gets category enum, failing if it doesn't exist
+ categoryStr = inputFileContents.pop(0).rstrip()
+ if categoryStr in strToCat:
+ category = strToCat[categoryStr]
+ else:
+ baseMsg = "invalid category in input file: '%s'"
+ raise IOError(baseMsg % categoryStr)
+
option = inputFileContents.pop(0).rstrip()
argument = inputFileContents.pop(0).rstrip()
@@ -103,7 +122,7 @@
if inputFileContents: loadedLine = inputFileContents.pop(0)
else: break
- CONFIG_DESCRIPTIONS[option.lower()] = (argument, description.rstrip())
+ CONFIG_DESCRIPTIONS[option.lower()] = (category, argument, description.rstrip())
except IndexError:
CONFIG_DESCRIPTIONS.clear()
raise IOError("input file format is invalid")
@@ -118,10 +137,22 @@
validOptions = [line[:line.find(" ")].lower() for line in configOptionQuery]
lastOption, lastArg = None, None
- lastDescription = ""
+ 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
@@ -135,7 +166,7 @@
# noise).
strippedDescription = lastDescription.strip()
if lastOption and (not validOptions or lastOption.lower() in validOptions):
- CONFIG_DESCRIPTIONS[lastOption.lower()] = (lastArg, strippedDescription)
+ CONFIG_DESCRIPTIONS[lastOption.lower()] = (lastCategory, lastArg, strippedDescription)
lastDescription = ""
# parses the option and argument
@@ -181,8 +212,8 @@
for i in range(len(sortedOptions)):
option = sortedOptions[i]
- argument, description = getConfigDescription(option)
- outputFile.write("%s\n%s\n%s\n" % (option, argument, description))
+ category, argument, description = getConfigDescription(option)
+ outputFile.write("%s\n%s\n%s\n%s\n" % (OPTION_CATEGORY_STR[category], option, argument, description))
if i != len(sortedOptions) - 1: outputFile.write(PERSIST_ENTRY_DIVIDER)
outputFile.close()
@@ -190,11 +221,13 @@
def getConfigDescription(option):
"""
- Provides a tuple with arguments and description for the given tor
- configuration option, fetched from its 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.
+ Provides a tuple of the form:
+ (category, argument usage, description)
+ with information for the tor tor configuration option fetched from its 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.
+
Arguments:
option - tor config option
"""