[tor-commits] [ooni-probe/master] Fix oonireport tool to actually support uploading of reports and status.

art at torproject.org art at torproject.org
Sat Aug 9 23:04:25 UTC 2014


commit d1c368d6cac955a42029b4075530ec28dfc4e861
Author: Arturo Filastò <art at fuffa.org>
Date:   Thu Aug 7 19:15:00 2014 +0200

    Fix oonireport tool to actually support uploading of reports and status.
---
 ooni/report/cli.py  |    7 +++++--
 ooni/report/tool.py |   11 +++++++++--
 ooni/reporter.py    |   37 +++++++++++++++++++++++++++++--------
 3 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/ooni/report/cli.py b/ooni/report/cli.py
index eee5c53..6b611d5 100644
--- a/ooni/report/cli.py
+++ b/ooni/report/cli.py
@@ -33,13 +33,16 @@ class Options(usage.Options):
         if self['command'] == "upload":
             try:
                 self['report_file'] = args[1]
-            except KeyError:
+            except IndexError:
                 self['report_file'] = None
 
 
 def parse_options():
     options = Options()
-    options.parseOptions()
+    try:
+        options.parseOptions()
+    except Exception as exc:
+        print exc
     return dict(options)
 
 
diff --git a/ooni/report/tool.py b/ooni/report/tool.py
index f3dd430..b8f60b0 100644
--- a/ooni/report/tool.py
+++ b/ooni/report/tool.py
@@ -28,9 +28,11 @@ def upload(report_file, collector=None, bouncer=None):
     if collector is None:
         try:
             collector = report_log[report_file]['collector']
+            if collector is None:
+                raise KeyError
         except KeyError:
             raise Exception(
-                "No collector or bouncer specified and report file not in log."
+                "No collector or bouncer specified and collector not in report log."
             )
 
     oonib_reporter = OONIBReporter(report.header, collector)
@@ -47,8 +49,13 @@ def upload(report_file, collector=None, bouncer=None):
 
 @defer.inlineCallbacks
 def upload_all(collector=None, bouncer=None):
+    print "Running upload all..."
     for report_file, value in oonib_report_log.reports_to_upload:
-        yield upload(report_file, collector, bouncer)
+        print report_file
+        try:
+            yield upload(report_file, collector, bouncer)
+        except Exception as exc:
+            print exc
 
 
 def print_report(report_file, value):
diff --git a/ooni/reporter.py b/ooni/reporter.py
index 88a9dec..f0f8822 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -409,24 +409,45 @@ class OONIBReportLog(object):
     def __init__(self, file_name=config.report_log_file):
         self.file_name = file_name
         self.create_report_log()
-        self._reports_incomplete = []
-        self._reports_in_progress = []
-        self._reports_to_upload = []
 
-    def update_stored_reports(self):
-        pass
+    def get_report_log(self):
+        with open(self.file_name) as f:
+            report_log = yaml.safe_load(f)
+        return report_log
 
     @property
     def reports_incomplete(self):
-        pass
+        reports = []
+        report_log = self.get_report_log()
+        for report_file, value in report_log.items():
+            if value['status'] in ('created'):
+                try:
+                    os.kill(value['pid'])
+                except:
+                    reports.append((report_file, value))
+        return reports
 
     @property
     def reports_in_progress(self):
-        pass
+        reports = []
+        report_log = self.get_report_log()
+        for report_file, value in report_log.items():
+            if value['status'] in ('created'):
+                try:
+                    os.kill(value['pid'])
+                    reports.append((report_file, value))
+                except:
+                    pass
+        return reports
 
     @property
     def reports_to_upload(self):
-        pass
+        reports = []
+        report_log = self.get_report_log()
+        for report_file, value in report_log.items():
+            if value['status'] in ('creation-failed', 'not-created'):
+                reports.append((report_file, value))
+        return reports
 
     def run(self, f, *arg, **kw):
         lock = defer.DeferredFilesystemLock(self.file_name + '.lock')





More information about the tor-commits mailing list