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

36
tools/convert-0.1-to-0.2-format Executable file
View 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)