forked from pjozog/settings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplysettings.py
executable file
·171 lines (125 loc) · 5.36 KB
/
applysettings.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python2
import os
import sys
import errno
import shutil
scriptDir = sys.path[0]
binDir = os.path.join(scriptDir, 'linux-stuff', 'bin')
homeDir = os.getenv('HOME')
dropboxDir = os.path.join(os.getenv('HOME'), 'Dropbox')
requiredDirs = [os.path.join(homeDir, '.config'),
os.path.join(homeDir, '.config', 'gtk-3.0'),
os.path.join(homeDir, '.config', 'terminator'),
os.path.join(homeDir, 'bin'),
os.path.join(homeDir, '.themes'),
os.path.join(homeDir, 'Documents'),
os.path.join(homeDir, 'Documents', 'MATLAB'),
os.path.join(homeDir, '.ssh')]
linkPairs = [
# format:
# (path to version-controlled file,
# name of symbolic link)
#
# think of it as running 'ln -sf <first_thing> <second_thing>'
(os.path.join(scriptDir, 'linux-stuff', '.bashrc'),
os.path.join(homeDir, '.bashrc')),
(os.path.join(scriptDir, 'linux-stuff', '.bash_profile'),
os.path.join(homeDir, '.bash_profile')),
(os.path.join(scriptDir, 'linux-stuff', '.zshrc'),
os.path.join(homeDir, '.zshrc')),
(os.path.join(scriptDir, 'linux-stuff', '.zshrc.local'),
os.path.join(homeDir, '.zshrc.local')),
(os.path.join(scriptDir, 'linux-stuff', '.zshrc.pre'),
os.path.join(homeDir, '.zshrc.pre')),
(os.path.join(scriptDir, 'linux-stuff', '.profile'),
os.path.join(homeDir, '.profile')),
(os.path.join(scriptDir, 'linux-stuff', '.shell_aliases'),
os.path.join(homeDir, '.shell_aliases')),
(os.path.join(scriptDir, 'emacs-stuff', '.emacs.d'),
os.path.join(homeDir, '.emacs.d')),
(os.path.join(scriptDir, 'openbox-stuff', 'openbox'),
os.path.join(homeDir, '.config', 'openbox')),
(os.path.join(scriptDir, 'awesome-stuff', 'awesome'),
os.path.join(homeDir, '.config', 'awesome')),
(os.path.join(scriptDir, 'ipython-stuff', 'ipython'),
os.path.join(homeDir, '.ipython')),
(os.path.join(scriptDir, 'ipython-stuff', 'matplotlib'),
os.path.join(homeDir, '.config', 'matplotlib')),
(os.path.join(scriptDir, 'linux-stuff', 'autostart.sh'),
os.path.join(homeDir, '.config', 'autostart.sh')),
(os.path.join(scriptDir, 'linux-stuff', 'settings.ini'),
os.path.join(homeDir, '.config', 'gtk-3.0', 'settings.ini')),
(os.path.join(scriptDir, 'linux-stuff', '.fonts.conf'),
os.path.join(homeDir, '.fonts.conf')),
(os.path.join(scriptDir, 'linux-stuff', '.dircolors'),
os.path.join(homeDir, '.dircolors')),
(os.path.join(scriptDir, 'linux-stuff', '.pythonrc'),
os.path.join(homeDir, '.pythonrc')),
(os.path.join(scriptDir, 'texpath'),
os.path.join(homeDir, 'texpath')),
(os.path.join(scriptDir, 'mercurial-stuff', '.hgrc'),
os.path.join(homeDir, '.hgrc')),
(os.path.join(scriptDir, 'git-stuff', '.gitconfig'),
os.path.join(homeDir, '.gitconfig')),
(os.path.join(scriptDir, 'linux-stuff', '.gtkrc-mine'),
os.path.join(homeDir, '.gtkrc-mine')),
(os.path.join(scriptDir, 'openbox-stuff', 'Radiance_ob_test'),
os.path.join(homeDir, '.themes', 'Radiance_ob_test')),
(os.path.join(scriptDir, 'linux-stuff', '.Xmodmap'),
os.path.join(homeDir, '.Xmodmap')),
(os.path.join(scriptDir, 'linux-stuff', '.aspell.en.pws'),
os.path.join(homeDir, '.aspell.en.pws')),
(os.path.join(scriptDir, 'linux-stuff', '.fonts'),
os.path.join(homeDir, '.fonts')),
(os.path.join(scriptDir, 'linux-stuff', '.xinitrc'),
os.path.join(homeDir, '.xinitrc')),
(os.path.join(scriptDir, 'gdb-stuff', '.gdbinit'),
os.path.join(homeDir, '.gdbinit')),
(os.path.join(scriptDir, 'matlab-stuff', 'startup.m'),
os.path.join(homeDir, 'Documents', 'MATLAB', 'startup.m')),
(os.path.join(dropboxDir, 'ssh', 'config'),
os.path.join(homeDir, '.ssh', 'config')),
(os.path.join(dropboxDir, 'zsh', 'prompt'),
os.path.join(homeDir, '.zshrc.prompt')),
(os.path.join(scriptDir, 'linux-stuff', '.xbindkeysrc.scm'),
os.path.join(homeDir, '.xbindkeysrc.scm')),
(os.path.join(scriptDir, 'terminator-stuff', 'config'),
os.path.join(homeDir, '.config', 'terminator', 'config'))
]
#add all the stuff in the 'bin' directory to linkPairs
for basename in os.listdir(binDir):
sourceName = os.path.abspath(os.path.join(binDir, basename))
linkName = os.path.join(homeDir, 'bin', basename)
linkPairs.append ((sourceName, linkName))
def createLink(src, dest):
os.symlink(src, dest)
def removeFile(path):
try:
os.remove(path)
except OSError, err:
if (err.errno == errno.EISDIR or
err.errno == errno.ENOTEMPTY):
printInfo('\tRemoving dir ' + path)
shutil.rmtree(path)
else:
pass
def makeDir(directory):
try:
os.mkdir(directory)
except OSError, err: #do nothing if directory exists
if err.errno == errno.EEXIST:
pass
def printInfo(string):
print 'INFO: ' + string
def main():
for d in requiredDirs:
makeDir(d)
for tuple in linkPairs:
sourceName = tuple[0]
linkName = tuple[1]
printInfo("Creating link: " + linkName)
removeFile(linkName)
createLink(sourceName, linkName)
return 0
if __name__ == '__main__':
sys.exit(main())