Package Ganga :: Package Lib :: Package Root :: Module shared
[hide private]
[frames] | no frames]

Source Code for Module Ganga.Lib.Root.shared

 1  """Module for sharing code between the Runtime and Download handlers.""" 
 2  import Ganga.Utility.logging 
 3  logger = Ganga.Utility.logging.getLogger() 
 4   
5 -def findPythonVersion(rootsys):
6 '''Digs around in rootsys for config files and then greps 7 the version of python used''' 8 import os 9 10 def lookInFile(config): 11 '''Looks in the specified file for the build config 12 and picks out the python version''' 13 version = None 14 if os.path.exists(config): 15 configFile = file(config) 16 for line in configFile:#loop through the file looking for #define 17 if line.startswith('#define R__CONFIGUREOPTION'): 18 for arg in line.split(' '):#look at value of #define 19 if arg.startswith('PYTHONDIR'): 20 arglist = arg.split('/') 21 #TODO: Would like some kind of check for arch here 22 if len(arglist) > 1:#prevent index out of range 23 version = arglist[-2] 24 return version
25 26 def useRootConfig(rootsys): 27 """Use the new root-config features to find the python version""" 28 version = None 29 root_config = os.path.join(rootsys,'bin','root-config') 30 if os.path.exists(root_config): 31 import subprocess 32 33 args = [root_config,'--python-version'] 34 35 run = subprocess.Popen(' '.join(args), shell = True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 36 out, err = [ e.splitlines() for e in run.communicate() ] 37 code = run.returncode 38 if code == 0 and out and not err and len(out) == 1: 39 split = out[0].split('.') 40 if len(out) != len(split): 41 version = '.'.join(split) 42 return version 43 44 45 version = None 46 for f in ['config.h','RConfigure.h']: 47 version = lookInFile(os.path.join(rootsys,'include',f)) 48 if version is not None: 49 break 50 if version is None: 51 version = useRootConfig(rootsys) 52 return version 53
54 -def setEnvironment(key, value, update=False,environment=None):
55 '''Sets an environment variable. If update=True, it prepends it to 56 the current value with os.pathsep as the seperator.''' 57 import os 58 if environment == None: 59 environment = os.environ 60 61 if update and environment.has_key(key): 62 value += (os.pathsep + environment[key])#prepend 63 environment[key] = value 64 65 return environment
66