1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from Ganga.Utility.util import importName
17
18 from Ganga.Utility.external.ordereddict import oDict
19 allRuntimes = oDict()
20
21 import Ganga.Utility.logging
22 logger = Ganga.Utility.logging.getLogger(modulename=1)
23
25 """Determine path to a script
26
27 Arguments:
28 name - Name of a script
29 searchPath - String of colon-separated directory names,
30 defining locations to be searched for script
31
32 If 'name' already gives the path to the script, then
33 'searchPath' is ignored.
34
35 Return value: String giving path to script (success)
36 or empty string (script not found)"""
37
38 import os
39
40 scriptPath = ""
41
42 if name:
43 fullName = os.path.expanduser( os.path.expandvars( name ) )
44 if os.path.exists( fullName ):
45 scriptPath = fullName
46 else:
47 if searchPath:
48 script = os.path.basename( fullName )
49 pathList = searchPath.split( ":" )
50 for directory in pathList :
51 if os.path.isdir( directory ):
52 dirPath = os.path.abspath( directory )
53 if script in os.listdir( dirPath ):
54 scriptPath = os.sep.join( [ dirPath, script ] )
55 break
56
57 return scriptPath
58
60 """Determine search path from configuration parameter
61
62 Argument:
63 configPar : Name of configuration parameter defining search path
64
65 Return value: Search path"""
66
67 import os
68 from Ganga.Utility.Config import Config, ConfigError, getConfig
69
70 config = getConfig( "Configuration" )
71
72 utilityDir = os.path.dirname( os.path.abspath( __file__ ) )
73 gangaRoot = os.path.dirname( os.path.dirname( utilityDir ) )
74
75 pathString1 = ""
76 if configPar:
77 try:
78 pathString1 = str( config[ configPar ] )
79 except ConfigError:
80 logger.error( "Option '%s' not defined in 'Configuration'" % \
81 configPar )
82
83
84 pathList1 = ['.']+pathString1.split( ":" )
85 pathList2 = []
86
87 for path in pathList1:
88 if ( "." != path ):
89 path = os.path.expanduser( os.path.expandvars( path ) )
90 if ( 0 != path.find( "/" ) ):
91 path = os.path.join( gangaRoot, path )
92 pathList2.append( path )
93
94 pathString2 = ":".join( pathList2 )
95 return pathString2
96
99 import os.path,sys
100 import Ganga.Utility.Config
101
102 self.path = os.path.normpath(path.rstrip('/'))
103 self.name = os.path.basename(self.path)
104 self.syspath = os.path.dirname(self.path)
105 self.mod = None
106 self.modpath = ''
107
108 showpath = self.syspath
109 if not showpath:
110 showpath = '<defaultpath>'
111 logger.info("initializing runtime: '%s' '%s'",self.name,showpath)
112
113 if allRuntimes.has_key(self.name):
114 if allRuntimes[self.name].path != self.path:
115 logger.warning('possible clash: runtime "%s" already exists at path "%s"',self.name,allRuntimes[self.name].path)
116
117 allRuntimes[self.name] = self
118
119 if self.syspath:
120
121
122 if not os.path.isabs(self.syspath):
123 self.syspath = os.path.join(Ganga.Utility.Config.getConfig('System')['GANGA_PYTHONPATH'], self.syspath)
124 sys.path.insert(0,self.syspath)
125
126 self.config = {}
127
128 try:
129 self.mod = __import__(self.name)
130 self.modpath = os.path.dirname(os.path.normpath(os.path.abspath(self.mod.__file__)))
131 if self.syspath:
132 if self.modpath.find(self.syspath) == -1:
133 logger.warning("runtime '%s' imported from '%s' but specified path is '%s'. You might be getting different code than expected!",self.name,self.modpath,self.syspath)
134 else:
135 logger.info("runtime package %s imported from %s",self.name,self.modpath)
136
137
138
139
140
141 __import__(self.name+".PACKAGE")
142
143 except ImportError,x:
144 logger.warning("cannot import runtime package %s: %s",self.name,str(x))
145
154
160
162 try:
163 import os.path
164
165
166
167
168
169
170 exec("import %s.BOOT"%self.name)
171 except ImportError, x:
172 logger.debug("problems with bootstrap of runtime package %s",self.name)
173 logger.debug(x)
174 except IOError,x:
175 logger.debug("problems with bootstrap of runtime package %s",self.name)
176 logger.debug(x)
177
179 try:
180 import os.path
181 execfile( os.path.join( self.modpath, 'TEMPLATES.py' ), globals )
182 except IOError, x:
183 logger.debug\
184 ( "Problems adding templates for runtime package %s", self.name)
185 logger.debug(x)
186
192
193
195 g = importName(self.name,'postBootstrapHook')
196 if g: g()
197 else:
198 logger.debug("no postBootstrapHook() in runtime package %s",self.name)
199