From dbcecf9970d584a1cfe30bb31c6a899e64d0b391 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 29 Apr 2013 16:38:21 +0200 Subject: [PATCH] use a dict to have keyword access Signed-off-by: Nico Schottelius --- ctt.text | 10 +++++++++- lib/ctt/__init__.py | 4 ++-- lib/ctt/report.py | 22 +++++++++------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/ctt.text b/ctt.text index 9c908ff..0b55207 100644 --- a/ctt.text +++ b/ctt.text @@ -75,8 +75,16 @@ Available parameters: -i, --ignore-case:: ignore case distinctions -f OUTPUT_FORMAT, --format OUTPUT_FORMAT:: - output format (default: {0} ({1}): {2}) + output format (default: {start_datetime} ({delta}): {comment}) +Output format may reference the following fields: + +- start_datetime +- end_datetime +- delta +- delta_seconds +- delta_minutes +- comment LISTPROJECTS ------------ diff --git a/lib/ctt/__init__.py b/lib/ctt/__init__.py index 17577e3..fbfac2f 100644 --- a/lib/ctt/__init__.py +++ b/lib/ctt/__init__.py @@ -23,14 +23,14 @@ import os import os.path -VERSION = "0.8" +VERSION = "0.9" FILE_DELTA = "delta" FILE_COMMENT = "comment" DATEFORMAT = "%Y-%m-%d" DATEFORMAT_PLAIN= DATEFORMAT.replace("%","") DATETIMEFORMAT = "%Y-%m-%d-%H%M" DATETIMEFORMAT_PLAIN= DATETIMEFORMAT.replace("%","") -REPORTFORMAT = "{0} ({1}): {2}" +REPORTFORMAT = "{start_datetime} ({delta}): {comment}" # Name of the folder to create - should not contain special characters # to ensure cross-os compatibility diff --git a/lib/ctt/report.py b/lib/ctt/report.py index 4282f00..da1776e 100755 --- a/lib/ctt/report.py +++ b/lib/ctt/report.py @@ -164,22 +164,18 @@ class Report(object): for time in sorted_times: entry = self._report_db[time] + report = {} - start_datetime = datetime.datetime.strptime(time, ctt.DATETIMEFORMAT) - - delta_seconds = int(float(entry['delta'])) - delta_minutes = int(delta_seconds/60) - delta = datetime.timedelta(seconds=int(float(entry['delta']))) - - end_datetime = start_datetime + delta - - # Strip off microsecends - this is really too much - end_datetime = end_datetime.replace(microsecond = 0) + report['start_datetime'] = datetime.datetime.strptime(time, ctt.DATETIMEFORMAT) + report['delta_seconds'] = int(float(entry['delta'])) + report['delta_minutes'] = int(report['delta_seconds']/60) + report['delta'] = datetime.timedelta(seconds=int(float(entry['delta']))) + report['end_datetime'] = (report['start_datetime'] + report['delta']).replace(microsecond = 0) if 'comment' in entry: - comment = entry['comment'] + report['comment'] = entry['comment'] else: - comment = False + report['comment'] = False - print(self.output_format.format(start_datetime, delta, comment, delta_seconds, delta_minutes)) + print(self.output_format.format_map(report))