1 """Module for sharing code between the Runtime and Download handlers."""
2 import Ganga.Utility.logging
3 logger = Ganga.Utility.logging.getLogger()
4
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:
17 if line.startswith('#define R__CONFIGUREOPTION'):
18 for arg in line.split(' '):
19 if arg.startswith('PYTHONDIR'):
20 arglist = arg.split('/')
21
22 if len(arglist) > 1:
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
66