[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [arm/release] Covering tor config options with /help
commit aa7fee5d5d92e33e81a169c254c4fc80a3ce0947
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Wed Sep 14 09:56:04 2011 -0700
Covering tor config options with /help
Issuing '/help [tor config option]' (for instance '/help exitpolicy') will
provide usage information and the man page description for the option.
---
src/util/torConfig.py | 14 +++++++-------
src/util/torInterpretor.py | 24 ++++++++++++++++++++++--
2 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/src/util/torConfig.py b/src/util/torConfig.py
index 557dc09..b2cf345 100644
--- a/src/util/torConfig.py
+++ b/src/util/torConfig.py
@@ -77,7 +77,8 @@ class ManPageEntry:
Information provided about a tor configuration option in its man page entry.
"""
- def __init__(self, index, category, argUsage, description):
+ def __init__(self, option, index, category, argUsage, description):
+ self.option = option
self.index = index
self.category = category
self.argUsage = argUsage
@@ -168,7 +169,7 @@ def loadOptionDescriptions(loadPath = None, checkVersion = True):
if inputFileContents: loadedLine = inputFileContents.pop(0)
else: break
- CONFIG_DESCRIPTIONS[option.lower()] = ManPageEntry(indexArg, category, argument, description.rstrip())
+ CONFIG_DESCRIPTIONS[option.lower()] = ManPageEntry(option, indexArg, category, argument, description.rstrip())
except IndexError:
CONFIG_DESCRIPTIONS.clear()
raise IOError("input file format is invalid")
@@ -209,7 +210,7 @@ def loadOptionDescriptions(loadPath = None, checkVersion = True):
# noise).
strippedDescription = lastDescription.strip()
if lastOption and (not validOptions or lastOption.lower() in validOptions):
- CONFIG_DESCRIPTIONS[lastOption.lower()] = ManPageEntry(optionCount, lastCategory, lastArg, strippedDescription)
+ CONFIG_DESCRIPTIONS[lastOption.lower()] = ManPageEntry(lastOption, optionCount, lastCategory, lastArg, strippedDescription)
optionCount += 1
lastDescription = ""
@@ -271,9 +272,8 @@ def saveOptionDescriptions(path):
torVersion = torTools.getConn().getInfo("version", "")
outputFile.write("Tor Version %s\n" % torVersion)
for i in range(len(sortedOptions)):
- option = sortedOptions[i]
- manEntry = getConfigDescription(option)
- outputFile.write("%s\nindex: %i\n%s\n%s\n%s\n" % (manEntry.category, manEntry.index, option, manEntry.argUsage, manEntry.description))
+ manEntry = getConfigDescription(sortedOptions[i])
+ outputFile.write("%s\nindex: %i\n%s\n%s\n%s\n" % (manEntry.category, manEntry.index, manEntry.option, manEntry.argUsage, manEntry.description))
if i != len(sortedOptions) - 1: outputFile.write(PERSIST_ENTRY_DIVIDER)
outputFile.close()
@@ -281,7 +281,7 @@ def saveOptionDescriptions(path):
def getConfigSummary(option):
"""
- Provides a short summary description of th configuration option. If none is
+ Provides a short summary description of the configuration option. If none is
known then this proivdes None.
Arguments:
diff --git a/src/util/torInterpretor.py b/src/util/torInterpretor.py
index 3908d6e..5733f8a 100644
--- a/src/util/torInterpretor.py
+++ b/src/util/torInterpretor.py
@@ -9,7 +9,7 @@ import readline
import version
-from util import connections, enum, hostnames, torTools
+from util import connections, enum, hostnames, torConfig, torTools, uiTools
COLOR_PROMPT = True # provides a colored interpretor prompt
INFO_HOSTNAMES = False # hostname lookups in /info results
@@ -300,7 +300,27 @@ class ControlInterpretor:
for line in description.split("\n"):
outputEntry.append((" " + line + "\n", OUTPUT_FORMAT))
else:
- outputEntry.append(("No help information for '%s'..." % arg, ERROR_FORMAT))
+ # check if this is a configuration option
+ manEntry = torConfig.getConfigDescription(arg)
+
+ if manEntry:
+ # provides basic usage information in bold, followed an indented
+ # copy of the man page description (wrapped to eighty characters)
+
+ helpTitle = "%s %s (category: %s)\n" % (manEntry.option, manEntry.argUsage, manEntry.category)
+ outputEntry.append((helpTitle, OUTPUT_FORMAT + (Attr.BOLD, )))
+
+ descLines = manEntry.description.split("\n")
+
+ for line in descLines:
+ if not line:
+ outputEntry.append(("\n", OUTPUT_FORMAT))
+ else:
+ while line:
+ drawPortion, line = uiTools.cropStr(line, 88, 4, 4, uiTools.Ending.HYPHEN, True)
+ outputEntry.append((" %s\n" % drawPortion.strip(), OUTPUT_FORMAT))
+ else:
+ outputEntry.append(("No help information for '%s'..." % arg, ERROR_FORMAT))
else:
# provides the GENERAL_HELP with everything bolded except descriptions
for line in GENERAL_HELP.split("\n"):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits