[tor-commits] [ooni-probe/master] Use vulture to find and delete some dead code.

art at torproject.org art at torproject.org
Mon Aug 18 12:13:57 UTC 2014


commit eb417483e4bf8772d9da71c71ecfd30404425320
Author: Arturo Filastò <art at fuffa.org>
Date:   Mon Aug 18 13:57:11 2014 +0200

    Use vulture to find and delete some dead code.
---
 ooni/deck.py         |    1 -
 ooni/nettest.py      |   18 -------------
 ooni/oonibclient.py  |   34 ++-----------------------
 ooni/otime.py        |   21 ----------------
 ooni/ratelimiting.py |   68 --------------------------------------------------
 ooni/settings.py     |    7 ------
 6 files changed, 2 insertions(+), 147 deletions(-)

diff --git a/ooni/deck.py b/ooni/deck.py
index 19c7fd5..3f64064 100644
--- a/ooni/deck.py
+++ b/ooni/deck.py
@@ -96,7 +96,6 @@ class Deck(InputFile):
         self.bouncer = ''
         self.netTestLoaders = []
         self.inputs = []
-        self.testHelpers = {}
 
         self.oonibclient = OONIBClient(self.bouncer)
 
diff --git a/ooni/nettest.py b/ooni/nettest.py
index 54a7d28..0d5c0f2 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -23,24 +23,6 @@ class NoTestCasesFound(Exception):
     pass
 
 
-def get_test_methods(item, method_prefix="test_"):
-    """
-    Look for test_ methods in subclasses of NetTestCase
-    """
-    test_cases = []
-    try:
-        assert issubclass(item, NetTestCase)
-        methods = reflect.prefixedMethodNames(item, method_prefix)
-        test_methods = []
-        for method in methods:
-            test_methods.append(method_prefix + method)
-        if test_methods:
-            test_cases.append((item, test_methods))
-    except (TypeError, AssertionError):
-        pass
-    return test_cases
-
-
 def getTestClassFromFile(net_test_file):
     """
     Will return the first class that is an instance of NetTestCase.
diff --git a/ooni/oonibclient.py b/ooni/oonibclient.py
index 7676b91..7dcc0af 100644
--- a/ooni/oonibclient.py
+++ b/ooni/oonibclient.py
@@ -13,33 +13,6 @@ from ooni.utils import log
 from ooni.utils.net import BodyReceiver, StringProducer, Downloader
 from ooni.utils.trueheaders import TrueHeadersSOCKS5Agent
 
-class Collector(object):
-    def __init__(self, address):
-        self.address = address
-
-        self.nettest_policy = None
-        self.input_policy = None
-    
-    @defer.inlineCallbacks
-    def loadPolicy(self):
-        # XXX implement caching of policies
-        oonibclient = OONIBClient(self.address)
-        log.msg("Looking up nettest policy for %s" % self.address)
-        self.nettest_policy = yield oonibclient.getNettestPolicy()
-        log.msg("Looking up input policy for %s" % self.address)
-        self.input_policy = yield oonibclient.getInputPolicy()
-
-    def validateInput(self, input_hash):
-        for i in self.input_policy:
-            if i['id'] == input_hash:
-                return True
-        return False
-
-    def validateNettest(self, nettest_name):
-        for i in self.nettest_policy:
-            if nettest_name == i['name']:
-                return True
-        return False
 
 class OONIBClient(object):
     retries = 3
@@ -99,7 +72,7 @@ class OONIBClient(object):
         bodyProducer = None
         if query:
             bodyProducer = StringProducer(json.dumps(query))
-        
+
         def genReceiver(finished, content_length):
             def process_response(s):
                 # If empty string then don't parse it.
@@ -124,9 +97,6 @@ class OONIBClient(object):
             return Downloader(download_path, finished, content_length)
 
         return self._request('GET', urn, genReceiver)
-    
-    def getNettestPolicy(self):
-        pass
 
     def getInput(self, input_hash):
         from ooni.deck import InputFile
@@ -239,7 +209,7 @@ class OONIBClient(object):
     def lookupTestHelpers(self, test_helper_names):
         try:
 
-            test_helper = yield self.queryBackend('POST', '/bouncer', 
+            test_helper = yield self.queryBackend('POST', '/bouncer',
                             query={'test-helpers': test_helper_names})
         except Exception, exc:
             log.exception(exc)
diff --git a/ooni/otime.py b/ooni/otime.py
index 0446d4d..21dab42 100644
--- a/ooni/otime.py
+++ b/ooni/otime.py
@@ -1,24 +1,6 @@
 import time
 from datetime import datetime
 
-def utcDateNow():
-    """
-    Returns the datetime object of the current UTC time.
-    """
-    return datetime.utcnow()
-
-def utcTimeNow():
-    """
-    Returns seconds since epoch in UTC time, it's of type float.
-    """
-    return time.mktime(time.gmtime())
-
-def dateToTime(date):
-    """
-    Takes as input a datetime object and outputs the seconds since epoch.
-    """
-    return time.mktime(date.timetuple())
-
 def prettyDateNow():
     """
     Returns a good looking string for the local time.
@@ -31,9 +13,6 @@ def utcPrettyDateNow():
     """
     return datetime.utcnow().ctime()
 
-def timeToPrettyDate(time_val):
-    return time.ctime(time_val)
-
 class InvalidTimestampFormat(Exception):
     pass
 
diff --git a/ooni/ratelimiting.py b/ooni/ratelimiting.py
deleted file mode 100644
index 986cf82..0000000
--- a/ooni/ratelimiting.py
+++ /dev/null
@@ -1,68 +0,0 @@
-class RateLimiter(object):
-    """
-    The abstract class that imposes limits over how measurements are scheduled,
-    how retries are handled and when we should be giving up on a certain
-    measurement.
-    """
-    @property
-    def timeout(self):
-        """
-        After what timeout a certain test should be considered to have failed
-        and attempt a retry if the maximum retry has not been reached.
-        """
-        raise NotImplemented
-
-    @property
-    def maxTimeout(self):
-        """
-        This is the maximum value that timeout can reach.
-        """
-        raise NotImplemented
-
-    @property
-    def concurrency(self):
-        """
-        How many concurrent requests should happen at the same time.
-        """
-        raise NotImplemented
-
-    def timedOut(self, measurement):
-        raise NotImplemented
-
-    def completed(self, measurement):
-        raise NotImplemented
-
-    def failed(self, measurement):
-        raise NotImplemented
-
-class StaticRateLimiter(RateLimiter):
-    """
-    This is a static ratelimiter that returns constant values.
-    """
-    @property
-    def timeout(self):
-        return 10
-
-    @property
-    def maxTimeout(self):
-        return 5 * 60
-
-    @property
-    def concurrency(self):
-        return 10
-
-    def timedOut(self, measurement):
-        pass
-
-    def completed(self, measurement):
-        pass
-
-    def failed(self, measurement, failure):
-        pass
-
-class TimeoutRateLimiter(RateLimiter):
-    pass
-
-class BandwidthRateLimiter(RateLimiter):
-    pass
-
diff --git a/ooni/settings.py b/ooni/settings.py
index 08150f0..a5b6468 100644
--- a/ooni/settings.py
+++ b/ooni/settings.py
@@ -26,8 +26,6 @@ class OConfig(object):
         self.tor_state = None
         # This is used to store the probes IP address obtained via Tor
         self.probe_ip = geoip.ProbeIP()
-        # This is used to keep track of the state of the sniffer
-        self.sniffer_running = None
         self.logging = True
         self.basic = Storage()
         self.advanced = Storage()
@@ -164,9 +162,4 @@ class OConfig(object):
 
             self.log_incoherences(incoherent)
 
-    def generate_pcap_filename(self, testDetails):
-        test_name, start_time = testDetails['test_name'], testDetails['start_time']
-        start_time = otime.epochToTimestamp(start_time)
-        return "report-%s-%s.%s" % (test_name, start_time, "pcap")
-
 config = OConfig()





More information about the tor-commits mailing list