[tor-commits] [oonib/master] Add support for specifying the format of report filenames and directories in the archive.
art at torproject.org
art at torproject.org
Mon Sep 29 18:13:34 UTC 2014
commit 33b953312a5244afd6295788304faab822cdbaf6
Author: Arturo Filastò <art at fuffa.org>
Date: Mon Sep 29 13:02:53 2014 +0200
Add support for specifying the format of report filenames and directories in the archive.
This implements: https://trac.torproject.org/projects/tor/ticket/13232#comment:1
---
bin/oonib | 1 +
oonib.conf.example | 2 +-
oonib/report/handlers.py | 37 +++++++++++++++++++++----------------
3 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/bin/oonib b/bin/oonib
index fcb0c72..109c74e 100755
--- a/bin/oonib
+++ b/bin/oonib
@@ -51,5 +51,6 @@ class OBaseRunner(UnixApplicationRunner):
temporary_data_dir = None
def createOrGetApplication(self):
return application
+
OBaseRunner.loggerFactory = LoggerFactory
OBaseRunner(config.main).run()
diff --git a/oonib.conf.example b/oonib.conf.example
index 6b07414..64eb5c5 100644
--- a/oonib.conf.example
+++ b/oonib.conf.example
@@ -29,7 +29,7 @@ main:
stale_time: 3600
tor_hidden_service: true
-
+ report_file_template: '{test_name}-{iso8601_timestamp}-{probe_asn}-probe.yamloo'
helpers:
http-return-json-headers:
address: null
diff --git a/oonib/report/handlers.py b/oonib/report/handlers.py
index 4b88647..13cc06e 100644
--- a/oonib/report/handlers.py
+++ b/oonib/report/handlers.py
@@ -16,13 +16,25 @@ from oonib import randomStr, otime, log
from oonib.config import config
-def report_file_name(report_details):
- timestamp = otime.timestamp(
- datetime.fromtimestamp(
- report_details['start_time']))
- dst_filename = '{test_name}-{timestamp}-{probe_asn}-probe.yamloo'.format(
- timestamp=timestamp,
- **report_details)
+def report_file_name(archive_dir, report_details):
+ timestamp = datetime.fromtimestamp(report_details['start_time'])
+ keys = dict(
+ report_details.items(),
+ iso8601_timestamp=otime.timestamp(timestamp),
+ year=timestamp.strftime("%Y"),
+ month=timestamp.strftime("%m"),
+ day=timestamp.strftime("%d"),
+ hour=timestamp.strftime("%H"),
+ minute=timestamp.strftime("%M"),
+ second=timestamp.strftime("%S")
+ )
+ report_file_template = "{test_name}-{iso8601_timestamp}-{probe_asn}-probe.yamloo"
+ if config.main.report_file_template:
+ report_file_template = config.main.report_file_template
+ dst_filename = os.path.join(archive_dir, report_file_template.format(**keys))
+ dst_dir = os.path.dirname(dst_filename)
+ if not os.path.exists(dst_dir):
+ os.makedirs(dst_dir)
return dst_filename
@@ -69,15 +81,8 @@ class Report(object):
except IOError:
raise e.ReportNotFound
- dst_filename = report_file_name(report_details)
- dst_path = os.path.join(self.archive_dir,
- report_details['probe_cc'])
-
- if not os.path.isdir(dst_path):
- os.mkdir(dst_path)
-
- dst_path = os.path.join(dst_path, dst_filename)
- shutil.move(report_filename, dst_path)
+ dst_filename = report_file_name(self.archive_dir, report_details)
+ shutil.move(report_filename, dst_filename)
if not self.delayed_call.called:
self.delayed_call.cancel()
More information about the tor-commits
mailing list