[tor-commits] [ooni-probe/master] Rewrite config.generatePcapFilename().

art at torproject.org art at torproject.org
Wed Mar 20 17:49:11 UTC 2013


commit 3b502c46a9f073671a0212b95c43cc74a14bf03d
Author: Isis Lovecruft <isis at torproject.org>
Date:   Mon Mar 11 22:56:14 2013 +0000

    Rewrite config.generatePcapFilename().
    
     * Fixes #8446.
     * Move attribute for storing sniffer_running state to the top of the file,
       where the other config attributes are.
---
 ooni/config.py |   39 ++++++++++++++++++++++++++-------------
 1 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/ooni/config.py b/ooni/config.py
index 74a1668..c40e569 100644
--- a/ooni/config.py
+++ b/ooni/config.py
@@ -34,6 +34,9 @@ sample_config_file = None
 # This is used to store the probes IP address obtained via Tor
 probe_ip = None
 
+# This is used to keep track of the state of the sniffer
+sniffer_running = None
+
 def get_root_path():
     this_directory = os.path.dirname(__file__)
     root = os.path.join(this_directory, '..')
@@ -90,18 +93,10 @@ def loadConfigFile():
 class TestFilenameNotSet(Exception):
     pass
 
-def generatePcapFilename():
-    if cmd_line_options['pcapfile']:
-        reports.pcap = cmd_line_options['pcapfile']
-    else:
-        if cmd_line_options['test']:
-            test_filename = os.path.basename(cmd_line_options['test'])
-        else:
-            test_filename = os.path.basename(cmd_line_options['testdeck'])
 
-        test_name = '.'.join(test_filename.split(".")[:-1])
-        frm_str = "report_%s_"+otime.timestamp()+".%s"
-        reports.pcap = frm_str % (test_name, "pcap")
+## This is the raw yaml configuration, and should not be publicly accessible,
+## i.e., you shouldn't need to touch it:
+_configuration = loadConfigFile()
 
 if not basic:
     # Here we make sure that we instance the config file attributes only once
@@ -114,5 +109,23 @@ if not resume_filename:
     except IOError as e:
         with open(resume_filename, 'w+') as f: pass
 
-# This is used to keep track of the state of the sniffer
-sniffer_running = None
+
+def generatePcapFilename(cmd_line_options=None):
+    if not cmd_line_options:
+        cmd_line_options = {}
+
+    if 'pcapfile' in cmd_line_options:
+        pcap_filename = cmd_line_options['pcapfile']
+    else:
+        if 'test' in cmd_line_options:
+            test_filename = os.path.basename(cmd_line_options['test'])
+        elif 'testdeck' in cmd_line_options:
+            test_filename = os.path.basename(cmd_line_options['testdeck'])
+        else:
+            test_filename = ''
+
+        test_name = '.'.join(test_filename.split(".")[:-1])
+        frm_str = "report_%s_" + otime.timestamp() + ".%s"
+        pcap_filename = frm_str % (test_name, "pcap")
+
+    return pcap_filename





More information about the tor-commits mailing list