|
Gaudi Framework, version v23r4 |
| Home | Generated: Mon Sep 17 2012 |
Functions | |
| def | set_env |
| def | parse_args |
| def | envFromXML |
| def | main |
| def env::envFromXML | ( | env, | |
| xmlfiles | |||
| ) |
Extend the environment declared in the dictionary env with the actions in the XML files specified in the list 'xmlfiles'.
Definition at line 87 of file env.py.
00088 : 00089 ''' 00090 Extend the environment declared in the dictionary env with the actions 00091 in the XML files specified in the list 'xmlfiles'. 00092 ''' 00093 from EnvConfig import Control 00094 control = Control.Environment() 00095 # declare scalar and list variables ("*PATH*" and "*DIRS*" are lists) 00096 for k, v in env.items(): 00097 if 'PATH' in k or 'DIRS' in k: 00098 t = 'list' 00099 else: 00100 t = 'scalar' 00101 control.declare(k, t, False) 00102 control.set(k, v) 00103 00104 for f in xmlfiles: 00105 control.loadXML(f) 00106 00107 return control.vars()
| def env::main | ( | ) |
Definition at line 108 of file env.py.
00109 : 00110 opts, args = parse_args() 00111 00112 # find the 'set' arguments in the list of arguments 00113 i = 0 00114 argc = len(args) 00115 while (i < argc) and ("=" in args[i]): 00116 i += 1 00117 opts.set.extend(args[:i]) 00118 cmd = args[i:] 00119 00120 # prepare initial dictionary 00121 if opts.ignore_environment: 00122 env = {} 00123 else: 00124 env = dict(os.environ) 00125 00126 if opts.xml: 00127 env = envFromXML(env, opts.xml) 00128 00129 env = set_env(env, 00130 set = opts.set, unset = opts.unset, 00131 append = opts.append, prepend = opts.prepend) 00132 if sys.platform.startswith("win"): 00133 env["PATH"] = env["PATH"] + os.pathsep + env["LD_LIBRARY_PATH"] 00134 elif sys.platform.startswith("darwin"): 00135 if "DYLD_LIBRARY_PATH" in env: 00136 env["DYLD_LIBRARY_PATH"] = env["DYLD_LIBRARY_PATH"] + os.pathsep + env["LD_LIBRARY_PATH"] 00137 else: 00138 env["DYLD_LIBRARY_PATH"] = env["LD_LIBRARY_PATH"] 00139 00140 00141 if not cmd: 00142 for nv in env.items(): 00143 print "%s=%s" % nv 00144 return 0 00145 else: 00146 from subprocess import Popen 00147 return Popen(cmd, env=env).wait()
| def env::parse_args | ( | ) |
Definition at line 48 of file env.py.
00049 : 00050 from optparse import OptionParser 00051 parser = OptionParser(prog = "env", 00052 usage = "Usage: %prog [OPTION]... [NAME=VALUE]... [COMMAND [ARG]...]", 00053 description = "Set each NAME to VALUE in the environment and run COMMAND.", 00054 epilog = "The operations are performed in the order: unset, set, append, " 00055 "prepend. If no COMMAND, print the resulting environment." ) 00056 parser.add_option("-i", "--ignore-environment", 00057 action = "store_true", 00058 help = "start with an empty environment") 00059 parser.add_option("-u", "--unset", 00060 metavar = "NAME", 00061 action = "append", 00062 help = "remove variable from the environment") 00063 parser.add_option("-s", "--set", 00064 metavar = "NAME=VALUE", 00065 action = "append", 00066 help = "set the variable NAME to VALUE") 00067 parser.add_option("-a", "--append", 00068 metavar = "NAME=VALUE", 00069 action = "append", 00070 help = "append VALUE to the variable NAME (with a '%s' as separator)" % os.pathsep) 00071 parser.add_option("-p", "--prepend", 00072 metavar = "NAME=VALUE", 00073 action = "append", 00074 help = "prepend VALUE to the variable NAME (with a '%s' as separator)" % os.pathsep) 00075 parser.add_option("-x", "--xml", 00076 action = "append", 00077 help = "XML file describing the changes to the environment") 00078 parser.disable_interspersed_args() 00079 parser.set_defaults(unset = [], 00080 set = [], 00081 append = [], 00082 prepend = [], 00083 xml = [], 00084 ignore_environment = False) 00085 00086 return parser.parse_args()
| def env::set_env | ( | env, | |
set = [], |
|||
unset = [], |
|||
append = [], |
|||
prepend = [] |
|||
| ) |
Manipulate the dictionary-like object 'env' according to the prescriptions in the lists 'unset', 'set', 'append' and 'prepend' (in this order). The lists must contain strings of the format 'NAME=VALUE' except for 'unset' which requires only 'NAME'.
Definition at line 7 of file env.py.
00008 : 00009 """ 00010 Manipulate the dictionary-like object 'env' according to the prescriptions in 00011 the lists 'unset', 'set', 'append' and 'prepend' (in this order). 00012 The lists must contain strings of the format 'NAME=VALUE' except for 'unset' 00013 which requires only 'NAME'. 00014 """ 00015 def parse(x): 00016 """split the "NAME=VALUE" string into the tuple ("NAME", "VALUE") 00017 replacing '[:]' with os.pathsep in VALUE""" 00018 n, v = x.split('=', 1) 00019 return n, v.replace('[:]', os.pathsep) 00020 def dictlist(l): 00021 """create a dictionary from the list of pairs by appending to lists""" 00022 d = {} 00023 for n, v in l: 00024 if n in d: 00025 d[n].append(v) 00026 else: 00027 d[n] = [v] 00028 return d 00029 # remove the 'unset' variables 00030 for n in unset: 00031 if n in env: 00032 log.debug("unset %s", n) 00033 del env[n] 00034 # set the requested variables 00035 env.update(map(parse, set)) 00036 # append 00037 for n, v in dictlist(map(parse, append)).items(): 00038 if n in env: 00039 v.insert(0, env[n]) # add old value at the beginning 00040 env[n] = os.pathsep.join(v) 00041 # prepend 00042 for n, v in dictlist(map(parse, reversed(prepend))).items(): 00043 if n in env: 00044 v.append(env[n]) # add old value at end 00045 env[n] = os.pathsep.join(v) 00046 00047 return env