forked from loganjhennessy/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.py
49 lines (41 loc) · 1.36 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
#!/usr/bin/python
import os
import shutil
currdir = os.path.dirname(os.path.abspath(__file__))
dotfiles = os.path.join(currdir, 'dotfiles')
exclude_list = ['.config']
files = []
dirs = []
for path in os.listdir(dotfiles):
if os.path.isfile(os.path.join(dotfiles, path)):
files.append(path)
else:
if path not in exclude_list:
dirs.append(path)
for path in os.listdir(os.path.join(dotfiles, '.config')):
if os.path.isfile(os.path.join(dotfiles, path)):
files.append('.config/' + path)
else:
dirs.append('.config/' + path)
homedir = os.path.expanduser("~")
for file in files:
dst = os.path.join(homedir, file)
if os.path.exists(dst) or os.path.islink(dst):
os.remove(dst)
os.symlink(os.path.join(dotfiles, file), dst)
for dir in dirs:
dst = os.path.join(homedir, dir)
print('attempting to copy to {}'.format(dst))
if os.path.exists(dst):
confirm = input('Detected directory at {}, please confirm deletion (y/n): '.format(dst))
if confirm.lower() == 'y':
if os.path.islink(dst):
os.remove(dst)
else:
shutil.rmtree(dst)
else:
print('Cannot continue with conflicting filepath.')
exit()
elif os.path.islink(dst):
os.remove(dst)
os.symlink(os.path.join(dotfiles, dir), dst)