diff --git a/changelog b/changelog index 2362971..99211e2 100644 --- a/changelog +++ b/changelog @@ -4,13 +4,14 @@ Changelog * Changes are always commented with their author in (braces) * Exception: No braces means author == Nico Schottelius -1.0: +1.0: 2014-07-01 * Added installer (Oz Nahum) * Bugfix in listprojects (Oz Nahum) * Allow ctt to run from checkout and installation path * Correct license indication in setup.py (Davide Riccardo Caliendo) * Added license and manifest files (Davide Riccardo Caliendo) * Added bash completion script (Davide Riccardo Caliendo) + * Report an error on invalid time entries 0.9: 2013-04-29 diff --git a/lib/ctt/__init__.py b/lib/ctt/__init__.py index b29e22d..f8b9572 100644 --- a/lib/ctt/__init__.py +++ b/lib/ctt/__init__.py @@ -70,5 +70,4 @@ def project_dir(project): return project_dir -def list_projects(ctt_dir): return os.listdir(ctt_dir) diff --git a/lib/ctt/report.py b/lib/ctt/report.py index 9e48e4a..4f6afb3 100755 --- a/lib/ctt/report.py +++ b/lib/ctt/report.py @@ -117,7 +117,12 @@ class Report(object): self._report_db = {} for dirname in os.listdir(self.project_dir): - dir_datetime = datetime.datetime.strptime(dirname, ctt.DISKFORMAT) + log.debug("Dirname: %s" % dirname) + try: + dir_datetime = datetime.datetime.strptime(dirname, ctt.DISKFORMAT) + except ValueError: + raise ctt.Error("Invalid time entry {entry} for project {project}, aborting!".format(entry=dirname, project=self.project)) + if dir_datetime >= self.start_date and dir_datetime <= self.end_date: filename = os.path.join(self.project_dir, dirname, ctt.FILE_DELTA) comment_filename = os.path.join(self.project_dir, dirname, ctt.FILE_COMMENT) @@ -182,12 +187,16 @@ class Report(object): entry = self._report_db[time] report = {} - report['start_datetime'] = datetime.datetime.strptime(time, ctt.DATETIMEFORMAT) + start_datetime = datetime.datetime.strptime(time, ctt.DATETIMEFORMAT) + delta = datetime.timedelta(seconds=int(float(entry['delta']))) + end_datetime = (start_datetime + delta).replace(microsecond = 0) + report['start_datetime'] = start_datetime.strftime(ctt.DATETIMEFORMAT) + report['end_datetime'] = end_datetime.strftime(ctt.DATETIMEFORMAT) + + report['delta'] = delta 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: report['comment'] = entry['comment']