[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Fixes reportfile creation when the reportfile name is not defined
commit b7bd271e7cda81bb8494f27f644b75bcc786bddf
Author: Flavio Amieiro <amieiro.flavio@xxxxxxxxx>
Date: Fri Dec 7 18:18:36 2012 -0200
Fixes reportfile creation when the reportfile name is not defined
My last commit (2becc29d40f8) broke the reporting when the filename wasn't
defined. I took the filename creation logic from
ooni/config.py@generateReportFilenames to use when the command line (or test
deck) does not define a name for the report file.
If this is the right way to go, this code probably needs a cleanup, at least to
avoid duplication of this code.
---
ooni/reporter.py | 24 ++++++++++++++++++------
1 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/ooni/reporter.py b/ooni/reporter.py
index f365a6a..6a8fd3f 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -194,13 +194,25 @@ class YAMLReporter(OReporter):
These are useful functions for reporting to YAML format.
"""
def __init__(self, cmd_line_options):
- if os.path.exists(cmd_line_options['reportfile']):
- log.msg("Report already exists with filename %s" % cmd_line_options['reportfile'])
- log.msg("Renaming it to %s" % cmd_line_options['reportfile']+'.old')
- os.rename(cmd_line_options['reportfile'], cmd_line_options['reportfile']+'.old')
+ if cmd_line_options['reportfile'] is None:
+ 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"
+ reportfile = frm_str % (test_name, "yamloo")
+ else:
+ reportfile = cmd_line_options['reportfile']
+
+ if os.path.exists(reportfile):
+ log.msg("Report already exists with filename %s" % reportfile)
+ log.msg("Renaming it to %s" % reportfile+'.old')
+ os.rename(reportfile, reportfile+'.old')
- log.debug("Creating %s" % cmd_line_options['reportfile'])
- self._stream = open(cmd_line_options['reportfile'], 'w+')
+ log.debug("Creating %s" % reportfile)
+ self._stream = open(reportfile, 'w+')
OReporter.__init__(self, cmd_line_options)
def _writeln(self, line):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits