(file) Return to localize.py CVS log (file) (dir) Up to [Development] / JSOC

  1 arta  1.1 #!/home/jsoc/bin/linux_x86_64/activepython
  2           
  3           import os.path
  4           import sys
  5           import getopt
  6           import re
  7           from subprocess import check_output, CalledProcessError
  8           
  9           # Constants
 10           VERS_FILE = 'jsoc_version.h'
 11           SDP_CFG = 'configsdp.txt'
 12           NET_CFG = 'config.local'
 13           NET_CFGMAP = 'config.local.map'
 14           RET_SUCCESS = 0
 15           RET_NOTDRMS = 1
 16           
 17 arta  1.2 PREFIX = """# This file was auto-generated by localize.py. Please do not edit it directly (running
 18           # configure will run localize.py, which will then overwrite any edits manually performed).
 19           """
 20 arta  1.1 
 21 arta  1.2 C_PREFIX = """/* This file was auto-generated by localize.py. Please do not edit it directly (running
 22            * configure will run localize.py, which will then overwrite any edits manually performed). */
 23 arta  1.1 """
 24           
 25 arta  1.2 PERL_BINPATH = '#!/usr/bin/perl\n'
 26           
 27           PERL_INTIAL = """package drmsparams;
 28               
 29           use warnings;
 30           use strict;
 31           """
 32           
 33           PERL_FXNS_A = """sub new
 34 arta  1.1 {
 35               my($clname) = shift;
 36               
 37               my($self) = 
 38               {
 39                   _paramsH => undef
 40               };
 41               
 42               bless($self, $clname);
 43               $self->{_paramsH} = $self->initialize();
 44               
 45               return $self;
 46           }
 47               
 48           sub DESTROY
 49           {
 50               my($self) = shift;
 51           }
 52 arta  1.2 """
 53           
 54           PERL_FXNS_B = """sub get
 55           {
 56               my($self) = shift;
 57               my($name) = shift;
 58               my($rv);
 59 arta  1.1     
 60 arta  1.2     if (exists($self->{_paramsH}->{$name}))
 61               {
 62                   return $self->{_paramsH}->{$name};
 63               }
 64               else
 65               {
 66                   return undef;
 67               }
 68           }
 69           1;"""
 70 arta  1.1 
 71 arta  1.3 ICC_MAJOR = 9
 72           ICC_MINOR = 0
 73           GCC_MAJOR = 3
 74           GCC_MINOR = 0
 75           IFORT_MAJOR = 9
 76           IFORT_MINOR = 0
 77           GFORT_MAJOR = 4
 78           GFORT_MINOR = 2
 79           
 80           
 81 arta  1.1 # Read arguments
 82           #  d - localization directory
 83           #  b - base name of all parameter files (e.g., -b drmsparams --> drmsparams.h, drmsparams.mk, drmsparams.pm, etc.)
 84           #  m - make file
 85           def GetArgs(args):
 86               rv = bool(0)
 87               optD = {}
 88               
 89               try:
 90                   opts, remainder = getopt.getopt(args, "hd:b:",["dir=", "base="])
 91               except getopt.GetoptError:
 92                   print('Usage:')
 93                   print('localize.py [-h] -d <localization directory> -b <parameter file base>')
 94                   rv = bool(1)
 95               
 96               if rv == bool(0):
 97                   for opt, arg in opts:
 98                       if opt == '-h':
 99                           print('localize.py [-h] -d <localization directory> -b <parameter file base>')
100                       elif opt in ("-d", "--dir"):
101                           regexp = re.compile(r"(\S+)/?")
102 arta  1.1                 matchobj = regexp.match(arg)
103                           if matchobj is None:
104                               rv = bool(1)
105                           else:
106                               optD['dir'] = matchobj.group(1)
107                       elif opt in ("-b", "--base"):
108                           optD['base'] = arg
109                       else:
110                           optD[opt] = arg
111           	
112               return optD
113           
114           def createMacroStr(key, val, keyColLen, status):
115               if keyColLen < len(key):
116                   status = bool(1)
117                   return None
118               else:
119                   nsp = keyColLen - len(key)
120                   spaces = str()
121                   for isp in range(nsp):
122                       spaces += ' '
123 arta  1.1         status = bool(0)
124                   return '#define ' + key + spaces + val + '\n'
125           
126           def createPerlConst(key, val, keyColLen, status):
127               if keyColLen < len(key):
128                   status = bool(1)
129                   return None
130               else:
131                   nsp = keyColLen - len(key)
132                   spaces = str()
133                   for isp in range(nsp):
134                       spaces += ' '
135                   status = bool(0)
136                   return 'use constant ' + key + ' => ' + spaces + val + ';\n'
137           
138 arta  1.3 def isSupportedPlat(plat):
139               regexp = re.compile(r"\s*(^x86_64|^ia32|^ia64|^avx)", re.IGNORECASE)
140               matchobj = regexp.match(plat);
141                   
142               if not matchobj is None:
143                   return bool(1);
144               else:
145                   return bool(0);
146           
147           def processMakeParam(mDefs, key, val, platDict, matchDict):
148               varMach = None
149               regexp = re.compile(r"(\S+):(\S+)")
150               matchobj = regexp.match(key)
151               if not matchobj is None:
152                   varName = matchobj.group(1)
153                   varMach = matchobj.group(2)
154               else:
155                   varName = key
156               
157               varValu = val
158                   
159 arta  1.3     if varMach is None:
160                   mDefs.extend(list('\n' + varName + ' = ' + varValu))
161               else:
162                   if isSupportedPlat(varMach):
163                       # The guard will compare varValu to $JSOC_MACHINE.
164                       if not varMach in platDict:
165                           platDict[varMach] = {}
166                       platDict[varMach][varName] = varValu
167                   else:
168                       # The guard will compare varValu to $MACHINETYPE (this is just the hostname of the machine on which localize.py is running).
169                       if not varMach in machDict:
170                           machDict[varMach] = {}
171                       machDict[varMach][varName] = varValu
172           
173 arta  1.4 def processParam(cfgfile, line, regexpComm, regexpDefs, regexpMake, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, platDict, machDict, section):
174 arta  1.1     status = 0
175               
176               matchobj = regexpComm.match(line)
177               if not matchobj is None:
178                   # Skip comment line
179                   return bool(0)
180               
181               matchobj = regexpDefs.match(line)
182               if not matchobj is None:
183 arta  1.3         del section[:]
184 arta  1.1         section.extend(list('defs'))
185                   return bool(0)
186               
187               matchobj = regexpMake.match(line)
188               if not matchobj is None:
189 arta  1.3         del section[:]
190                   section.extend(list('make'))
191                   return bool(0)
192 arta  1.1             
193               if ''.join(section) == 'defs' or not cfgfile:
194                   matchobj = regexp.match(line)
195                   if not matchobj is None:
196                       # We have a key-value line
197                       keyCfgSp = matchobj.group(1)
198                       val = matchobj.group(2)
199                       
200                       # Must map the indirect name to the actual name
201                       if keymap:
202                           # Map to actual name only if the keymap is not empty (which signifies NA).
203                           if keyCfgSp in keymap:
204                               key = keymap[keyCfgSp]
205                           elif keyCfgSp == 'LOCAL_CONFIG_SET' or keyCfgSp == 'DRMS_SAMPLE_NAMESPACE':
206                               # Ignore parameters that are not useful and shouldn't have been there in the first place
207                               return bool(0)
208                           elif not cfgfile:
209                               # Should not be doing mapping for addenda
210                               key = keyCfgSp
211                           else:
212                               raise Exception('badKeyMapKey', keyCfgSp)
213 arta  1.1             else:
214                           key = keyCfgSp
215                       
216                       matchobj = regexpQuote.match(key)
217                       if not matchobj is None:
218                           quote = matchobj.group(1)
219                           key = matchobj.group(2)
220           
221                           # master defs dictionary
222                           defs[key] = val
223                           
224                           # C header file
225                           if quote == "q":
226                               # Add double-quotes
227                               cDefs.extend(list(createMacroStr(key, '"' + val + '"', 40, status)))
228                           elif quote == "p":
229                               # Add parentheses
230                               cDefs.extend(list(createMacroStr(key, '(' + val + ')', 40, status)))
231                           elif quote == "a":
232                               # Leave as-is
233                               cDefs.extend(list(createMacroStr(key, val, 40, status)))
234 arta  1.1                 else:
235                               # Unknown quote type
236                               raise Exception('badQuoteQual', key)
237                           
238                           if status:
239                               raise Exception('paramNameTooLong', key)
240                           
241                           # Make file - val should never be quoted; just use as is
242 arta  1.4                 mDefsGen.extend(list('\n' + key + ' = ' + val))
243 arta  1.1                 
244                           # Perl file - val should ALWAYS be single-quote quoted
245                           # Save const info to a string
246                           perlConstSection.extend(list(createPerlConst(key, "'" + val + "'", 40, status)))
247                           
248                           if status:
249                               raise Exception('paramNameTooLong', key)
250                           
251                           # Save initialization information as a string. Now that we've defined
252                           # constants (the names of which are the parameter names) 
253                           # we can refer to those in the init section. The key variable holds the
254                           # name of the constant.
255 arta  1.2                 perlInitSection.extend(list('\n  $self->{_paramsH}->{' + key + '} = ' + "'" + val + "';"))
256 arta  1.1             else:
257                           # No quote qualifier
258                           raise Exception('missingQuoteQual', key)
259 arta  1.3     elif ''.join(section) == 'make' and cfgfile:
260                   # Configure the remaining make variables defined in the __MAKE__ section of the configuration file. Third-party
261                   # library make variables are specified in the __MAKE__ section.
262                   matchobj = regexp.match(line)
263                   if not matchobj is None:
264                       # We have a key-value line
265                       key = matchobj.group(1)
266                       val = matchobj.group(2)
267           
268                       # This information is for making make variables only. We do not need to worry about quoting any values
269                       defs[key] = val
270 arta  1.4             processMakeParam(mDefsMake, key, val, platDict, machDict)
271 arta  1.1     
272               return bool(0)
273           
274           # We have some extraneous line or a newline - ignore.
275           
276           # defs is a dictionary containing all parameters (should they be needed in this script)
277 arta  1.4 def parseConfig(fin, keymap, addenda, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection):
278 arta  1.1     rv = bool(0)
279               
280               # Open required config file (config.local)
281               try:
282                   # Examine each line, looking for key=value pairs.
283                   regexpDefs = re.compile(r"^__DEFS__")
284                   regexpMake = re.compile(r"^__MAKE__")
285                   regexpComm = re.compile(r"^\s*#")
286                   regexpQuote = re.compile(r"^\s*(\w):(.+)")
287 arta  1.3         regexp = re.compile(r"^\s*(\S+)\s+(\S+)")
288 arta  1.1         
289 arta  1.3         platDict = {}
290                   machDict = {}
291 arta  1.1         section = list()
292                   
293                   # Process the parameters in the configuration file
294                   iscfg = bool(1)
295                   if not fin is None:
296                       for line in fin:
297 arta  1.4                 ppRet = processParam(iscfg, line, regexpComm, regexpDefs, regexpMake, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, platDict, machDict, section)
298 arta  1.1                 if ppRet:
299                               break;
300                       
301                   # Process addenda - these are parameters that are not configurable and must be set in the 
302                   # NetDRMS build.
303                   iscfg = bool(0)
304                   for key in addenda:
305                       item = key + ' ' + addenda[key]
306 arta  1.4             ppRet = processParam(iscfg, item, regexpComm, regexpDefs, regexpMake, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, platDict, machDict, section)
307 arta  1.1             if ppRet:
308                           break;
309               except Exception as exc:
310                   msg, violator = exc.args
311                   if msg == 'badKeyMapKey':
312                       # If we are here, then there was a non-empty keymap, and the parameter came from
313                       # the configuration file.
314                       print('Unknown parameter name ' + "'" + violator + "'" + ' in ' + cfgfile + '.', file=sys.stderr)
315                       rv = bool(1)
316                   elif msg == 'badQuoteQual':
317                       # The bad quote qualifier came from the configuration file, not the addenda, since
318                       # we will have fixed any bad qualifiers in the addenda (which is populated by code).
319                       print('Unknown quote qualifier ' + "'" + violator + "'" + ' in ' + cfgfile + '.', file=sys.stderr)
320                       rv = bool(1)
321                   elif msg == 'missingQuoteQual':
322                       print('Missing quote qualifier for parameter ' + "'" + violator + "'" + ' in ' + cfgfile + '.', file=sys.stderr)
323                       rv = bool(1)
324                   elif msg == 'paramNameTooLong':
325                       print('Macro name ' + "'" + violator + "' is too long.", file=sys.stderr)
326                       rv = bool(1)
327                   else:
328 arta  1.1             # re-raise the exception
329                       raise
330           
331 arta  1.4     # Put information collected in platDict and machDict into mDefs. Must do this here, and not in processParam, since
332               # we need to parse all platform-specific make variables before grouping them into platform categories.
333 arta  1.3     if not rv:
334                   for plat in platDict:
335 arta  1.4             mDefsMake.extend(list('\nifeq ($(JSOC_MACHINE), linux_' + plat.lower() + ')'))
336 arta  1.3             for var in platDict[plat]:
337 arta  1.4                 mDefsMake.extend(list('\n' + var + ' = ' + platDict[plat][var]))
338                       mDefsMake.extend(list('\nendif\n'))
339 arta  1.3                              
340               if not rv:
341                   for mach in machDict:
342 arta  1.4             mDefsMake.extend(list('\nifeq ($(MACHTYPE), ' + mach + ')'))
343 arta  1.3             for var in platDict[plat]:
344 arta  1.4                 mDefsMake.extend(list('\n' + var + ' = ' + platDict[plat][var]))
345                       mDefsMake.extend(list('\nendif\n'))
346 arta  1.3                              
347 arta  1.1     return rv
348           
349           def getMgrUIDLine(defs, uidParam):
350               rv = bool(0)
351               
352               cmd = 'id -u ' + defs['SUMS_MANAGER']
353               try:
354                   ret = check_output(cmd, shell=True)
355                   uidParam['q:SUMS_MANAGER_UID'] = ret.decode("utf-8")
356               except ValueError:
357                   print('Unable to run cmd: ' + cmd + '.')
358                   rv = bool(1)
359               except CalledProcessError:
360                   print('Command ' + "'" + cmd + "'" + ' ran improperly.')
361                   rv = bool(1)
362           
363               return rv
364           
365 arta  1.3 def isVersion(maj, min, majDef, minDef):
366               res = 0
367               
368               if maj > majDef or (maj == majDef and min >= minDef):
369                   res = 1
370               
371               return res
372           
373           def configureComps(defs, mDefs):
374               rv = bool(0)
375               autoConfig = (not defs['AUTOSELCOMP'] == '0')
376               
377               if autoConfig:
378                   hasicc = bool(0)
379                   hasgcc = bool(0)
380                   hasifort = bool(0)
381                   hasgfort = bool(0)
382                   
383                   # Try icc.
384                   cmd = 'icc -V 2>&1'
385                   try:
386 arta  1.3             ret = check_output(cmd, shell=True)
387                       ret = ret.decode("utf-8")
388                   except CalledProcessError:
389                       print('Command ' + "'" + cmd + "'" + ' ran improperly.')
390                       rv = bool(1)
391                   
392                   if rv == bool(0):
393                       regexp = re.compile(r".+Version\s+(\d+)[.](\d+)", re.DOTALL)
394                       matchobj = regexp.match(ret)
395                       if matchobj is None:
396                           raise Exception('unexpectedIccRet', ret)
397                       else:
398                           major = matchobj.group(1)
399                           minor = matchobj.group(2)
400                           if isVersion(int(major), int(minor), ICC_MAJOR, ICC_MINOR):
401                               hasicc = bool(1)
402                       
403                   # Try gcc.
404                   if not hasicc:
405                       cmd = 'gcc -v 2>&1'
406                       try:
407 arta  1.3                 ret = check_output(cmd, shell=True)
408                           ret = ret.decode("utf-8")
409                       except CalledProcessError:
410                           print('Command ' + "'" + cmd + "'" + ' ran improperly.')
411                           rv = bool(1)
412           
413                       if rv == bool(0):
414                           regexp = re.compile(r".+gcc\s+version\s+(\d+)\.(\d+)", re.DOTALL)
415                           matchobj = regexp.match(ret)
416                           if matchobj is None:
417                               raise Exception('unexpectedGccRet', ret)
418                           else:
419                               major = matchobj.group(1)
420                               minor = matchobj.group(2)
421                               if isVersion(int(major), int(minor), GCC_MAJOR, GCC_MINOR):
422                                   hasgcc = bool(1)
423           
424                   # Try ifort.
425                   cmd = 'ifort -V 2>&1'
426                   try:
427                       ret = check_output(cmd, shell=True)
428 arta  1.3             ret = ret.decode("utf-8")
429                   except CalledProcessError:
430                       print('Command ' + "'" + cmd + "'" + ' ran improperly.')
431                       rv = bool(1)
432           
433                   if rv == bool(0):
434                       regexp = re.compile(r".+Version\s+(\d+)\.(\d+)", re.DOTALL)
435                       matchobj = regexp.match(ret)
436                       if matchobj is None:
437                           raise Exception('unexpectedIfortRet', ret)
438                       else:
439                           major = matchobj.group(1)
440                           minor = matchobj.group(2)
441                           if isVersion(int(major), int(minor), IFORT_MAJOR, IFORT_MINOR):
442                               hasifort = bool(1)
443                   
444                   # Try gfortran
445                   if not hasifort:
446                       cmd = 'gfortran -v 2>&1'
447                       try:
448                           ret = check_output(cmd, shell=True)
449 arta  1.3                 ret = ret.decode("utf-8")
450                       except CalledProcessError:
451                           print('Command ' + "'" + cmd + "'" + ' ran improperly.')
452                           rv = bool(1)
453           
454                       if rv == bool(0):
455                           regexp = re.compile(r".+gcc\s+version\s+(\d+)\.(\d+)", re.DOTALL)
456                           matchobj = regexp.match(ret)
457                           if matchobj is None:
458                               raise Exception('unexpectedGfortranRet', ret)
459                           else:
460                               major = matchobj.group(1)
461                               minor = matchobj.group(2)
462                               if isVersion(int(major), int(minor), GFORT_MAJOR, GFORT_MINOR):
463                                   hasgfort = bool(1)
464                   
465                   # Append the compiler make variables to the make file 
466                   if not hasicc and not hasgcc:
467                       print('Fatal error: Acceptable C compiler not found! You will be unable to build the DRMS library.', file=sys.stderr)
468                       rv = bool(1)
469                   elif hasicc:
470 arta  1.3             mDefs.extend(list('\nCOMPILER = icc'))
471                   else:
472                       mDefs.extend(list('\nCOMPILER = gcc'))
473           
474                   if not hasifort and not hasgfort:
475                       print('Warning: Acceptable Fortran compiler not found! Fortran interface will not be built, and you will be unable to build Fortran modules.', file=sys.stderr)
476                   elif hasifort:
477                       mDefs.extend(list('\nFCOMPILER = ifort'))
478                   else:
479                       mDefs.extend(list('\nFCOMPILER = gfortran'))
480               
481                   # Environment overrides. These get written, regardless of the disposition of auto-configuration.
482                   mDefs.extend(list('\nifneq $(JSOC_COMPILER,)\n  COMPILER = $(JSOC_COMPILER)\nendif'))
483                   mDefs.extend(list('\nifneq $(JSOC_FCOMPILER,)\n  FCOMPILER = $(JSOC_FCOMPILER)\nendif'))
484           
485               return rv
486           
487 arta  1.4 def writeFiles(base, cfile, mfile, pfile, cDefs, mDefsGen, mDefsMake, mDefsComps, perlConstSection, perlInitSection):
488 arta  1.1     rv = bool(0)
489 arta  1.4 
490               # Merge mDefsGen, mDefsMake, and mDefsComps into a single string with compiler configuration first, general parameters next, then
491               # make-specific make variables (e.g., third-party library information) last.
492               mDefs = '\n# Compiler Selection\n' + ''.join(mDefsComps) + '\n\n# General Parameters\n' + ''.join(mDefsGen) + '\n\n# Parameters to Configure make\n' + ''.join(mDefsMake)
493 arta  1.1     
494               try:
495                   with open(cfile, 'w') as cout, open(mfile, 'w') as mout, open(pfile, 'w') as pout:
496                       # C file of macros
497 arta  1.2             print(C_PREFIX, file=cout)
498                       print('/* This file contains a set of preprocessor macros - one for each configuration parameter. */\n', file=cout)
499 arta  1.1             buf = '__' + base.upper() + '_H'
500                       print('#ifndef ' + buf, file=cout)
501                       print('#define ' + buf, file=cout)
502                       print(''.join(cDefs), file=cout)
503                       print('#endif', file=cout)
504                       
505                       # Make file of make variables
506 arta  1.2             print(PREFIX, file=mout)
507 arta  1.4             print('# This file contains a set of make-variable values. The first section contains compiler-selection variables, the second contains general configuration variables, and the third section contains variables that configure how make is run.', file=mout)
508                       print(mDefs, file=mout)
509 arta  1.1             
510 arta  1.2             # Perl module
511                       print(PERL_BINPATH, file=pout)
512                       print(PREFIX, file=pout)
513                       print('# This file contains a set of constants - one for each configuration parameter.\n', file=pout)
514                       print(PERL_INTIAL, file=pout)
515 arta  1.1             print(''.join(perlConstSection), file=pout)
516 arta  1.2             print(PERL_FXNS_A, file=pout)
517 arta  1.1             print('sub initialize', file=pout)
518                       print('{', file=pout)
519 arta  1.2             print('  my($self) = shift;', file=pout, end='')
520 arta  1.1             print('', file=pout)
521                       print(''.join(perlInitSection), file=pout)
522 arta  1.2             print('}\n', file=pout)
523                       print(PERL_FXNS_B, file=pout)
524 arta  1.1     except IOError as exc:
525                   sys.stderr.write(exc.strerror)
526                   sys.stderr.write('Unable to open a parameter vile.')
527                   rv = bool(1)
528           
529               return rv
530 arta  1.3 
531 arta  1.2 def configureNet(cfgfile, cfile, mfile, pfile, base, keymap):
532 arta  1.1     rv = bool(0)
533               
534               defs = {}
535               cDefs = list()
536               mDefs = list()
537 arta  1.4     mDefsGen = list()
538               mDefsMake = list()
539               mDefsComps = list()
540 arta  1.1     perlConstSection = list()
541               perlInitSection = list()
542 arta  1.2     addenda = {}
543               
544               # There are three parameters that are not configurable and must be set.
545               addenda['a:USER'] = 'NULL'
546               addenda['a:PASSWD'] = 'NULL'
547               addenda['p:DSDS_SUPPORT'] = '0'
548               addenda['a:BUILD_TYPE'] = 'NETDRMS' # Means a non-Stanford build. This will set two additional macros used by make:
549                                                   #   __LOCALIZED_DEFS__ and NETDRMS_BUILD. The former is to support legacy code
550                                                   #   which incorrectly used this macro, and the latter is for future use. 
551                                                   #   __LOCALIZED_DEFS__ is deprecated and should not be used in new code.
552 arta  1.1 
553               try:
554                   with open(cfgfile, 'r') as fin:
555 arta  1.3             # Process configuration parameters
556 arta  1.4             rv = parseConfig(fin, keymap, addenda, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection)
557 arta  1.1             if rv == bool(0):
558 arta  1.3                 # Must add a parameter for the SUMS_MANAGER UID (for some reason). This must be done after the
559                           # config file is processed since an input to getMgrUIDLine() is one of the config file's
560                           # parameter values.
561 arta  1.1                 uidParam = {}
562                           rv = getMgrUIDLine(defs, uidParam)
563                           if rv == bool(0):
564 arta  1.4                     rv = parseConfig(None, keymap, uidParam, defs, cDefs, mDefsGen, None, perlConstSection, perlInitSection)
565 arta  1.3                 
566                       # Configure the compiler-selection make variables.
567                       if rv == bool(0):
568 arta  1.4                 rv = configureComps(defs, mDefsComps)
569 arta  1.1 
570 arta  1.3             # Write out the parameter files.
571                       if rv == bool(0):
572 arta  1.4                 rv = writeFiles(base, cfile, mfile, pfile, cDefs, mDefsGen, mDefsMake, mDefsComps, perlConstSection, perlInitSection)
573 arta  1.1     except IOError as exc:
574                   sys.stderr.write(exc.strerror)
575                   sys.stderr.write('Unable to read configuration file ' + cfgfile + '.')
576 arta  1.3     except Exception as exc:
577                   type, msg = exc.args
578                   if type == 'unexpectedIccRet':
579                       print('icc -V returned this unexpected message:\n' + msg, file=sys.stderr)
580                       rv = bool(1)
581                   elif type == 'unexpectedGccRet':
582                       print('gcc -v returned this unexpected message:\n' + msg, file=sys.stderr)
583                       rv = bool(1)
584                   elif type == 'unexpectedIfortRet':
585                       print('ifort -V returned this unexpected message:\n' + msg, file=sys.stderr)
586                       rv = bool(1)
587                   elif type == 'unexpectedGfortranRet':
588                       print('gfortran -v returned this unexpected message:\n' + msg, file=sys.stderr)
589                       rv = bool(1)
590                   else:
591                       # re-raise the exception
592                       raise
593 arta  1.1         
594 arta  1.2     return rv
595 arta  1.1 
596 arta  1.2 def configureSdp(cfgfile, cfile, mfile, pfile, base, keymap):
597 arta  1.1     rv = bool(0)
598               
599               defs = {}
600               cDefs = list()
601 arta  1.5     mDefsGen = list()
602               mDefsMake = list()
603               mDefsComps = list()
604 arta  1.1     perlConstSection = list()
605               perlInitSection = list()
606 arta  1.2     addenda = {}
607               
608 arta  1.5     addenda['a:USER'] = 'NULL'
609               addenda['a:PASSWD'] = 'NULL'
610               addenda['p:DSDS_SUPPORT'] = '1'
611               addenda['a:BUILD_TYPE'] = 'JSOC_SDP' # Means a Stanford build. This will set one additional macro used by make: JSOC_SDP_BUILD.
612 arta  1.1     
613               try:
614                   with open(cfgfile, 'r') as fin:
615 arta  1.5             rv = parseConfig(cfgfile, keymap, addenda, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection)
616 arta  1.1             if rv == bool(0):
617 arta  1.2                 # Must add a parameter for the SUMS_MANAGER UID (for some reason)
618                           uidParam = {}
619                           rv = getMgrUIDLine(defs, uidParam)
620                           if rv == bool(0):
621 arta  1.5                     rv = parseConfig(None, keymap, uidParam, defs, cDefs, mDefsGen, NONE, perlConstSection, perlInitSection)
622 arta  1.2                 
623 arta  1.5                 # Configure the compiler-selection make variables.
624                           if rv == bool(0):
625                               rv = configureComps(defs, mDefsComps)
626 arta  1.3                 
627                           if rv == bool(0):
628 arta  1.5                     rv = writeFiles(base, cfile, mfile, pfile, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection)
629 arta  1.1     except IOError as exc:
630                   sys.stderr.write(exc.strerror)
631                   sys.stderr.write('Unable to read configuration file ' + cfgfile + '.')
632 arta  1.5     except Exception as exc:
633                   type, msg = exc.args
634                   if type == 'unexpectedIccRet':
635                       print('icc -V returned this unexpected message:\n' + msg, file=sys.stderr)
636                       rv = bool(1)
637                   elif type == 'unexpectedGccRet':
638                       print('gcc -v returned this unexpected message:\n' + msg, file=sys.stderr)
639                       rv = bool(1)
640                   elif type == 'unexpectedIfortRet':
641                       print('ifort -V returned this unexpected message:\n' + msg, file=sys.stderr)
642                       rv = bool(1)
643                   elif type == 'unexpectedGfortranRet':
644                       print('gfortran -v returned this unexpected message:\n' + msg, file=sys.stderr)
645                       rv = bool(1)
646                   else:
647                       # re-raise the exception
648                       raise
649                   
650 arta  1.2     return rv
651           
652 arta  1.1 # Beginning of program
653           rv = RET_SUCCESS
654           net = bool(1)
655           
656           # Parse arguments
657           if __name__ == "__main__":
658               optD = GetArgs(sys.argv[1:])
659           
660           if not(optD is None):
661               # Ensure we are configuring a DRMS tree
662               cdir = os.path.realpath(os.getcwd())
663               versfile = cdir + '/base/' + VERS_FILE
664           
665               if not os.path.isfile(versfile):
666                   rv = RET_NOTDRMS
667           
668           # Determine whether we are localizing a Stanford build, or a NetDRMS build. If configsdp.txt exists, then
669           # it is a Stanford build, otherwise it is a NetDRMS build.
670           if rv == RET_SUCCESS:
671               stanfordFile = cdir + '/' + SDP_CFG
672               if os.path.isfile(stanfordFile):
673 arta  1.1         net = bool(0)
674               
675               cfile = optD['dir'] + '/' + optD['base'] + '.h'
676               mfile = optD['dir'] + '/' + optD['base'] + '.mk'
677               pfile = optD['dir'] + '/' + optD['base'] + '.pm'
678           
679               if net:
680                   try:
681                       with open(NET_CFGMAP, 'r') as fin:
682                           regexpComm = re.compile(r"^\s*#")
683                           regexp = re.compile(r"^\s*(\S+)\s+(\w:\S+)")
684                           # Must map from config.local namespace to DRMS namespace (e.g., the names used for the C macros)
685                           keymap = {}
686                           for line in fin:
687                               matchobj = regexpComm.match(line)
688                               if not matchobj is None:
689                                   # Skip comment line
690                                   continue
691           
692                               matchobj = regexp.match(line)
693                               if not(matchobj is None):
694 arta  1.1                         # We have a key-value line
695                                   key = matchobj.group(1)
696                                   val = matchobj.group(2)
697                                   keymap[key] = val
698                   except OSError:
699                       sys.stderr.write('Unable to read configuration map-file ' + NET_CFGMAP + '.')
700                       rv = bool(1)
701                       
702 arta  1.2         
703 arta  1.1 
704                   # We also need to set the UID of the SUMS manager. We have the name of the
705                   # SUMS manager (it is in the configuration file)
706 arta  1.2         configureNet(NET_CFG, cfile, mfile, pfile, optD['base'], keymap)
707 arta  1.1     else:
708 arta  1.2         configureSdp(SDP_CFG, cfile, mfile, pfile, optD['base'], {})
709 arta  1.1     
710               
711           

Karen Tian
Powered by
ViewCVS 0.9.4