-
Notifications
You must be signed in to change notification settings - Fork 0
/
setenv.py
executable file
·60 lines (52 loc) · 1.34 KB
/
setenv.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
import os,sys
import sys
if len(sys.argv)>1 and sys.argv[1]=="1":
os.system("cmd /c \"setenv.bat amd64 2> nul\"")
else:
os.system("cmd /c \"setenv.bat x86 2> nul\"")
def readenv(filename):
env={}
fIN=open(filename, "r")
for line in fIN.readlines():
idx=line.find("=")
if idx!=-1:
var=line[:idx]
val=line[idx+1:-1]
env[var]=val
return env
def escape(val):
val=val.replace("\\","\\\\")
return '"'+val+'"'
def escapepath(val):
tmp={}
paths=val.split(";")
newpath=[]
for path in paths:
if not path in tmp:
tmp[path]=1
path=path.replace("c:","/cygdrive/c")
path=path.replace("C:","/cygdrive/c")
path=path.replace("\\","/")
path=path.replace(" ","\\ ")
path=path.replace("(","\\(")
path=path.replace(")","\\)")
newpath.append(path)
return ":".join(newpath)
env_before=readenv("env_before.txt")
env_after=readenv("env_after.txt")
os.remove("env_before.txt")
os.remove("env_after.txt")
for var,val in env_after.items():
if not var in env_before:
print("export %s=%s"%(var,escape(val)))
else:
oldval=env_before[var]
if val != oldval:
if var!="PATH":
pass
# currently only allow path to be different
#print var,"different"
#print oldval
#print val
else:
print("export PATH=%s"%(escapepath(val)))