forked from DOCGroup/autobuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautobuild_vars.py
executable file
·74 lines (56 loc) · 1.82 KB
/
autobuild_vars.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
from optparse import OptionParser
import sys, string
import xml.sax
import xml.sax.handler
def parse_args ():
parser = OptionParser ()
parser.add_option ("-u", action="store_true", dest="unix", default=False,
help="Use Unix environment characteristics")
parser.add_option ("-w", action="store_true", dest="windows", default=False,
help="Use Windows environment characteristics")
return parser.parse_args ()
class AutobuildHandler (xml.sax.handler.ContentHandler):
def __init__ (self):
self.env_map = dict ()
# Constructor
return
def startElement (self, name, attrs):
if name == "environment":
self.env_map [attrs.get ("name")] = attrs.get ("value")
def main ():
(opts, args) = parse_args ()
if len(args) != 1:
print "Must pass exactly one argument to this script."
return
# Create the parser
handler = AutobuildHandler ()
parser = xml.sax.make_parser ()
parser.setContentHandler (handler)
# Parse
inFile = file (args[0], 'r')
parser.parse (inFile)
inFile.close ()
# Set up characteristics
set_expr = ""
sep_expr = ""
var_pre_expr = ""
var_post_expr = ""
if opts.unix:
set_expr = "export "
sep_expr = ":"
var_pre_expr = "$"
elif opts.windows:
set_expr = "set "
sep_expr = ";"
var_pre_expr = "%"
var_post_expr = "%"
else:
print "You must specify either unix or windows!"
exit
for variable, value in handler.env_map.iteritems ():
command = set_expr + variable + "=" + value
if variable.find ("PATH") != -1:
command += sep_expr + var_pre_expr + variable + var_post_expr
print command
if __name__ == "__main__":
main ()