-
Notifications
You must be signed in to change notification settings - Fork 6
/
bootstrap.py
69 lines (56 loc) · 1.99 KB
/
bootstrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/local/bin/python
import os
import sys
import shutil
def mkdir(d):
try:
os.makedirs(d)
except Exception:
pass
home = os.path.expanduser('~')
taskd = os.path.join(home, '.task')
taskrc = os.path.join(home, '.taskrc')
timed = os.path.join(home, '.timewarrior')
timecfg = os.path.join(timed, 'timewarrior.cfg')
# Keep data in a target folder like cloud-disk
if len(sys.argv) > 1:
dst = os.path.realpath(sys.argv[1])
dtaskd = os.path.join(dst, 'taskwarrior')
dtimed = os.path.join(dst, 'timewarrior')
map(mkdir, (dtaskd, dtimed))
# # Migrate existing data of taskwarrior
if os.path.isdir(taskd):
for fn in os.listdir(taskd):
if fn.endswith('.data'):
shutil.copy(os.path.join(taskd, fn), dtaskd)
with open(taskrc, 'a') as file:
file.write('\ndata.location=%s' % dtaskd)
# # Migrate existing data of timewarrior
timedd = os.path.join(timed, 'data')
dtimedd = os.path.join(dtimed, 'data')
if os.path.isdir(timedd):
shutil.move(timedd, dtimed)
else:
mkdir(dtimedd)
os.path.isdir(timed) or mkdir(timed)
os.symlink(dtimedd, timed)
taskd = dtaskd
timed = dtimed
map(mkdir, (taskd, timed))
# Install hooks and extensions of Pomodoro-Warriors
base = os.path.dirname(os.path.realpath(sys.argv[0]))
btaskd = os.path.join(base, 'taskwarrior')
btimed = os.path.join(base, 'timewarrior')
btimecfg = os.path.join(btimed, 'timewarrior.cfg')
# # Backup and setup hooks of taskwarrior
hooks = os.path.join(taskd, 'hooks')
os.path.isdir(hooks) and shutil.move(hooks, hooks + '.bak')
os.symlink(os.path.join(btaskd, 'hooks'), hooks)
with open(taskrc, 'a') as file:
file.write('\ninclude %s/taskrc' % btaskd)
# # Backup and setup extensions of timewarrior
exts = os.path.join(timed, 'extensions')
os.path.isdir(exts) and shutil.move(exts, exts + '.bak')
os.symlink(os.path.join(btimed, 'extensions'), exts)
with open(timecfg, 'a') as file:
file.write('\n%s' % open(btimecfg).read())