[metrics-tasks/master] task-6329: move OptionParser creation to its own function

commit 32c5f0be8774d2556a650d143f03b855e8ea17c5 Author: delber <delber@riseup.net> Date: Thu Aug 2 11:25:14 2012 +0000 task-6329: move OptionParser creation to its own function --- task-6329/tor-relays-stats.py | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-) diff --git a/task-6329/tor-relays-stats.py b/task-6329/tor-relays-stats.py index 9706d80..d966f66 100755 --- a/task-6329/tor-relays-stats.py +++ b/task-6329/tor-relays-stats.py @@ -249,14 +249,7 @@ class RelayStats(object): selection_weights[2] * 100.0, selection_weights[3] * 100.0, selection_weights[4] * 100.0) -def download_details_file(): - url = urllib.urlopen('https://onionoo.torproject.org/details?type=relay') - details_file = open("details.json", 'w') - details_file.write(url.read()) - url.close() - details_file.close() - -if '__main__' == __name__: +def create_option_parser(): parser = OptionParser() parser.add_option("-d", "--download", action="store_true", help="download details.json from Onionoo service") @@ -291,6 +284,17 @@ if '__main__' == __name__: group.add_option("-s", "--short", action="store_true", help="cut the length of the line output at 70 chars") parser.add_option_group(group) + return parser + +def download_details_file(): + url = urllib.urlopen('https://onionoo.torproject.org/details?type=relay') + details_file = open("details.json", 'w') + details_file.write(url.read()) + url.close() + details_file.close() + +if '__main__' == __name__: + parser = create_option_parser() (options, args) = parser.parse_args() if len(args) > 0: parser.error("Did not understand positional argument(s), use options instead.")
participants (1)
-
karsten@torproject.org