-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_env.py
executable file
·71 lines (54 loc) · 1.95 KB
/
setup_env.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
70
71
#!/usr/bin/env python
"""Symlink appropriate files into your home directory."""
import os
import subprocess
# Global - add files you want to ignore in the current directory
IGNORED = ["README.md", "_bashrc", ".git", "windows", "bundles.vim"]
def main():
dotfiles_dir = os.path.dirname(os.path.realpath(__file__))
home = os.getenv("HOME")
print "Installing apt-packages"
reqs = os.path.join(dotfiles_dir, 'requirements.txt')
subprocess.call('cat {0} | xargs sudo apt-get install'.format(reqs), shell=True)
dotfiles = os.listdir(dotfiles_dir)
dotfiles.sort()
maxlen = max([len(s) for s in dotfiles])
formatstr = "%%%ds -" % (maxlen + 2)
for f in dotfiles:
print formatstr % f,
if f.startswith("setup_"):
print "Ignoring (setup script)"
continue
if f.endswith("~"):
print "Ignoring (temp file)"
continue
if f in IGNORED:
print "Ignoring (explict)"
continue
if f.startswith("_"):
source = os.path.join(dotfiles_dir, f)
dest = os.path.join(home, f).replace("_", ".")
if os.path.exists(dest):
print "Ignoring (already exists)"
continue
try:
os.symlink(source, dest)
print "Linked to %s" % dest
except OSError:
print "Failed (OSError)"
raise
else:
print "Ignoring (unexpected name)"
bashrc = os.path.join(home, ".bashrc")
bashrc_line = "source ~/dotfiles/_bashrc"
found = False
with open(bashrc) as f:
for line in f:
if line.strip() == bashrc_line:
print "\n.bashrc has already been modified."
found = True
if not found:
print "\nAdding dotfiles/.bashrc to the end of the ~/.bashrc"
os.system('echo "%s" >> $HOME/.bashrc' % bashrc_line)
if __name__ == "__main__":
main()