From 6d827c1dcce7311c2d1dc068ba9293d77e44a9e0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 28 Aug 2012 17:23:24 +0200 Subject: [PATCH] Add support for comments (after tracking) Signed-off-by: Nico Schottelius --- lib/ctt/__init__.py | 1 + lib/ctt/tracker.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/ctt/__init__.py b/lib/ctt/__init__.py index 3d008a0..a958395 100644 --- a/lib/ctt/__init__.py +++ b/lib/ctt/__init__.py @@ -25,6 +25,7 @@ import os.path VERSION = "0.1" FILE_DELTA = "delta" +FILE_COMMENT = "comment" DATEFORMAT = "%Y-%m-%d" DATEFORMAT_PLAIN= DATEFORMAT.replace("%","") DATETIMEFORMAT = "%Y-%m-%d-%H%M" diff --git a/lib/ctt/tracker.py b/lib/ctt/tracker.py index 8c72e73..969f431 100755 --- a/lib/ctt/tracker.py +++ b/lib/ctt/tracker.py @@ -37,6 +37,7 @@ class Tracker: self.project_dir = ctt.project_dir(project) self._tracked_time = False + self.comment = None # Setup default values try: @@ -60,9 +61,17 @@ class Tracker: def commandline(cls, args): tracker = cls(args.project[0], args.start, args.end, args.comment) tracker.track_time() + + if args.comment: + tracker.record_comment() + tracker.write_time() log.info(tracker.delta()) + def record_comment(self): + """Record a comment for tracked data""" + self.comment = input("Comment: ") + # Track time and return information from tracking def track_time(self): """Track time, if necessary""" @@ -105,6 +114,11 @@ class Tracker: with open(filename, "w") as fd: fd.write("%s\n" % self.delta()) + if self.comment: + filename = os.path.join(time_dir, ctt.FILE_COMMENT) + with open(filename, "w") as fd: + fd.write("%s\n" % self.comment) + def delta(self, in_seconds=True): """Return time delta - empty (==0) if not tracked"""