ctt/tools/convert-0.1-to-0.2-format
Nico Schottelius 58a8924811 change disk format and add conversion utility
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
2012-08-28 14:03:58 +02:00

36 lines
1,021 B
Python
Executable file

#!/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)