commit 8caafbc46c7c696f97cb1895604780af63566813 Author: Damian Johnson atagar@torproject.org Date: Sat Apr 19 12:35:18 2014 -0700
Moving SIGNAL option descriptions to config
Another good candidate for our config. This required a couple fixes for our config util...
* @uses_settings couldn't be used with class methods * dictionaries were unordered - no reason not to keep ordering --- stem/interpretor/commands.py | 17 +++++------------ stem/interpretor/settings.cfg | 8 ++++++++ stem/util/conf.py | 15 +++++++++------ 3 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/stem/interpretor/commands.py b/stem/interpretor/commands.py index 4b35955..34d736d 100644 --- a/stem/interpretor/commands.py +++ b/stem/interpretor/commands.py @@ -15,16 +15,6 @@ OUTPUT_FORMAT = (Color.BLUE, ) BOLD_OUTPUT_FORMAT = (Color.BLUE, Attr.BOLD) ERROR_FORMAT = (Attr.BOLD, Color.RED)
-SIGNAL_DESCRIPTIONS = ( - ("RELOAD / HUP", "reload our torrc"), - ("SHUTDOWN / INT", "gracefully shut down, waiting 30 seconds if we're a relay"), - ("DUMP / USR1", "logs information about open connections and circuits"), - ("DEBUG / USR2", "makes us log at the DEBUG runlevel"), - ("HALT / TERM", "immediately shut down"), - ("CLEARDNSCACHE", "clears any cached DNS results"), - ("NEWNYM", "clears the DNS cache and uses new circuits for future connections") -) - HELP_OPTIONS = { 'HELP': ("/help [OPTION]", 'help.help'), 'EVENTS': ("/events [types]", 'help.events'), @@ -169,7 +159,8 @@ class ControlInterpretor(object):
self.received_events.append(event)
- def do_help(self, arg): + @uses_settings + def do_help(config, self, arg): """ Performs the '/help' operation, giving usage information for the given argument or a general summary if there wasn't one. @@ -252,7 +243,9 @@ class ControlInterpretor(object): elif arg == 'SIGNAL': # lists descriptions for all of the signals
- for signal, description in SIGNAL_DESCRIPTIONS: + descriptions = config.get('help.signal.options', {}) + + for signal, description in descriptions.items(): output += format('%-15s' % signal, *BOLD_OUTPUT_FORMAT) output += format(' - %s\n' % description, *OUTPUT_FORMAT) elif arg == 'SETEVENTS': diff --git a/stem/interpretor/settings.cfg b/stem/interpretor/settings.cfg index da33dbc..553cdae 100644 --- a/stem/interpretor/settings.cfg +++ b/stem/interpretor/settings.cfg @@ -171,6 +171,14 @@ help.protocolinfo |starting, like Tor's version and controller authentication. This can be done |before authenticating to the control port.
+help.signal.options RELOAD / HUP => reload our torrc +help.signal.options SHUTDOWN / INT => gracefully shut down, waiting 30 seconds if we're a relay +help.signal.options DUMP / USR1 => logs information about open connections and circuits +help.signal.options DEBUG / USR2 => makes us log at the DEBUG runlevel +help.signal.options HALT / TERM => immediately shut down +help.signal.options CLEARDNSCACHE => clears any cached DNS results +help.signal.options NEWNYM => clears the DNS cache and uses new circuits for future connections + # Autocompletion commands. We dynamically load more, such as GETINFO and # GETCONF options tor will recognize so this just includes other base commands.
diff --git a/stem/util/conf.py b/stem/util/conf.py index 3f753f0..420d4e6 100644 --- a/stem/util/conf.py +++ b/stem/util/conf.py @@ -157,7 +157,7 @@ Here's an expanation of what happened... +- get_value - provides the value for a given key as a string """
-import functools +import collections import threading
from stem.util import log @@ -268,11 +268,14 @@ def uses_settings(handle, path, lazy_load = True): config.set('settings_loaded', 'true')
def annotation(func): - if lazy_load and not config.get('settings_loaded', False): - config.load(path) - config.set('settings_loaded', 'true') + def wrapped(*args, **kwargs): + if lazy_load and not config.get('settings_loaded', False): + config.load(path) + config.set('settings_loaded', 'true')
- return functools.partial(func, config) + return func(config, *args, **kwargs) + + return wrapped
return annotation
@@ -679,7 +682,7 @@ class Config(object): elif isinstance(default, tuple): val = tuple(val) elif isinstance(default, dict): - valMap = {} + valMap = collections.OrderedDict() for entry in val: if "=>" in entry: entryKey, entryVal = entry.split("=>", 1)
tor-commits@lists.torproject.org