[tor-commits] [ooni-probe/master] Added annotations mechanism and improved the UX of the disable geoip flag

art at torproject.org art at torproject.org
Mon May 26 16:47:37 UTC 2014


commit 49f78b1294dc31555187351fa9a637dd71a80e84
Author: kudrom <kudrom at riseup.net>
Date:   Thu May 22 00:30:58 2014 +0200

    Added annotations mechanism and improved the UX of the disable geoip flag
---
 ooni/director.py |    7 ++++++-
 ooni/nettest.py  |   11 +++++++++++
 ooni/oonicli.py  |    4 +++-
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/ooni/director.py b/ooni/director.py
index 1bb3668..be5d551 100644
--- a/ooni/director.py
+++ b/ooni/director.py
@@ -127,7 +127,12 @@ class Director(object):
             log.msg("Connecting to Tor Control Port...")
             yield self.getTorState()
 
-        if not config.global_options['no-geoip']:
+        if config.global_options['no-geoip']:
+            annotations = config.global_options['annotations'].lower()
+            aux = map(lambda x: x in annotations, ["city", "country", "asn"])
+            if annotations is None or not all(aux):
+                log.msg("You should add annotations for the country, city and ASN")
+        else:
             yield config.probe_ip.lookup()
 
     @property
diff --git a/ooni/nettest.py b/ooni/nettest.py
index fb0bf95..16e65f5 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -613,6 +613,17 @@ class NetTestCase(object):
         This is the internal setup method to be overwritten by templates.
         """
         self.report = {}
+        if "annotations" in config.global_options and config.global_options["annotations"] is not None:
+            annotations = []
+            for annotation in config.global_options["annotations"].split(","):
+                pair = annotation.split(":")
+                if len(pair) == 2:
+                    key = pair[0].strip()
+                    value = pair[1].strip()
+                    annotations.append({key: value})
+                else:
+                    log.err("Invalid annotation: %s" % annotation)
+            self.report["annotations"] = annotations
         self.inputs = None
     
     def requirements(self):
diff --git a/ooni/oonicli.py b/ooni/oonicli.py
index 1e3e7ef..37f514e 100644
--- a/ooni/oonicli.py
+++ b/ooni/oonicli.py
@@ -49,7 +49,9 @@ class Options(usage.Options):
                      ["configfile", "f", None,
                          "Specify a path to the ooniprobe configuration file"],
                      ["datadir", "d", None,
-                         "Specify a path to the ooniprobe data directory"]
+                         "Specify a path to the ooniprobe data directory"],
+                     ["annotations", "a", None,
+                         "Annotate the report with a key:value[, key:value] format."]
                      ]
 
     compData = usage.Completions(





More information about the tor-commits mailing list