[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Re-organize module structure



commit 83b169fbae5174255d17939464b29782f81d6de8
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Sat Jan 12 14:56:48 2013 +0100

    Re-organize module structure
---
 ooni/director.py     |   87 ++++++++++++++++++++++++++++++++++++++++++++++++++
 ooni/managers.py     |   77 --------------------------------------------
 ooni/measurements.py |   77 --------------------------------------------
 ooni/nettest.py      |   61 +++++++++++++++++++++++++++++++++++
 4 files changed, 148 insertions(+), 154 deletions(-)

diff --git a/ooni/director.py b/ooni/director.py
new file mode 100644
index 0000000..cf23269
--- /dev/null
+++ b/ooni/director.py
@@ -0,0 +1,87 @@
+from ooni.managers import ReportingEntryManager, MeasurementsManager
+from ooni.nettest import NetTest
+
+class Director(object):
+    """
+    Singleton object responsible for coordinating the Measurements Manager and the
+    Reporting Manager.
+
+    How this all looks like is as follows:
+
+    +------------------------------------------------+
+    |                   Director                     |<--+
+    +------------------------------------------------+   |
+        ^                                ^               |
+        |        Measurement             |               |
+    +---------+  [---------]    +--------------------+   |
+    |         |                 | MeasurementManager |   |
+    | NetTest |  [---------]    +--------------------+   |
+    |         |                 | [----------------] |   |
+    +---------+  [---------]    | [----------------] |   |
+        |                       | [----------------] |   |
+        |                       +--------------------+   |
+        v                                                |
+    +---------+   ReportEntry                            |
+    |         |   [---------]    +--------------------+  |
+    |  Report |                  | ReportEntryManager |  |
+    |         |   [---------]    +--------------------+  |
+    +---------+                  | [----------------] |  |
+                  [---------]    | [----------------] |--
+                                 | [----------------] |
+                                 +--------------------+
+
+    [------------] are Tasks
+
+    +------+
+    |      |  are TaskManagers
+    +------+
+    |      |
+    +------+
+
+    +------+
+    |      |  are general purpose objects
+    +------+
+
+    """
+    _scheduledTests = 0
+
+    def __init__(self):
+        self.reporters = reporters
+
+        self.netTests = []
+
+        self.measurementsManager = MeasurementsManager(manager=self,
+                netTests=self.netTests)
+        self.measurementsManager.director = self
+
+        self.reportEntryManager = ReportingEntryManager()
+        self.reportEntryManager.director = self
+
+    def startTest(self, net_test_file, inputs, options):
+        """
+        Create the Report for the NetTest and start the report NetTest.
+        """
+        report = Report()
+        report.reportEntryManager = self.reportEntryManager
+
+        net_test = NetTest(net_test_file, inputs, options, report)
+        net_test.director = self
+
+        self.measurementsManager.schedule(net_test.generateMeasurements())
+
+    def measurementTimedOut(self, measurement):
+        """
+        This gets called every time a measurement times out independenty from
+        the fact that it gets re-scheduled or not.
+        """
+        pass
+
+    def measurementFailed(self, failure, measurement):
+        pass
+
+    def writeFailure(self, measurement, failure):
+        pass
+
+    def writeReport(self, report_write_task):
+        self.reportingManager.write(report_write_task)
+
diff --git a/ooni/managers.py b/ooni/managers.py
index c4b4d2a..f6d4c74 100644
--- a/ooni/managers.py
+++ b/ooni/managers.py
@@ -199,80 +199,3 @@ class ReportEntryManager(object):
     def failed(self, failure, measurement):
         pass
 
-class Director(object):
-    """
-    Singleton object responsible for coordinating the Measurements Manager and the
-    Reporting Manager.
-
-    How this all looks like is as follows:
-
-    +------------------------------------------------+
-    |                   Director                     |<--+
-    +------------------------------------------------+   |
-        ^                                ^               |
-        |        Measurement             |               |
-    +---------+  [---------]    +--------------------+   |
-    |         |                 | MeasurementManager |   |
-    | NetTest |  [---------]    +--------------------+   |
-    |         |                 | [----------------] |   |
-    +---------+  [---------]    | [----------------] |   |
-        |                       | [----------------] |   |
-        |                       +--------------------+   |
-        v                                                |
-    +---------+   ReportEntry                            |
-    |         |   [---------]    +--------------------+  |
-    |  Report |                  | ReportEntryManager |  |
-    |         |   [---------]    +--------------------+  |
-    +---------+                  | [----------------] |  |
-                  [---------]    | [----------------] |--
-                                 | [----------------] |
-                                 +--------------------+
-
-    [------------] are Tasks
-
-    +------+
-    |      |  are TaskManagers
-    +------+
-    |      |
-    +------+
-
-    +------+
-    |      |  are general purpose objects
-    +------+
-
-    """
-    _scheduledTests = 0
-
-    def __init__(self):
-        self.reporters = reporters
-
-        self.netTests = []
-
-        self.measurementsManager = MeasurementsManager(manager=self,
-                netTests=self.netTests)
-        self.measurementsManager.director = self
-
-        self.reportingManager = ReportingEntryManager()
-        self.reportingManager.director = self
-
-    def startTest(self, net_test_file, inputs, options):
-        """
-        Create the Report for the NetTest and start the report NetTest.
-        """
-        report = Report()
-        net_test = NetTest(net_test_file, inputs, options, report)
-        net_test.director = self
-
-    def measurementTimedOut(self, measurement):
-        """
-        This gets called every time a measurement times out independenty from
-        the fact that it gets re-scheduled or not.
-        """
-        pass
-
-    def measurementFailed(self, measurement, failure):
-        pass
-
-    def writeFailure(self, measurement, failure):
-        pass
-
diff --git a/ooni/measurements.py b/ooni/measurements.py
deleted file mode 100644
index 0ef8ef6..0000000
--- a/ooni/measurements.py
+++ /dev/null
@@ -1,77 +0,0 @@
-from .tasks import TaskWithTimeout
-
-class NetTest(object):
-    director = None
-
-    def __init__(self, net_test_file, inputs, options, report):
-        """
-        net_test_file:
-            is a file object containing the test to be run.
-
-        inputs:
-            is a generator containing the inputs to the net test.
-
-        options:
-            is a dict containing the opitions to be passed to the net test.
-        """
-        self.test_cases = self.loadNetTestFile(net_test_file)
-        self.inputs = inputs
-        self.options = options
-
-    def loadNetTestFile(self, net_test_file):
-        """
-        Creates all the necessary test_cases (a list of tuples containing the
-        NetTestCase (test_class, test_method))
-
-        example:
-            [(test_classA, test_method1),
-            (test_classA, test_method2),
-            (test_classA, test_method3),
-            (test_classA, test_method4),
-            (test_classA, test_method5),
-
-            (test_classB, test_method1),
-            (test_classB, test_method2)]
-
-        Note: the inputs must be valid for test_classA and test_classB.
-
-        net_test_file:
-            is a file like object that will be used to generate the test_cases.
-        """
-        # XXX Not implemented
-        raise NotImplemented
-
-    def timedOut(self, measurement):
-        """
-        This gets called when a measurement has timed out. This may or may not
-        trigger a retry inside of MeasurementsTracker.
-        """
-        self.director.measurementTimedOut(measurement)
-
-    def failed(self, measurement, failure):
-        """
-        This gets called when a measurement has failed in the sense that all
-        the retries have failed at successfully running the test.
-        This means that it's a definitive failure and we will no longer make
-        any attempts at re-running the measurement.
-        """
-        self.director.measurementFailed(measurement, failure)
-
-    def succeeded(self, measurement):
-        """
-        This gets called when a measurement has failed.
-        """
-        self.report.write(measurement)
-
-    def generateMeasurements(self):
-        """
-        This is a generator that yields measurements and sets their timeout
-        value and their netTest attribute.
-        """
-        for test_input in self.inputs:
-            for test_class, test_method in self.test_cases:
-                measurement = Measurement(test_class, test_method, test_input)
-                measurement.netTest = self
-                measurement.timeout = self.rateLimiter.timeout
-                yield measurement
-
diff --git a/ooni/nettest.py b/ooni/nettest.py
index 538fcf9..2b1c550 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -10,6 +10,67 @@ from twisted.python import usage
 from ooni.errors import handleAllFailures, failureToString
 from ooni.utils import log
 
+class NetTest(object):
+    director = None
+
+    def __init__(self, net_test_file, inputs, options, report):
+        """
+        The NetTest object is responsible for keeping a reference to the
+        Report and the loading of NetTestCases from test files.
+
+        net_test_file:
+            is a file object containing the test to be run.
+
+        inputs:
+            is a generator containing the inputs to the net test.
+
+        options:
+            is a dict containing the opitions to be passed to the net test.
+        """
+        self.test_cases = self.loadNetTestFile(net_test_file)
+        self.inputs = inputs
+        self.options = options
+
+    def loadNetTestFile(self, net_test_file):
+        """
+        Creates all the necessary test_cases (a list of tuples containing the
+        NetTestCase (test_class, test_method))
+
+        example:
+            [(test_classA, test_method1),
+            (test_classA, test_method2),
+            (test_classA, test_method3),
+            (test_classA, test_method4),
+            (test_classA, test_method5),
+
+            (test_classB, test_method1),
+            (test_classB, test_method2)]
+
+        Note: the inputs must be valid for test_classA and test_classB.
+
+        net_test_file:
+            is a file like object that will be used to generate the test_cases.
+        """
+        # XXX Not implemented
+        raise NotImplemented
+
+    def succeeded(self, measurement):
+        """
+        This gets called when a measurement has failed.
+        """
+        self.report.write(measurement)
+
+    def generateMeasurements(self):
+        """
+        This is a generator that yields measurements and sets their timeout
+        value and their netTest attribute.
+        """
+        for test_input in self.inputs:
+            for test_class, test_method in self.test_cases:
+                measurement = Measurement(test_class, test_method, test_input)
+                measurement.netTest = self
+                measurement.timeout = self.rateLimiter.timeout
+                yield measurement
 
 class NoPostProcessor(Exception):
     pass



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits