-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap
executable file
·102 lines (79 loc) · 3.07 KB
/
bootstrap
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
import argparse
import json
import os
from bs_tools.tools import validating_user_input, load_dotfiles
from bs_tools import bootstrap_opts
IGNORE = [
'README.md',
'bs_tools/*',
'bootstrap',
'.gitignore',
'.git/*',
'.idea/*',
'*~',
'venv/*',
'uninstall',
'dotfile-bootstrap/*',
'bs_ignore.json'
]
def symlink_files(skip_files, skip_folders):
overwrite_all = False
ignore_files = IGNORE + skip_files + [x + "/*" for x in skip_folders]
files = load_dotfiles(ignore_files)
for file in files:
opts = bootstrap_opts.parse_opts(file)
filename = os.path.basename(file)
file = os.path.join(os.getcwd(), file)
for opt, fcn in bootstrap_opts.BOOTSTRAP_OPTS:
val = opts.get(opt, False)
if val:
filename = fcn(filename, val)
print("Preparing to symlink " + file + " to " + filename)
if os.path.lexists(filename):
if not overwrite_all:
inpt = validating_user_input("{filename} exists. Overwrite?".format(
filename=filename
))
if inpt == 'n':
print("Symlink aborted.\n")
continue # go to next file
if inpt == 'a':
overwrite_all = True
os.remove(filename)
filepath = os.path.dirname(filename)
if not os.path.exists(filepath):
os.mkdir(filepath)
os.symlink(file, filename)
print("Symlink created!\n")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--symlink', action='store_true')
parser.add_argument('-c', '--config', metavar="config-file",
help="Specify configuration of dotfiles")
parser.add_argument('-f', '--no-install-file', action='append',
help="Skip installing specified file. Note: if filename"
" is not unique, you must specify folder as well"
" (ex: path/file.txt)",
metavar='file-to-skip', default=[])
parser.add_argument('-F', '--no-install-folder', action='append',
help="Skip installing any files from specified folder",
metavar='folder-to-skip', default=[])
args = parser.parse_args()
try:
with open("bs_ignore.json") as ignore:
print("Ignoring files as specified in bs_ignore.json")
ignore_files = json.load(ignore)
IGNORE.extend(ignore_files)
except FileNotFoundError as e:
pass
if args.config:
# break configuration file down into appropriate arguments
update_args = vars(args)
with open(args.config) as config_file:
conf = json.load(config_file)
for key, value in conf.items():
if isinstance(update_args[key], list):
update_args[key].extend(value)
if args.symlink:
symlink_files(args.no_install_file, args.no_install_folder)