[tor-commits] [ooni-probe/master] Fixes pcapfile name generation and concentrates it where it's needed
art at torproject.org
art at torproject.org
Sat Dec 8 11:26:53 UTC 2012
commit 452c9e7908beae3bf175a8e80139dab18e4005a6
Author: Flavio Amieiro <amieiro.flavio at gmail.com>
Date: Fri Dec 7 23:27:47 2012 -0200
Fixes pcapfile name generation and concentrates it where it's needed
---
ooni/config.py | 21 ++++++++++++---------
ooni/oonicli.py | 2 +-
ooni/runner.py | 18 +++++++++---------
3 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/ooni/config.py b/ooni/config.py
index 8ab129d..74a1668 100644
--- a/ooni/config.py
+++ b/ooni/config.py
@@ -90,15 +90,18 @@ def loadConfigFile():
class TestFilenameNotSet(Exception):
pass
-def generateReportFilenames():
- try:
- test_filename = os.path.basename(cmd_line_options['test'])
- except IndexError:
- raise TestFilenameNotSet
-
- test_name = '.'.join(test_filename.split(".")[:-1])
- frm_str = "report_%s_"+otime.timestamp()+".%s"
- reports.pcap = frm_str % (test_name, "pcap")
+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")
if not basic:
# Here we make sure that we instance the config file attributes only once
diff --git a/ooni/oonicli.py b/ooni/oonicli.py
index 2df8195..23c4dd5 100644
--- a/ooni/oonicli.py
+++ b/ooni/oonicli.py
@@ -128,7 +128,7 @@ def run():
if config.privacy.includepcap:
log.msg("Starting")
- runner.startSniffing()
+ runner.startSniffing(cmd_line_options)
resume = cmd_line_options['resume']
diff --git a/ooni/runner.py b/ooni/runner.py
index d978ec2..4483ce4 100644
--- a/ooni/runner.py
+++ b/ooni/runner.py
@@ -521,7 +521,7 @@ def startTor():
d.addErrback(setup_failed)
return d
-def startSniffing():
+def startSniffing(cmd_line_options):
""" Start sniffing with Scapy. Exits if required privileges (root) are not
available.
"""
@@ -536,6 +536,14 @@ def startSniffing():
print "Starting sniffer"
config.scapyFactory = ScapyFactory(config.advanced.interface)
+ if not config.reports.pcap:
+ config.cmd_line_options = cmd_line_options
+ config.generatePcapFilename()
+ if os.path.exists(config.reports.pcap):
+ print "Report PCAP already exists with filename %s" % config.reports.pcap
+ print "Renaming it to %s" % config.reports.pcap+".old"
+ os.rename(config.reports.pcap, config.reports.pcap+".old")
+
sniffer = ScapySniffer(config.reports.pcap)
config.scapyFactory.registerProtocol(sniffer)
@@ -544,14 +552,6 @@ def loadTest(cmd_line_options):
Takes care of parsing test command line arguments and loading their
options.
"""
- config.cmd_line_options = cmd_line_options
- config.generateReportFilenames()
-
- if os.path.exists(config.reports.pcap):
- print "Report PCAP already exists with filename %s" % config.reports.pcap
- print "Renaming it to %s" % config.reports.pcap+".old"
- os.rename(config.reports.pcap, config.reports.pcap+".old")
-
classes = findTestClassesFromFile(cmd_line_options['test'])
test_cases, options = loadTestsAndOptions(classes, cmd_line_options)
More information about the tor-commits
mailing list