[metrics-tasks/master] Add argument parsing, delete GeoIP.dat

commit 14c41dc65d51b3723e38c2e01f9d529145cfbdc4 Author: Sathyanarayanan Gunasekaran <gsathya.ceg@gmail.com> Date: Thu Jul 19 22:39:07 2012 +0530 Add argument parsing, delete GeoIP.dat Following options were added - -o, --output = Output filename -c, --consensus = Input consensus dir -g, --geoip = GeoIP database Removed GeoIP.dat from the git repo. --- task-6232/GeoIP.dat | Bin 1343110 -> 0 bytes task-6232/pyentropy.py | 32 ++++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/task-6232/GeoIP.dat b/task-6232/GeoIP.dat deleted file mode 100644 index 00510d5..0000000 Binary files a/task-6232/GeoIP.dat and /dev/null differ diff --git a/task-6232/pyentropy.py b/task-6232/pyentropy.py index ae28f05..1a981fe 100644 --- a/task-6232/pyentropy.py +++ b/task-6232/pyentropy.py @@ -1,5 +1,5 @@ """ -Usage - python pyentropy.py <consensus-dir> <output-file> +Usage - python pyentropy.py -h Output - A CSV file of the format (without newlines): <valid-after>, <entropy for all nodes>, @@ -17,7 +17,7 @@ import sys import math import os import pygeoip -import getopt +from optparse import OptionParser KEYS = ['r','s','v','w','p','m'] @@ -119,17 +119,25 @@ def run(file_name): str(entropy_country), str(max_entropy_country)]) -def usage(): - print "Usage - python pyentropy.py <consensus-dir> <output-file>" +def parse_args(): + usage = "Usage - python pyentropy.py [options]" + parser = OptionParser(usage) + + parser.add_option("-g", "--geoip", dest="geoip", default="GeoIP.dat", help="Input GeoIP database") + parser.add_option("-o", "--output", dest="output", default="entropy.csv", help="Output filename") + parser.add_option("-c", "--consensus", dest="consensus", default="in/consensus", help="Input consensus dir") + + (options, args) = parser.parse_args() + + return options if __name__ == "__main__": - if len(sys.argv) != 3: - usage() - sys.exit() - - gi = pygeoip.GeoIP(os.path.join(os.path.dirname(__file__), 'GeoIP.dat')) - with open(sys.argv[2], 'w') as f: - for file_name in os.listdir(sys.argv[1]): - string = run(os.path.join(sys.argv[1], file_name)) + + options = parse_args() + gi = pygeoip.GeoIP(options.geoip) + + with open(options.output, 'w') as f: + for file_name in os.listdir(options.consensus): + string = run(os.path.join(options.consensus, file_name)) if string: f.write("%s\n" % (string))
participants (1)
-
karsten@torproject.org