-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·45 lines (37 loc) · 1.4 KB
/
setup.py
File metadata and controls
executable file
·45 lines (37 loc) · 1.4 KB
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
#!/usr/bin/python
import os
import re
import sys
CONFIG_FILES=[('bin/activate', 'HOMEDIR="%s"'),
('bin/activate.csh', 'setenv HOMEDIR "%s"'),
('bin/activate.fish', 'set -gx HOME_DIR "%s"')]
def setup():
setup_bootstrap()
setup_links()
def setup_bootstrap():
_path = os.path.dirname(os.path.abspath(__file__))
for f_name,pat in CONFIG_FILES:
f = open("%s/%s" % (_path, f_name), "r")
lines = map(lambda x: x.rstrip(), f.readlines())
f = open("%s/%s" % (_path, f_name), "w+")
re_pat = "^(.*)%s.*" % (pat[:pat.find("%s")],)
for l in lines:
if re.search(re_pat, l) != None:
f.write("%s%s\n" % (re.search(re_pat, l).groups()[0], pat % (_path,)))
else:
f.write("%s\n" % (l,))
f.close()
def setup_links():
_path = os.path.dirname(os.path.abspath(__file__))
search_paths = ["/usr/bin/python", "/usr/local/bin/python", "/sw/bin/python"]
os.remove(os.path.join(_path, "bin/python"))
for p in search_paths:
if os.path.exists(p):
print "linking %s -> %s" % (os.path.join(_path, "bin/python"), p)
os.symlink(p, os.path.join(_path, "bin/python"))
return
print "couldn't find python!!! searched %s" % (search_paths,)
sys.exit(-1)
if __name__ == "__main__":
## TODO : allow specification of path-to-python-bin
setup()