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 def processParam(cfgfile, line, regexpComm, regexpDefs, regexpMake, regexpQuote, regexp, keymap, defs, cDefs, mDefs, 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.2 mDefs.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 processMakeParam(mDefs, 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.2 def parseConfig(fin, keymap, addenda, defs, cDefs, mDefs, 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.3 ppRet = processParam(iscfg, line, regexpComm, regexpDefs, regexpMake, regexpQuote, regexp, keymap, defs, cDefs, mDefs, 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.3 ppRet = processParam(iscfg, item, regexpComm, regexpDefs, regexpMake, regexpQuote, regexp, keymap, defs, cDefs, mDefs, 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.3 # Put information collected in platDict and machDict into mDefs
332 if not rv:
333 for plat in platDict:
334 mDefs.extend(list('\nifeq ($(JSOC_MACHINE), linux_' + plat.lower() + ')'))
335 for var in platDict[plat]:
336 mDefs.extend(list('\n' + var + ' = ' + platDict[plat][var]))
337 mDefs.extend(list('\nendif\n'))
338
339 if not rv:
340 for mach in machDict:
341 mDefs.extend(list('\nifeq ($(MACHTYPE), ' + mach + ')'))
342 for var in platDict[plat]:
343 mDefs.extend(list('\n' + var + ' = ' + platDict[plat][var]))
344 mDefs.extend(list('\nendif\n'))
345
|
346 arta 1.1 return rv
347
348 def getMgrUIDLine(defs, uidParam):
349 rv = bool(0)
350
351 cmd = 'id -u ' + defs['SUMS_MANAGER']
352 try:
353 ret = check_output(cmd, shell=True)
354 uidParam['q:SUMS_MANAGER_UID'] = ret.decode("utf-8")
355 except ValueError:
356 print('Unable to run cmd: ' + cmd + '.')
357 rv = bool(1)
358 except CalledProcessError:
359 print('Command ' + "'" + cmd + "'" + ' ran improperly.')
360 rv = bool(1)
361
362 return rv
363
|
364 arta 1.3 def isVersion(maj, min, majDef, minDef):
365 res = 0
366
367 if maj > majDef or (maj == majDef and min >= minDef):
368 res = 1
369
370 return res
371
372 def configureComps(defs, mDefs):
373 rv = bool(0)
374 autoConfig = (not defs['AUTOSELCOMP'] == '0')
375
376 if autoConfig:
377 hasicc = bool(0)
378 hasgcc = bool(0)
379 hasifort = bool(0)
380 hasgfort = bool(0)
381
382 # Try icc.
383 cmd = 'icc -V 2>&1'
384 try:
385 arta 1.3 ret = check_output(cmd, shell=True)
386 ret = ret.decode("utf-8")
387 except CalledProcessError:
388 print('Command ' + "'" + cmd + "'" + ' ran improperly.')
389 rv = bool(1)
390
391 if rv == bool(0):
392 regexp = re.compile(r".+Version\s+(\d+)[.](\d+)", re.DOTALL)
393 matchobj = regexp.match(ret)
394 if matchobj is None:
395 raise Exception('unexpectedIccRet', ret)
396 else:
397 major = matchobj.group(1)
398 minor = matchobj.group(2)
399 if isVersion(int(major), int(minor), ICC_MAJOR, ICC_MINOR):
400 hasicc = bool(1)
401
402 # Try gcc.
403 if not hasicc:
404 cmd = 'gcc -v 2>&1'
405 try:
406 arta 1.3 ret = check_output(cmd, shell=True)
407 ret = ret.decode("utf-8")
408 except CalledProcessError:
409 print('Command ' + "'" + cmd + "'" + ' ran improperly.')
410 rv = bool(1)
411
412 if rv == bool(0):
413 regexp = re.compile(r".+gcc\s+version\s+(\d+)\.(\d+)", re.DOTALL)
414 matchobj = regexp.match(ret)
415 if matchobj is None:
416 raise Exception('unexpectedGccRet', ret)
417 else:
418 major = matchobj.group(1)
419 minor = matchobj.group(2)
420 if isVersion(int(major), int(minor), GCC_MAJOR, GCC_MINOR):
421 hasgcc = bool(1)
422
423 # Try ifort.
424 cmd = 'ifort -V 2>&1'
425 try:
426 ret = check_output(cmd, shell=True)
427 arta 1.3 ret = ret.decode("utf-8")
428 except CalledProcessError:
429 print('Command ' + "'" + cmd + "'" + ' ran improperly.')
430 rv = bool(1)
431
432 if rv == bool(0):
433 regexp = re.compile(r".+Version\s+(\d+)\.(\d+)", re.DOTALL)
434 matchobj = regexp.match(ret)
435 if matchobj is None:
436 raise Exception('unexpectedIfortRet', ret)
437 else:
438 major = matchobj.group(1)
439 minor = matchobj.group(2)
440 if isVersion(int(major), int(minor), IFORT_MAJOR, IFORT_MINOR):
441 hasifort = bool(1)
442
443 # Try gfortran
444 if not hasifort:
445 cmd = 'gfortran -v 2>&1'
446 try:
447 ret = check_output(cmd, shell=True)
448 arta 1.3 ret = ret.decode("utf-8")
449 except CalledProcessError:
450 print('Command ' + "'" + cmd + "'" + ' ran improperly.')
451 rv = bool(1)
452
453 if rv == bool(0):
454 regexp = re.compile(r".+gcc\s+version\s+(\d+)\.(\d+)", re.DOTALL)
455 matchobj = regexp.match(ret)
456 if matchobj is None:
457 raise Exception('unexpectedGfortranRet', ret)
458 else:
459 major = matchobj.group(1)
460 minor = matchobj.group(2)
461 if isVersion(int(major), int(minor), GFORT_MAJOR, GFORT_MINOR):
462 hasgfort = bool(1)
463
464 # Append the compiler make variables to the make file
465 if not hasicc and not hasgcc:
466 print('Fatal error: Acceptable C compiler not found! You will be unable to build the DRMS library.', file=sys.stderr)
467 rv = bool(1)
468 elif hasicc:
469 arta 1.3 mDefs.extend(list('\nCOMPILER = icc'))
470 else:
471 mDefs.extend(list('\nCOMPILER = gcc'))
472
473 if not hasifort and not hasgfort:
474 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)
475 elif hasifort:
476 mDefs.extend(list('\nFCOMPILER = ifort'))
477 else:
478 mDefs.extend(list('\nFCOMPILER = gfortran'))
479
480 # Environment overrides. These get written, regardless of the disposition of auto-configuration.
481 mDefs.extend(list('\nifneq $(JSOC_COMPILER,)\n COMPILER = $(JSOC_COMPILER)\nendif'))
482 mDefs.extend(list('\nifneq $(JSOC_FCOMPILER,)\n FCOMPILER = $(JSOC_FCOMPILER)\nendif'))
483
484 return rv
485
|
486 arta 1.1 def writeFiles(base, cfile, mfile, pfile, cDefs, mDefs, perlConstSection, perlInitSection):
487 rv = bool(0)
488
489 try:
490 with open(cfile, 'w') as cout, open(mfile, 'w') as mout, open(pfile, 'w') as pout:
491 # C file of macros
|
492 arta 1.2 print(C_PREFIX, file=cout)
493 print('/* This file contains a set of preprocessor macros - one for each configuration parameter. */\n', file=cout)
|
494 arta 1.1 buf = '__' + base.upper() + '_H'
495 print('#ifndef ' + buf, file=cout)
496 print('#define ' + buf, file=cout)
497 print(''.join(cDefs), file=cout)
498 print('#endif', file=cout)
499
500 # Make file of make variables
|
501 arta 1.2 print(PREFIX, file=mout)
|
502 arta 1.1 print('# This file contains a set of make-variable values - one for each configuration parameter.', file=mout)
503 print(''.join(mDefs), file=mout)
504
|
505 arta 1.2 # Perl module
506 print(PERL_BINPATH, file=pout)
507 print(PREFIX, file=pout)
508 print('# This file contains a set of constants - one for each configuration parameter.\n', file=pout)
509 print(PERL_INTIAL, file=pout)
|
510 arta 1.1 print(''.join(perlConstSection), file=pout)
|
511 arta 1.2 print(PERL_FXNS_A, file=pout)
|
512 arta 1.1 print('sub initialize', file=pout)
513 print('{', file=pout)
|
514 arta 1.2 print(' my($self) = shift;', file=pout, end='')
|
515 arta 1.1 print('', file=pout)
516 print(''.join(perlInitSection), file=pout)
|
517 arta 1.2 print('}\n', file=pout)
518 print(PERL_FXNS_B, file=pout)
|
519 arta 1.1 except IOError as exc:
520 sys.stderr.write(exc.strerror)
521 sys.stderr.write('Unable to open a parameter vile.')
522 rv = bool(1)
523
524 return rv
|
525 arta 1.3
|
526 arta 1.2 def configureNet(cfgfile, cfile, mfile, pfile, base, keymap):
|
527 arta 1.1 rv = bool(0)
528
529 defs = {}
530 cDefs = list()
531 mDefs = list()
532 perlConstSection = list()
533 perlInitSection = list()
|
534 arta 1.2 addenda = {}
535
536 # There are three parameters that are not configurable and must be set.
537 addenda['a:USER'] = 'NULL'
538 addenda['a:PASSWD'] = 'NULL'
539 addenda['p:DSDS_SUPPORT'] = '0'
540 addenda['a:BUILD_TYPE'] = 'NETDRMS' # Means a non-Stanford build. This will set two additional macros used by make:
541 # __LOCALIZED_DEFS__ and NETDRMS_BUILD. The former is to support legacy code
542 # which incorrectly used this macro, and the latter is for future use.
543 # __LOCALIZED_DEFS__ is deprecated and should not be used in new code.
|
544 arta 1.1
545 try:
546 with open(cfgfile, 'r') as fin:
|
547 arta 1.3 # Process configuration parameters
|
548 arta 1.2 rv = parseConfig(fin, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection)
|
549 arta 1.1 if rv == bool(0):
|
550 arta 1.3 # Must add a parameter for the SUMS_MANAGER UID (for some reason). This must be done after the
551 # config file is processed since an input to getMgrUIDLine() is one of the config file's
552 # parameter values.
|
553 arta 1.1 uidParam = {}
554 rv = getMgrUIDLine(defs, uidParam)
555 if rv == bool(0):
|
556 arta 1.2 rv = parseConfig(None, keymap, uidParam, defs, cDefs, mDefs, perlConstSection, perlInitSection)
|
557 arta 1.3
558 # Configure the compiler-selection make variables.
559 if rv == bool(0):
560 rv = configureComps(defs, mDefs)
|
561 arta 1.1
|
562 arta 1.3 # Write out the parameter files.
563 if rv == bool(0):
564 rv = writeFiles(base, cfile, mfile, pfile, cDefs, mDefs, perlConstSection, perlInitSection)
|
565 arta 1.1 except IOError as exc:
566 sys.stderr.write(exc.strerror)
567 sys.stderr.write('Unable to read configuration file ' + cfgfile + '.')
|
568 arta 1.3 except Exception as exc:
569 type, msg = exc.args
570 if type == 'unexpectedIccRet':
571 print('icc -V returned this unexpected message:\n' + msg, file=sys.stderr)
572 rv = bool(1)
573 elif type == 'unexpectedGccRet':
574 print('gcc -v returned this unexpected message:\n' + msg, file=sys.stderr)
575 rv = bool(1)
576 elif type == 'unexpectedIfortRet':
577 print('ifort -V returned this unexpected message:\n' + msg, file=sys.stderr)
578 rv = bool(1)
579 elif type == 'unexpectedGfortranRet':
580 print('gfortran -v returned this unexpected message:\n' + msg, file=sys.stderr)
581 rv = bool(1)
582 else:
583 # re-raise the exception
584 raise
|
585 arta 1.1
|
586 arta 1.2 return rv
|
587 arta 1.1
|
588 arta 1.2 def configureSdp(cfgfile, cfile, mfile, pfile, base, keymap):
|
589 arta 1.1 rv = bool(0)
590
591 defs = {}
592 cDefs = list()
593 mDefs = list()
594 perlConstSection = list()
595 perlInitSection = list()
|
596 arta 1.2 addenda = {}
597
598 addenda['a:BUILD_TYPE'] = 'JSOC_SDP'
|
599 arta 1.1
600 try:
601 with open(cfgfile, 'r') as fin:
|
602 arta 1.2 rv = parseConfig(cfgfile, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection)
|
603 arta 1.1 if rv == bool(0):
|
604 arta 1.2 # Must add a parameter for the SUMS_MANAGER UID (for some reason)
605 uidParam = {}
606 rv = getMgrUIDLine(defs, uidParam)
607 if rv == bool(0):
608 rv = parseConfig(None, keymap, uidParam, defs, cDefs, mDefs, perlConstSection, perlInitSection)
609
|
610 arta 1.3
611 # So, we need to rename __MAKE__ in configsdp.txt to something else (__PROJ_MK_RULES__).
612 # The only code that currently reads this file is configproj.pl, so we change that logic to use __PROJ_MK_RULES__
613 # for the make rules.
614 if rv == bool(0):
615 rv = writeFiles(base, cfile, mfile, pfile, cDefs, mDefs, perlConstSection, perlInitSection)
|
616 arta 1.1 except IOError as exc:
617 sys.stderr.write(exc.strerror)
618 sys.stderr.write('Unable to read configuration file ' + cfgfile + '.')
619
|
620 arta 1.2 return rv
621
|
622 arta 1.1 # Beginning of program
623 rv = RET_SUCCESS
624 net = bool(1)
625
626 # Parse arguments
627 if __name__ == "__main__":
628 optD = GetArgs(sys.argv[1:])
629
630 if not(optD is None):
631 # Ensure we are configuring a DRMS tree
632 cdir = os.path.realpath(os.getcwd())
633 versfile = cdir + '/base/' + VERS_FILE
634
635 if not os.path.isfile(versfile):
636 rv = RET_NOTDRMS
637
638 # Determine whether we are localizing a Stanford build, or a NetDRMS build. If configsdp.txt exists, then
639 # it is a Stanford build, otherwise it is a NetDRMS build.
640 if rv == RET_SUCCESS:
641 stanfordFile = cdir + '/' + SDP_CFG
642 if os.path.isfile(stanfordFile):
643 arta 1.1 net = bool(0)
644
645 cfile = optD['dir'] + '/' + optD['base'] + '.h'
646 mfile = optD['dir'] + '/' + optD['base'] + '.mk'
647 pfile = optD['dir'] + '/' + optD['base'] + '.pm'
648
649 if net:
650 try:
651 with open(NET_CFGMAP, 'r') as fin:
652 regexpComm = re.compile(r"^\s*#")
653 regexp = re.compile(r"^\s*(\S+)\s+(\w:\S+)")
654 # Must map from config.local namespace to DRMS namespace (e.g., the names used for the C macros)
655 keymap = {}
656 for line in fin:
657 matchobj = regexpComm.match(line)
658 if not matchobj is None:
659 # Skip comment line
660 continue
661
662 matchobj = regexp.match(line)
663 if not(matchobj is None):
664 arta 1.1 # We have a key-value line
665 key = matchobj.group(1)
666 val = matchobj.group(2)
667 keymap[key] = val
668 except OSError:
669 sys.stderr.write('Unable to read configuration map-file ' + NET_CFGMAP + '.')
670 rv = bool(1)
671
|
672 arta 1.2
|
673 arta 1.1
674 # We also need to set the UID of the SUMS manager. We have the name of the
675 # SUMS manager (it is in the configuration file)
|
676 arta 1.2 configureNet(NET_CFG, cfile, mfile, pfile, optD['base'], keymap)
|
677 arta 1.1 else:
|
678 arta 1.2 configureSdp(SDP_CFG, cfile, mfile, pfile, optD['base'], {})
|
679 arta 1.1
680
681
|