change disk format and add conversion utility

Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
Nico Schottelius 2012-08-28 14:03:58 +02:00
commit 58a8924811
4 changed files with 48 additions and 11 deletions

View file

@ -27,9 +27,13 @@ VERSION = "0.1"
FILE_DELTA = "delta"
DATEFORMAT = "%Y-%m-%d"
DATEFORMAT_PLAIN= DATEFORMAT.replace("%","")
DATETIMEFORMAT = "%Y-%m-%d-%H:%M"
DATETIMEFORMAT = "%Y-%m-%d-%H%M"
DATETIMEFORMAT_PLAIN= DATETIMEFORMAT.replace("%","")
# Name of the folder to create - should not contain special characters
# to ensure cross-os compatibility
DISKFORMAT = DATETIMEFORMAT
class Error(Exception):
pass

View file

@ -74,15 +74,15 @@ class Report(object):
self._report_db = {}
for dirname in os.listdir(self.project_dir):
if dirname >= self.start_seconds and dirname <= self.end_seconds:
dir_datetime = datetime.datetime.strptime(dirname, ctt.DISKFORMAT)
if dir_datetime >= self.start_date and dir_datetime <= self.end_date:
filename = os.path.join(self.project_dir, dirname, ctt.FILE_DELTA)
with open(filename, "r") as fd:
self._report_db[dirname] = fd.read().rstrip('\n')
log.debug("%s: %s" % (dirname, self._report_db[dirname]))
log.debug("Recording: %s: %s" % (dirname, self._report_db[dirname]))
else:
log.debug("%s/%s" % (float(dirname) - float(self.start_seconds),
float(self.end_seconds) - float(dirname)))
log.debug("Skipping: %s" % dirname)
def report(self):
"""Show report to the user"""

View file

@ -93,11 +93,8 @@ class Tracker:
raise ctt.Error("End date must be after start date! (%s > %s)!" %
(self.start_datetime, self.end_datetime))
start_seconds = self.start_datetime.strftime("%s")
end_seconds = self.end_datetime.strftime("%s")
delta_seconds = self.delta()
time_dir = os.path.join(self.project_dir, start_seconds)
subdirname = self.start_datetime.strftime(ctt.DISKFORMAT)
time_dir = os.path.join(self.project_dir, subdirname)
if os.path.exists(time_dir):
raise ctt.Error("Already tracked time at this beginning for this project")
@ -106,7 +103,7 @@ class Tracker:
filename = os.path.join(time_dir, ctt.FILE_DELTA)
with open(filename, "w") as fd:
fd.write("%s\n" % delta_seconds)
fd.write("%s\n" % self.delta())
def delta(self, in_seconds=True):
"""Return time delta - empty (==0) if not tracked"""