[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [compass/master] Added support for using a custom named datafile.
commit 809e93455d5f80b213d8b2a4fbcf585422f4ecb6
Author: Chris Wacek <cwacek@xxxxxxxxxxxxxxxxx>
Date: Tue Jan 15 15:40:41 2013 -0500
Added support for using a custom named datafile.
---
app.py | 6 +++++-
compass.py | 13 ++++++++-----
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/app.py b/app.py
index 45217a6..d68c5b9 100644
--- a/app.py
+++ b/app.py
@@ -120,7 +120,11 @@ def index():
def json_result():
options = Opt(dict(request.args.items()))
- stats = compass.RelayStats(options)
+ if "TESTING_DATAFILE" in app.config and "TESTING" in app.config:
+ stats = compass.RelayStats(options,app.config['TESTING_DATAFILE'])
+ else:
+ stats = compass.RelayStats(options)
+
results = stats.select_relays(stats.relays, options)
relays = stats.sort_and_reduce(results,
diff --git a/compass.py b/compass.py
index 1f8d171..18e7c8c 100755
--- a/compass.py
+++ b/compass.py
@@ -184,17 +184,18 @@ class InverseFilter(BaseFilter):
return inverse_relays
class RelayStats(object):
- def __init__(self, options):
+ def __init__(self, options, custom_datafile="details.json"):
self._data = None
self._filters = self._create_filters(options)
self._get_group = self._get_group_function(options)
self._relays = None
+ self._datafile_name = custom_datafile
@property
def data(self):
- if not self._data:
- self._data = json.load(file(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'details.json')))
- return self._data
+ if not self._data:
+ self._data = json.load(file(os.path.join(os.path.dirname(os.path.abspath(__file__)), self._datafile_name)))
+ return self._data
@property
def relays(self):
@@ -495,6 +496,8 @@ def create_option_parser():
help="cut the length of the line output at 70 chars")
group.add_option("-j", "--json", action="store_true",
help="output in JSON rather than human-readable format")
+ group.add_option("--datafile", default="details.json",
+ help="use a custom datafile (Default: 'details.json')")
parser.add_option_group(group)
return parser
@@ -551,7 +554,7 @@ if '__main__' == __name__:
if not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'details.json')):
parser.error("Did not find details.json. Re-run with --download.")
- stats = RelayStats(options)
+ stats = RelayStats(options,options.datafile)
results = stats.select_relays(stats.relays,options)
sorted_results = stats.sort_and_reduce(results,options)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits