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

[tor-commits] [ooni-probe/master] Call .path on FilePath instead of using os.path.



commit c82275034f71f60276e58012dacf4c0293422c0f
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Fri May 9 22:42:21 2014 +0200

    Call .path on FilePath instead of using os.path.
---
 ooni/deck.py     |   26 ++++++++++++++------------
 ooni/oonicli.py  |    2 +-
 ooni/reporter.py |    6 +++---
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/ooni/deck.py b/ooni/deck.py
index 8a26d0c..ad90d03 100644
--- a/ooni/deck.py
+++ b/ooni/deck.py
@@ -21,7 +21,7 @@ class InputFile(object):
         cache_path = os.path.join(os.path.abspath(base_path), input_hash)
         self.cached_file = cache_path
         self.cached_descriptor = cache_path + '.desc'
-    
+
     @property
     def descriptorCached(self):
         if os.path.exists(self.cached_descriptor):
@@ -30,7 +30,7 @@ class InputFile(object):
                 self.load(descriptor)
             return True
         return False
-    
+
     @property
     def fileCached(self):
         if os.path.exists(self.cached_file):
@@ -52,7 +52,7 @@ class InputFile(object):
                 'date': self.date,
                 'description': self.description
             }, f)
-    
+
     def load(self, descriptor):
         self.name = descriptor['name']
         self.version = descriptor['version']
@@ -69,7 +69,7 @@ class InputFile(object):
 def nettest_to_path(path, allow_arbitrary_paths=False):
     """
     Takes as input either a path or a nettest name.
-    
+
     Args:
 
         allow_arbitrary_paths:
@@ -81,13 +81,15 @@ def nettest_to_path(path, allow_arbitrary_paths=False):
     """
     if allow_arbitrary_paths and os.path.exists(path):
         return path
-    elif FilePath(config.nettest_directory).preauthChild(path + '.py').exists():
-        return os.path.join(config.nettest_directory, path + '.py')
+
+    fp = FilePath(config.nettest_directory).preauthChild(path + '.py')
+    if fp.exists():
+        return fp.path
     else:
         raise e.NetTestNotFound(path)
 
 class Deck(InputFile):
-    def __init__(self, deck_hash=None, 
+    def __init__(self, deck_hash=None,
                  deckFile=None,
                  decks_directory=config.decks_directory):
         self.id = deck_hash
@@ -107,7 +109,7 @@ class Deck(InputFile):
     @property
     def cached_file(self):
         return os.path.join(self.decksDirectory, self.deckHash)
-   
+
     @property
     def cached_descriptor(self):
         return self.cached_file + '.desc'
@@ -162,7 +164,7 @@ class Deck(InputFile):
         if self.bouncer:
             log.msg("Looking up test helpers...")
             yield self.lookupTestHelpers()
-    
+
     @defer.inlineCallbacks
     def lookupTestHelpers(self):
         self.oonibclient.address = self.bouncer
@@ -178,7 +180,7 @@ class Deck(InputFile):
                 if th['test_class'].localOptions[th['option']]:
                     continue
                 required_test_helpers.append(th['name'])
-        
+
         if not required_test_helpers and not requires_collector:
             defer.returnValue(None)
 
@@ -212,7 +214,7 @@ class Deck(InputFile):
             if 'url' in i:
                 log.debug("Downloading %s" % i['url'])
                 self.oonibclient.address = i['address']
-                
+
                 try:
                     input_file = yield self.oonibclient.downloadInput(i['hash'])
                 except:
@@ -222,5 +224,5 @@ class Deck(InputFile):
                     input_file.verify()
                 except AssertionError:
                     raise e.UnableToLoadDeckInput, cached_path
-                
+
                 i['test_class'].localOptions[i['key']] = input_file.cached_file
diff --git a/ooni/oonicli.py b/ooni/oonicli.py
index 889b108..9bd1add 100644
--- a/ooni/oonicli.py
+++ b/ooni/oonicli.py
@@ -181,7 +181,7 @@ def runWithDirector(logging=True, start_tor=True):
     except Exception as e:
         log.err(e)
         sys.exit(5)
-    
+
     d = director.start(start_tor=start_tor)
 
     def setup_nettest(_):
diff --git a/ooni/reporter.py b/ooni/reporter.py
index a512891..273242e 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -171,7 +171,7 @@ class YAMLReporter(OReporter):
 
         if not os.path.isdir(report_destination):
             raise InvalidDestination
-        
+
         if not report_filename:
             report_filename = "report-" + \
                               test_details['test_name'] + "-" + \
@@ -301,7 +301,7 @@ class OONIBReporter(OReporter):
 
         from txsocksx.http import SOCKS5Agent
         from twisted.internet import reactor
-        
+
         if self.collectorAddress.startswith('httpo://'):
             self.collectorAddress = \
                     self.collectorAddress.replace('httpo://', 'http://')
@@ -369,7 +369,7 @@ class OONIBReporter(OReporter):
             log.err("Failed to parse collector response %s" % backend_response)
             log.exception(e)
             raise errors.OONIBReportCreationError
-       
+
         if response.code == 406:
             # XXX make this more strict
             log.err("The specified input or nettests cannot be submitted to this collector.")



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