[tor-commits] [ooni-probe/master] Code cleanup and error handling

art at torproject.org art at torproject.org
Thu Mar 8 05:04:00 UTC 2012


commit 465786b5d693d66ecb206f81e69342610478e413
Author: Arturo Filastò <hellais at gmail.com>
Date:   Tue Mar 6 21:48:00 2012 -0800

    Code cleanup and error handling
---
 plugoo/assets.py  |    9 ++++++---
 plugoo/reports.py |   10 +++++++---
 plugoo/tests.py   |   20 +++++++-------------
 tests/template.py |    8 +++++---
 4 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/plugoo/assets.py b/plugoo/assets.py
index 5f93d1b..bb2cb78 100644
--- a/plugoo/assets.py
+++ b/plugoo/assets.py
@@ -1,5 +1,6 @@
 class Asset:
-    """This is an ooni-probe asset. It is a python
+    """
+    This is an ooni-probe asset. It is a python
     iterator object, allowing it to be efficiently looped.
     To create your own custom asset your should subclass this
     and override the next_asset method and the len method for
@@ -16,7 +17,8 @@ class Asset:
         return self
 
     def len(self):
-        """Returns the length of the asset
+        """
+        Returns the length of the asset
         """
         for i, l in enumerate(self.fh):
             pass
@@ -25,7 +27,8 @@ class Asset:
         return i + 1
 
     def next_asset(self):
-        """Return the next asset.
+        """
+        Return the next asset.
         """
         # XXX this is really written with my feet.
         #     clean me up please...
diff --git a/plugoo/reports.py b/plugoo/reports.py
index 5a9fb8b..90de498 100644
--- a/plugoo/reports.py
+++ b/plugoo/reports.py
@@ -87,7 +87,8 @@ class Report:
 
 
     def tcp_report(self, data):
-        """This connect to the specified tcp server
+        """
+        This connect to the specified tcp server
         and writes the data passed as argument.
         """
         host, port = self.tcp.split(":")
@@ -105,7 +106,9 @@ class Report:
 
 
     def scp_report(self, data, rfile=None, mode='a+'):
-        """Push data to the remote ssh server.
+        """
+        Push data to the remote ssh server.
+
         :rfile the remote filename to write
         :data the raw data content that should be written
         :mode in what mode the file should be created
@@ -160,7 +163,8 @@ class Report:
 
 
     def send_report(self, data, type):
-        """This sends the report using the
+        """
+        This sends the report using the
         specified type.
         """
         #print "Reporting %s to %s" % (data, type)
diff --git a/plugoo/tests.py b/plugoo/tests.py
index 24986b2..0e87874 100644
--- a/plugoo/tests.py
+++ b/plugoo/tests.py
@@ -26,17 +26,19 @@ class Test:
         pass
 
     def experiment(self, *a, **b):
-        """Override this method to write your own
+        """
+        Override this method to write your own
         Plugoo.
         """
         pass
 
     def load_assets(self, assets):
-        """Takes as input an array of Asset objects and
+        """
+        Takes as input an array of Asset objects and
         outputs an iterator for the loaded assets.
+
         example:
         assets = [hostlist, portlist, requestlist]
-
         """
         asset_count = len(assets)
         bigsize = 0
@@ -63,16 +65,6 @@ class Test:
             else:
                 yield (x)
 
-    def srun(self, assets=None, buffer=10, timeout=2):
-        self.logger.info("Starting %s", self.name)
-        if assets:
-            self.logger.debug("Running through tests")
-            for i, data in enumerate(self.load_assets(assets)):
-                args = {'data': data}
-                ret = self.experiment(**args)
-                print ret
-                self.report(ret)
-
     def run(self, assets=None, buffer=10, timeout=100000):
         self.logger.info("Starting %s", self.name)
         jobs = []
@@ -101,5 +93,7 @@ class Test:
                     self.report(job.value)
                     job.kill()
                 jobs = []
+        else:
+            self.logger.error("No Assets! Dying!")
 
 
diff --git a/tests/template.py b/tests/template.py
index 42952bf..f5f9d93 100644
--- a/tests/template.py
+++ b/tests/template.py
@@ -5,6 +5,8 @@
     This is a Test template, to be used when writing your
     own OONI probe Tests.
 """
+import os
+
 from plugoo.assets import Asset
 from plugoo.tests import Test
 
@@ -18,7 +20,7 @@ class TestTemplateAsset(Asset):
     and should be passed on instantiation to the test.
     """
     def __init__(self, file=None):
-        self = asset.__init__(self, file)
+        self = Asset.__init__(self, file)
 
 
 class TestTemplate(Test):
@@ -32,13 +34,13 @@ class TestTemplate(Test):
         on the "dirty" network and should be compared with the
         control.
         """
-        pass
+        return False
 
     def control(self):
         """
         Fill this up with the control related code.
         """
-        pass
+        return True
 
 def run(ooni):
     """





More information about the tor-commits mailing list