[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Open YAML report in createReport
commit f94ad6bc7a01b78c3b6a63f8ad965bb5dea23f07
Author: aagbsn <aagbsn@xxxxxxxx>
Date: Thu Feb 28 15:57:23 2013 +0100
Open YAML report in createReport
Also adds reporter exceptions ReportAlreadyClosed and ReportNotCreated
---
ooni/errors.py | 6 ++++++
ooni/reporter.py | 12 +++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/ooni/errors.py b/ooni/errors.py
index 2023dbf..36a042f 100644
--- a/ooni/errors.py
+++ b/ooni/errors.py
@@ -126,3 +126,9 @@ class InvalidOONIBCollectorAddress(Exception):
class AllReportersFailed(Exception):
pass
+class ReportNotCreated(Exception):
+ pass
+
+class ReportAlreadyClosed(Exception):
+ pass
+
diff --git a/ooni/reporter.py b/ooni/reporter.py
index 69d4892..c01e904 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -27,6 +27,7 @@ except ImportError:
from ooni.errors import InvalidOONIBCollectorAddress
+from ooni.errors import ReportNotCreated, ReportAlreadyClosed
from ooni import otime
from ooni.utils import geodata, pushFilenameStack
@@ -184,15 +185,17 @@ class YAMLReporter(OReporter):
log.msg("Report already exists with filename %s" % report_path)
pushFilenameStack(report_path)
- log.debug("Creating %s" % report_path)
- self._stream = open(report_path, 'w+')
-
+ self.report_path = report_path
OReporter.__init__(self, test_details)
def _writeln(self, line):
self._write("%s\n" % line)
def _write(self, format_string, *args):
+ if not self._stream:
+ raise ReportNotCreated
+ if self._stream.closed:
+ raise ReportAlreadyClosed
s = str(format_string)
assert isinstance(s, type(''))
if args:
@@ -214,6 +217,9 @@ class YAMLReporter(OReporter):
"""
Writes the report header and fire callbacks on self.created
"""
+ log.debug("Creating %s" % self.report_path)
+ self._stream = open(self.report_path, 'w+')
+
self._writeln("###########################################")
self._writeln("# OONI Probe Report for %s (%s)" % (self.testDetails['test_name'],
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits