change disk format and add conversion utility
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
parent
be36db753d
commit
58a8924811
4 changed files with 48 additions and 11 deletions
|
@ -27,9 +27,13 @@ VERSION = "0.1"
|
||||||
FILE_DELTA = "delta"
|
FILE_DELTA = "delta"
|
||||||
DATEFORMAT = "%Y-%m-%d"
|
DATEFORMAT = "%Y-%m-%d"
|
||||||
DATEFORMAT_PLAIN= DATEFORMAT.replace("%","")
|
DATEFORMAT_PLAIN= DATEFORMAT.replace("%","")
|
||||||
DATETIMEFORMAT = "%Y-%m-%d-%H:%M"
|
DATETIMEFORMAT = "%Y-%m-%d-%H%M"
|
||||||
DATETIMEFORMAT_PLAIN= DATETIMEFORMAT.replace("%","")
|
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):
|
class Error(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -74,15 +74,15 @@ class Report(object):
|
||||||
|
|
||||||
self._report_db = {}
|
self._report_db = {}
|
||||||
for dirname in os.listdir(self.project_dir):
|
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)
|
filename = os.path.join(self.project_dir, dirname, ctt.FILE_DELTA)
|
||||||
with open(filename, "r") as fd:
|
with open(filename, "r") as fd:
|
||||||
self._report_db[dirname] = fd.read().rstrip('\n')
|
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:
|
else:
|
||||||
log.debug("%s/%s" % (float(dirname) - float(self.start_seconds),
|
log.debug("Skipping: %s" % dirname)
|
||||||
float(self.end_seconds) - float(dirname)))
|
|
||||||
|
|
||||||
def report(self):
|
def report(self):
|
||||||
"""Show report to the user"""
|
"""Show report to the user"""
|
||||||
|
|
|
@ -93,11 +93,8 @@ class Tracker:
|
||||||
raise ctt.Error("End date must be after start date! (%s > %s)!" %
|
raise ctt.Error("End date must be after start date! (%s > %s)!" %
|
||||||
(self.start_datetime, self.end_datetime))
|
(self.start_datetime, self.end_datetime))
|
||||||
|
|
||||||
start_seconds = self.start_datetime.strftime("%s")
|
subdirname = self.start_datetime.strftime(ctt.DISKFORMAT)
|
||||||
end_seconds = self.end_datetime.strftime("%s")
|
time_dir = os.path.join(self.project_dir, subdirname)
|
||||||
delta_seconds = self.delta()
|
|
||||||
|
|
||||||
time_dir = os.path.join(self.project_dir, start_seconds)
|
|
||||||
|
|
||||||
if os.path.exists(time_dir):
|
if os.path.exists(time_dir):
|
||||||
raise ctt.Error("Already tracked time at this beginning for this project")
|
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)
|
filename = os.path.join(time_dir, ctt.FILE_DELTA)
|
||||||
|
|
||||||
with open(filename, "w") as fd:
|
with open(filename, "w") as fd:
|
||||||
fd.write("%s\n" % delta_seconds)
|
fd.write("%s\n" % self.delta())
|
||||||
|
|
||||||
def delta(self, in_seconds=True):
|
def delta(self, in_seconds=True):
|
||||||
"""Return time delta - empty (==0) if not tracked"""
|
"""Return time delta - empty (==0) if not tracked"""
|
||||||
|
|
36
tools/convert-0.1-to-0.2-format
Executable file
36
tools/convert-0.1-to-0.2-format
Executable file
|
@ -0,0 +1,36 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
DATETIMEFORMAT = "%Y-%m-%d-%H%M"
|
||||||
|
DISKFORMAT = DATETIMEFORMAT
|
||||||
|
|
||||||
|
|
||||||
|
basedir = os.environ['HOME']
|
||||||
|
ctt_dir = os.path.join(basedir, ".ctt")
|
||||||
|
|
||||||
|
for project in os.listdir(ctt_dir):
|
||||||
|
time_dir = os.path.join(ctt_dir, project)
|
||||||
|
for time in os.listdir(time_dir):
|
||||||
|
print("Converting dir %s/%s" % (project, time))
|
||||||
|
try:
|
||||||
|
import_time = datetime.datetime.fromtimestamp(int(time))
|
||||||
|
except ValueError as e:
|
||||||
|
print("No old style directory %s from project %s - skipping" % (time, project))
|
||||||
|
continue
|
||||||
|
|
||||||
|
new_dirname = import_time.strftime(DISKFORMAT)
|
||||||
|
|
||||||
|
print("%s -> %s" % (time, new_dirname))
|
||||||
|
src = os.path.join(ctt_dir, project, time)
|
||||||
|
dst = os.path.join(ctt_dir, project, new_dirname)
|
||||||
|
print("%s -> %s" % (src, dst))
|
||||||
|
|
||||||
|
if os.path.exists(dst):
|
||||||
|
print("Cannot overwrite dst: %s, skipping %s" % (dst, src))
|
||||||
|
continue
|
||||||
|
|
||||||
|
os.rename(src, dst)
|
||||||
|
|
Loading…
Reference in a new issue