ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/localize.py
(Generate patch)

Comparing localize.py (file contents):
Revision 1.1 by arta, Thu Nov 7 19:09:52 2013 UTC vs.
Revision 1.2 by arta, Thu Nov 7 21:03:04 2013 UTC

# Line 14 | Line 14 | NET_CFGMAP = 'config.local.map'
14   RET_SUCCESS = 0
15   RET_NOTDRMS = 1
16  
17 < PERL_PREFIX = """
18 < #!/usr/bin/perl
17 > 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  
21 < package drmsparams;
21 > 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   """
24  
25 < PERL_FXNS = """
26 < sub new
25 > 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   {
35      my($clname) = shift;
36      
# Line 40 | Line 49 | sub DESTROY
49   {
50      my($self) = shift;
51   }
43    
52   """
53  
54 + PERL_FXNS_B = """sub get
55 + {
56 +    my($self) = shift;
57 +    my($name) = shift;
58 +    my($rv);
59 +    
60 +    if (exists($self->{_paramsH}->{$name}))
61 +    {
62 +        return $self->{_paramsH}->{$name};
63 +    }
64 +    else
65 +    {
66 +        return undef;
67 +    }
68 + }
69 + 1;"""
70 +
71   # Read arguments
72   #  d - localization directory
73   #  b - base name of all parameter files (e.g., -b drmsparams --> drmsparams.h, drmsparams.mk, drmsparams.pm, etc.)
# Line 167 | Line 192 | def processParam(cfgfile, line, regexpCo
192                      raise Exception('paramNameTooLong', key)
193                  
194                  # Make file - val should never be quoted; just use as is
195 <                mDefs.extend(list(key + ' = ' + val + '\n'))
195 >                mDefs.extend(list('\n' + key + ' = ' + val))
196                  
197                  # Perl file - val should ALWAYS be single-quote quoted
198                  # Save const info to a string
# Line 180 | Line 205 | def processParam(cfgfile, line, regexpCo
205                  # constants (the names of which are the parameter names)
206                  # we can refer to those in the init section. The key variable holds the
207                  # name of the constant.
208 <                perlInitSection.extend(list('  $self->{_paramsH}->{' + key + '} = ' + key + ';\n'))
208 >                perlInitSection.extend(list('\n  $self->{_paramsH}->{' + key + '} = ' + "'" + val + "';"))
209              else:
210                  # No quote qualifier
211                  raise Exception('missingQuoteQual', key)
# Line 190 | Line 215 | def processParam(cfgfile, line, regexpCo
215   # We have some extraneous line or a newline - ignore.
216  
217   # defs is a dictionary containing all parameters (should they be needed in this script)
218 < def parseConfig(fin, cfile, mfile, pfile, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection):
218 > def parseConfig(fin, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection):
219      rv = bool(0)
220      
221      # Open required config file (config.local)
# Line 267 | Line 292 | def writeFiles(base, cfile, mfile, pfile
292      try:
293          with open(cfile, 'w') as cout, open(mfile, 'w') as mout, open(pfile, 'w') as pout:
294              # C file of macros
295 +            print(C_PREFIX, file=cout)
296 +            print('/* This file contains a set of preprocessor macros - one for each configuration parameter. */\n', file=cout)
297              buf = '__' + base.upper() + '_H'
298              print('#ifndef ' + buf, file=cout)
299              print('#define ' + buf, file=cout)
# Line 274 | Line 301 | def writeFiles(base, cfile, mfile, pfile
301              print('#endif', file=cout)
302              
303              # Make file of make variables
304 +            print(PREFIX, file=mout)
305              print('# This file contains a set of make-variable values - one for each configuration parameter.', file=mout)
306              print(''.join(mDefs), file=mout)
307              
308 <            # Create the constants in the Perl file (mapping parameter name from config.local namespace to
309 <            # DRMS-module namespace
310 <            print(PERL_PREFIX, file=pout)
308 >            # Perl module
309 >            print(PERL_BINPATH, file=pout)
310 >            print(PREFIX, file=pout)
311 >            print('# This file contains a set of constants - one for each configuration parameter.\n', file=pout)
312 >            print(PERL_INTIAL, file=pout)
313              print(''.join(perlConstSection), file=pout)
314 <            print(PERL_FXNS, file=pout)
314 >            print(PERL_FXNS_A, file=pout)
315              print('sub initialize', file=pout)
316              print('{', file=pout)
317 <            print('  my($self) = shift;', file=pout)
317 >            print('  my($self) = shift;', file=pout, end='')
318              print('', file=pout)
319              print(''.join(perlInitSection), file=pout)
320 <            print('}', file=pout)
321 <            
320 >            print('}\n', file=pout)
321 >            print(PERL_FXNS_B, file=pout)
322      except IOError as exc:
323          sys.stderr.write(exc.strerror)
324          sys.stderr.write('Unable to open a parameter vile.')
# Line 296 | Line 326 | def writeFiles(base, cfile, mfile, pfile
326  
327      return rv
328              
329 < def configureNet(cfgfile, cfile, mfile, pfile, base, keymap, addenda):
329 > def configureNet(cfgfile, cfile, mfile, pfile, base, keymap):
330      rv = bool(0)
331      
332      defs = {}
# Line 304 | Line 334 | def configureNet(cfgfile, cfile, mfile,
334      mDefs = list()
335      perlConstSection = list()
336      perlInitSection = list()
337 +    addenda = {}
338 +    
339 +    # There are three parameters that are not configurable and must be set.
340 +    addenda['a:USER'] = 'NULL'
341 +    addenda['a:PASSWD'] = 'NULL'
342 +    addenda['p:DSDS_SUPPORT'] = '0'
343 +    addenda['a:BUILD_TYPE'] = 'NETDRMS' # Means a non-Stanford build. This will set two additional macros used by make:
344 +                                        #   __LOCALIZED_DEFS__ and NETDRMS_BUILD. The former is to support legacy code
345 +                                        #   which incorrectly used this macro, and the latter is for future use.
346 +                                        #   __LOCALIZED_DEFS__ is deprecated and should not be used in new code.
347  
348      try:
349          with open(cfgfile, 'r') as fin:
350 <            rv = parseConfig(fin, cfile, mfile, pfile, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection)
350 >            rv = parseConfig(fin, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection)
351              if rv == bool(0):
352                  # Must add a parameter for the SUMS_MANAGER UID (for some reason)
353                  uidParam = {}
354                  rv = getMgrUIDLine(defs, uidParam)
355                  if rv == bool(0):
356 <                    rv = parseConfig(None, cfile, mfile, pfile, keymap, uidParam, defs, cDefs, mDefs, perlConstSection, perlInitSection)
356 >                    rv = parseConfig(None, keymap, uidParam, defs, cDefs, mDefs, perlConstSection, perlInitSection)
357  
358                  if rv == bool(0):
359                      rv = writeFiles(base, cfile, mfile, pfile, cDefs, mDefs, perlConstSection, perlInitSection)
# Line 321 | Line 361 | def configureNet(cfgfile, cfile, mfile,
361          sys.stderr.write(exc.strerror)
362          sys.stderr.write('Unable to read configuration file ' + cfgfile + '.')
363          
364 +    return rv
365  
366 < def configureSdp(cfgfile, cfile, mfile, pfile, base, keymap, addenda):
366 > def configureSdp(cfgfile, cfile, mfile, pfile, base, keymap):
367      rv = bool(0)
368      
369      defs = {}
# Line 330 | Line 371 | def configureSdp(cfgfile, cfile, mfile,
371      mDefs = list()
372      perlConstSection = list()
373      perlInitSection = list()
374 +    addenda = {}
375 +    
376 +    addenda['a:BUILD_TYPE'] = 'JSOC_SDP'
377      
378      try:
379          with open(cfgfile, 'r') as fin:
380 <            rv = parseConfig(cfgfile, cfile, mfile, pfile, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection)
380 >            rv = parseConfig(cfgfile, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection)
381              if rv == bool(0):
382 +                # Must add a parameter for the SUMS_MANAGER UID (for some reason)
383 +                uidParam = {}
384 +                rv = getMgrUIDLine(defs, uidParam)
385 +                if rv == bool(0):
386 +                    rv = parseConfig(None, keymap, uidParam, defs, cDefs, mDefs, perlConstSection, perlInitSection)
387 +                
388                  rv = writeFiles(base, cfile, mfile, pfile, cDefs, mDefs, perlConstSection, perlInitSection)
389      except IOError as exc:
390          sys.stderr.write(exc.strerror)
391          sys.stderr.write('Unable to read configuration file ' + cfgfile + '.')
392  
393 +    return rv
394 +
395   # Beginning of program
396   rv = RET_SUCCESS
397   net = bool(1)
# Line 368 | Line 420 | if rv == RET_SUCCESS:
420      pfile = optD['dir'] + '/' + optD['base'] + '.pm'
421  
422      if net:
371        addenda = {}
372
423          try:
424              with open(NET_CFGMAP, 'r') as fin:
425                  regexpComm = re.compile(r"^\s*#")
# Line 392 | Line 442 | if rv == RET_SUCCESS:
442              sys.stderr.write('Unable to read configuration map-file ' + NET_CFGMAP + '.')
443              rv = bool(1)
444              
445 <        # There are three parameters that are not configurable and must be set.
396 <        addenda['a:USER'] = 'NULL'
397 <        addenda['a:PASSWD'] = 'NULL'
398 <        addenda['p:DSDS_SUPPORT'] = '0'
445 >        
446  
447          # We also need to set the UID of the SUMS manager. We have the name of the
448          # SUMS manager (it is in the configuration file)
449 <        configureNet(NET_CFG, cfile, mfile, pfile, optD['base'], keymap, addenda)
449 >        configureNet(NET_CFG, cfile, mfile, pfile, optD['base'], keymap)
450      else:
451 <        configureSdp(SDP_CFG, cfile, mfile, pfile, optD['base'], {}, addenda)
451 >        configureSdp(SDP_CFG, cfile, mfile, pfile, optD['base'], {})
452      
453      
454  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines