1
3 """ PackageSetup objects represent the external packages required by a given runtime unit of Ganga.
4 The package information is stored in a dictionary. See Ganga/PACKAGE.py
5 """
7 """
8 Initialize the Package object with the list of required external packages
9 """
10 self.packages = packages
11
13 """ Return a tuple (path,tarball) which describes the external package:
14 - path points to the package top directory
15 - tarball is the package tarball name
16
17 If *force=False* (default) the python version is checked and if the package
18 is not required then return ('','').
19
20 If *force=True* the path is returned even if the package is not required.
21 """
22
23 import os.path,sys
24
25 package = self.packages[name]
26
27 try:
28 package_required = sys.hexversion < int(package['maxHexVersion'],16) or force
29 except (KeyError,ValueError):
30 package_required = 1
31
32 if not package_required:
33 return ('','')
34
35 platfdir = getPlaftorm()
36
37 if package.has_key('noarch') and package['noarch']:
38 platfdir = 'noarch'
39
40 return (os.path.join(getExternalHome(),name,package['version'],platfdir),
41 '-'.join([name,package['version'],platfdir,'ganga.tar.gz']) )
42
43
45 """ Return a path to the package for specified environment variable.
46 For example: _getPackagePath('x','LD_LIBRARY_PATH') returns a LD_LIBRARY_PATH for the package (if defined).
47 The value may be a string or a list of strings - in the later case the individual path components will
48 be separated by colons (':').
49 If the path is not defined (see getPackagePath()) then return an empty string.
50 """
51 import os
52 path,tarball = self.getPackagePath(name,force)
53 if path and self.packages[name].has_key(var):
54 from Ganga.Utility.util import isStringLike
55
56 ppath = self.packages[name][var]
57
58 if isStringLike(ppath):
59 ppath = [ppath]
60
61 return ':'.join(map(lambda p: os.path.join(path,p), ppath))
62
63
64
65
66 else:
67 return ''
68
70 """ Update environment (os.environ) and prepend a package path to var.
71 """
72 import sys, os.path
73
74 if getExternalHome():
75 path = self.getPackagePath2(name,var)
76 if path:
77 try:
78 pp = ':'+os.environ[var]
79 except KeyError:
80 pp = ''
81 os.environ[var] = path+pp
82
84 """ Update the sys.path variable for a given package by adding a given package to the PYTHONPATH.
85 It assumes that the first item in PYTHONPATH is Ganga, so the package path is added as a second item.
86 """
87 import sys, os.path
88
89 if getExternalHome():
90 path = self.getPackagePath2(name,'syspath')
91 if path:
92 sys.path.insert(1,path)
93
94 return True
95
97 """
98 Update environment (os.environ) and *set* (overwrite) a package path to var.
99 """
100 import sys, os
101
102 if getExternalHome():
103 path = self.getPackagePath2(name,var)
104 if path:
105 os.environ[var] = path
106
107 return True
108
110
111 """Function to check that the Python version number is greater
112 than the minimum required.
113
114 Arguments:
115 minVersion - String representation of minimum version required
116 minHexVersion - Hexadecimal representation of minimum version required
117
118 Return value: True if Python version number is greater than minimum,
119 False otherwise"""
120
121 import sys
122
123 status = True
124
125 if sys.hexversion < minHexVersion:
126 print "ERROR: Ganga requires Python version %s or greater"\
127 % str( minVersion )
128 print "ERROR: Currently using Python %s" % sys.version.split()[ 0 ]
129 status = False
130
131 return status
132
133
134
135
136
137 _new_platform=None
152
159
160 -def setExternalHome(externalHome):
161 """
162 Set the dir hosting the external packages
163 """
164 import Ganga
165 Ganga.PACKAGE._defaultExternalHome = externalHome
166
168 """
169 Returns the current external home directory set for Ganga
170 """
171 from Ganga.PACKAGE import _defaultExternalHome
172 return _defaultExternalHome
173