Package Ganga :: Package Utility :: Module Setup
[hide private]
[frames] | no frames]

Source Code for Module Ganga.Utility.Setup

  1   
2 -class PackageSetup:
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 """
6 - def __init__(self,packages):
7 """ 8 Initialize the Package object with the list of required external packages 9 """ 10 self.packages = packages
11
12 - def getPackagePath(self,name,force=False):
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
44 - def getPackagePath2(self,name,var,force=False):
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 ## for p in ppath: 64 ## result += os.path.join(path,p) 65 ## return result 66 else: 67 return ''
68
69 - def prependPath(self,name,var):
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
83 - def setSysPath(self,name):
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
96 - def setPath(self,name,var):
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
109 -def checkPythonVersion(minVersion, minHexVersion):
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 ### Override the default guessed platform and external dir 135 #save the first update request to detect conflicts generated by 136 #two Ganga packages setting a different platform 137 _new_platform=None
138 -def setPlatform(platform):
139 """ 140 Override globally the auto-detected platform string 141 """ 142 global _new_platform 143 144 if _new_platform and _new_platform != platform: 145 raise RuntimeError("Ganga platform has been already set to: %s" % str(_new_platform)) 146 # change the global platform used in bootstrap 147 import Ganga 148 if Ganga.PACKAGE._defaultPlatform != platform: 149 print 'The platform identification string (%s) used to resolve Ganga dependencies has been explicitly set to: %s.'\ 150 % (Ganga.PACKAGE._defaultPlatform, platform) 151 Ganga.PACKAGE._defaultPlatform =_new_platform = platform
152
153 -def getPlaftorm():
154 """ 155 Returns the current platform string set for Ganga 156 """ 157 from Ganga.PACKAGE import _defaultPlatform 158 return _defaultPlatform
159
160 -def setExternalHome(externalHome):
161 """ 162 Set the dir hosting the external packages 163 """ 164 import Ganga 165 Ganga.PACKAGE._defaultExternalHome = externalHome
166
167 -def getExternalHome():
168 """ 169 Returns the current external home directory set for Ganga 170 """ 171 from Ganga.PACKAGE import _defaultExternalHome 172 return _defaultExternalHome 173