[tor-commits] [arm/master] Using format() for user output
atagar at torproject.org
atagar at torproject.org
Sun Sep 15 22:29:21 UTC 2013
commit 5a2bf18ead7eff1f518a3f2b25e1af157a7c377a
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Sep 14 20:43:12 2013 -0700
Using format() for user output
Aaron Johnson introduced me to str's format() method, and on reflection there's
a few situations where it makes our code quite a bit nicer. Making it so...
---
arm/settings.cfg | 18 +++++++++---------
arm/starter.py | 19 ++++++++++++++-----
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/arm/settings.cfg b/arm/settings.cfg
index 368d418..dc3a44d 100644
--- a/arm/settings.cfg
+++ b/arm/settings.cfg
@@ -2,15 +2,15 @@ msg.help
|Usage arm [OPTION]
|Terminal status monitor for Tor relays.
|
-| -i, --interface [ADDRESS:]PORT change control interface from %s:%i
+| -i, --interface [ADDRESS:]PORT change control interface from {address}:{port}
| -s, --socket SOCKET_PATH attach using unix domain socket if present,
-| SOCKET_PATH defaults to: %s
+| SOCKET_PATH defaults to: {socket}
| -c, --config CONFIG_PATH loaded configuration options, CONFIG_PATH
-| defaults to: %s
-| -d, --debug writes all arm logs to %s
+| defaults to: {config}
+| -d, --debug writes all arm logs to {debug_path}
| -b, --blind disable connection lookups
-| -e, --event EVENT_FLAGS event types in message log (default: %s)
-|%s
+| -e, --event EVENT_FLAGS event types in message log (default: {events})
+|{event_flags}
| -v, --version provides version information
| -h, --help presents this help
|
@@ -29,7 +29,7 @@ msg.wrong_socket_type
msg.uncrcognized_auth_type
|Tor is using a type of authentication we do not recognize...
|
-| %s
+| {auth_methods}
|
|Please check that arm is up to date and if there is an existing issue on
|'http://bugs.torproject.org'. If there isn't one then let us know!
@@ -43,8 +43,8 @@ msg.missing_password_bug
msg.unreadable_cookie_file
|We were unable to read tor's authentication cookie...
|
-| Path: %s
-| Issue: %s
+| Path: {path}
+| Issue: {issue}
# Important tor configuration options (shown by default)
config.important BandwidthRate
diff --git a/arm/starter.py b/arm/starter.py
index f84937d..efcda91 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -2,8 +2,8 @@
"""
Command line application for monitoring Tor relays, providing real time status
-information. This is the starter for the application, handling and validating
-command line parameters.
+information. This starts the applicatin, getting a tor connection and parsing
+arguments.
"""
import collections
@@ -205,7 +205,7 @@ def _authenticate(controller, password):
else:
raise ValueError(CONFIG['msg.wrong_socket_type'])
except stem.connection.UnrecognizedAuthMethods as exc:
- raise ValueError(CONFIG['msg.uncrcognized_auth_type'] % ', '.join(exc.unknown_auth_methods))
+ raise ValueError(CONFIG['msg.uncrcognized_auth_type'].format(auth_methods = ', '.join(exc.unknown_auth_methods)))
except stem.connection.IncorrectPassword:
raise ValueError("Incorrect password")
except stem.connection.MissingPassword:
@@ -215,7 +215,7 @@ def _authenticate(controller, password):
password = getpass.getpass("Tor controller password: ")
return _authenticate(controller, password)
except stem.connection.UnreadableCookieFile as exc:
- raise ValueError(CONFIG['msg.unreadable_cookie_file'] % (exc.cookie_path, str(exc)))
+ raise ValueError(CONFIG['msg.unreadable_cookie_file'].format(path = exc.cookie_path, issue = str(exc)))
except stem.connection.AuthenticationFailure as exc:
raise ValueError("Unable to authenticate: %s" % exc)
@@ -287,7 +287,16 @@ def main():
sys.exit()
if args.print_help:
- print CONFIG['msg.help'] % (ARGS['control_address'], ARGS['control_port'], ARGS['control_socket'], ARGS['config'], LOG_DUMP_PATH, ARGS['logged_events'], arm.logPanel.EVENT_LISTING)
+ print CONFIG['msg.help'].format(
+ address = ARGS['control_address'],
+ port = ARGS['control_port'],
+ socket = ARGS['control_socket'],
+ config = ARGS['config'],
+ debug_path = LOG_DUMP_PATH,
+ events = ARGS['logged_events'],
+ event_flags = arm.logPanel.EVENT_LISTING
+ )
+
sys.exit()
config.set("startup.blindModeEnabled", str(args.blind))
More information about the tor-commits
mailing list