-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathinstall.py
executable file
·77 lines (59 loc) · 1.96 KB
/
install.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
#!/usr/bin/python
#install.py
#install script - this should work out of the box if the above path is right
############################################################################
import os,os.path,sys
if len(sys.argv) < 2 :
print "usage: %s <username> "%sys.argv[0]
sys.exit(1)
def findcmd(cmd) :
val = os.popen("which %s"%cmd).readline().strip()
if val.find("no %s"%cmd) != -1 :
return None
return val
vals = {}
vals["USER"] = sys.argv[1]
vals["PATH"] = os.getcwd()+"/";
vals["HOME"] = os.path.expanduser("~") #os.environ["HOME"]+"/"
vals["ED"] = findcmd("vi")
vals["XT"] = findcmd("xterm")
vals["CYGWIN"] = ('0','1')[os.popen("uname").readline().find("CYGWIN") != -1]
#hack for macOS
if not vals["XT"] :
macxt = "/usr/X11R6/bin/xterm"
if os.path.isfile(macxt) :
vals["XT"] = macxt
# hack for OS X El Capitan
else :
macxt = "/usr/X11/bin/xterm"
if os.path.isfile(macxt) :
vals["XT"] = macxt
globals().update(vals)
infile = open("settings.pl.template",'r')
outfile = open("settings.pl",'w')
symlink = os.path.join(HOME,".tagtimerc")
target = os.path.join(PATH,"settings.pl")
def getVar(line) :
fields = line.split("__")
if len(fields) == 3 :
return fields[1]
return None
for lineNum,line in enumerate(infile) :
var = getVar(line)
if var :
if not var in vals or not vals[var] :
print "*** WARNING *** no value defined for __%s__"%var,"on line",lineNum,"of settings.pl.template"
print "*** you must manually set this parameter in settings.pl for tagtime to function properly"
else :
pat = "__%s__"%var
line = line.replace(pat,vals[var])
pos = line.find(";")+1
line = line[:pos].ljust(40)+line[pos:]
outfile.write(line)
if os.path.isdir(symlink) :
print "ERROR - directory exists: ",symlink
sys.exit(1)
if os.path.isfile(symlink) :
os.remove(symlink)
os.system("ln -s %s %s"%(target,symlink))
print "Done! Take a look at settings.pl to see if it looks ok..."