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

Diff for /JSOC/localize.py between version 1.1 and 1.2

version 1.1, 2013/11/07 19:09:52 version 1.2, 2013/11/07 21:03:04
Line 14  NET_CFGMAP = 'config.local.map'
Line 14  NET_CFGMAP = 'config.local.map'
 RET_SUCCESS = 0 RET_SUCCESS = 0
 RET_NOTDRMS = 1 RET_NOTDRMS = 1
  
 PERL_PREFIX = """  PREFIX = """# This file was auto-generated by localize.py. Please do not edit it directly (running
 #!/usr/bin/perl  # configure will run localize.py, which will then overwrite any edits manually performed).
   """
   
   C_PREFIX = """/* This file was auto-generated by localize.py. Please do not edit it directly (running
    * configure will run localize.py, which will then overwrite any edits manually performed). */
   """
   
   PERL_BINPATH = '#!/usr/bin/perl\n'
   
   PERL_INTIAL = """package drmsparams;
  
 package drmsparams;  use warnings;
   use strict;
 """ """
  
 PERL_FXNS = """  PERL_FXNS_A = """sub new
 sub new  
 { {
     my($clname) = shift;     my($clname) = shift;
  
Line 40  sub DESTROY
Line 49  sub DESTROY
 { {
     my($self) = shift;     my($self) = shift;
 } }
   
 """ """
  
   PERL_FXNS_B = """sub get
   {
       my($self) = shift;
       my($name) = shift;
       my($rv);
   
       if (exists($self->{_paramsH}->{$name}))
       {
           return $self->{_paramsH}->{$name};
       }
       else
       {
           return undef;
       }
   }
   1;"""
   
 # Read arguments # Read arguments
 #  d - localization directory #  d - localization directory
 #  b - base name of all parameter files (e.g., -b drmsparams --> drmsparams.h, drmsparams.mk, drmsparams.pm, etc.) #  b - base name of all parameter files (e.g., -b drmsparams --> drmsparams.h, drmsparams.mk, drmsparams.pm, etc.)
Line 167  def processParam(cfgfile, line, regexpCo
Line 192  def processParam(cfgfile, line, regexpCo
                     raise Exception('paramNameTooLong', key)                     raise Exception('paramNameTooLong', key)
  
                 # Make file - val should never be quoted; just use as is                 # Make file - val should never be quoted; just use as is
                 mDefs.extend(list(key + ' = ' + val + '\n'))                  mDefs.extend(list('\n' + key + ' = ' + val))
  
                 # Perl file - val should ALWAYS be single-quote quoted                 # Perl file - val should ALWAYS be single-quote quoted
                 # Save const info to a string                 # Save const info to a string
Line 180  def processParam(cfgfile, line, regexpCo
Line 205  def processParam(cfgfile, line, regexpCo
                 # constants (the names of which are the parameter names)                 # constants (the names of which are the parameter names)
                 # we can refer to those in the init section. The key variable holds the                 # we can refer to those in the init section. The key variable holds the
                 # name of the constant.                 # name of the constant.
                 perlInitSection.extend(list('  $self->{_paramsH}->{' + key + '} = ' + key + ';\n'))                  perlInitSection.extend(list('\n  $self->{_paramsH}->{' + key + '} = ' + "'" + val + "';"))
             else:             else:
                 # No quote qualifier                 # No quote qualifier
                 raise Exception('missingQuoteQual', key)                 raise Exception('missingQuoteQual', key)
Line 190  def processParam(cfgfile, line, regexpCo
Line 215  def processParam(cfgfile, line, regexpCo
 # We have some extraneous line or a newline - ignore. # We have some extraneous line or a newline - ignore.
  
 # defs is a dictionary containing all parameters (should they be needed in this script) # defs is a dictionary containing all parameters (should they be needed in this script)
 def parseConfig(fin, cfile, mfile, pfile, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection):  def parseConfig(fin, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection):
     rv = bool(0)     rv = bool(0)
  
     # Open required config file (config.local)     # Open required config file (config.local)
Line 267  def writeFiles(base, cfile, mfile, pfile
Line 292  def writeFiles(base, cfile, mfile, pfile
     try:     try:
         with open(cfile, 'w') as cout, open(mfile, 'w') as mout, open(pfile, 'w') as pout:         with open(cfile, 'w') as cout, open(mfile, 'w') as mout, open(pfile, 'w') as pout:
             # C file of macros             # C file of macros
               print(C_PREFIX, file=cout)
               print('/* This file contains a set of preprocessor macros - one for each configuration parameter. */\n', file=cout)
             buf = '__' + base.upper() + '_H'             buf = '__' + base.upper() + '_H'
             print('#ifndef ' + buf, file=cout)             print('#ifndef ' + buf, file=cout)
             print('#define ' + buf, file=cout)             print('#define ' + buf, file=cout)
Line 274  def writeFiles(base, cfile, mfile, pfile
Line 301  def writeFiles(base, cfile, mfile, pfile
             print('#endif', file=cout)             print('#endif', file=cout)
  
             # Make file of make variables             # Make file of make variables
               print(PREFIX, file=mout)
             print('# This file contains a set of make-variable values - one for each configuration parameter.', file=mout)             print('# This file contains a set of make-variable values - one for each configuration parameter.', file=mout)
             print(''.join(mDefs), file=mout)             print(''.join(mDefs), file=mout)
  
             # Create the constants in the Perl file (mapping parameter name from config.local namespace to              # Perl module
             # DRMS-module namespace              print(PERL_BINPATH, file=pout)
             print(PERL_PREFIX, file=pout)              print(PREFIX, file=pout)
               print('# This file contains a set of constants - one for each configuration parameter.\n', file=pout)
               print(PERL_INTIAL, file=pout)
             print(''.join(perlConstSection), file=pout)             print(''.join(perlConstSection), file=pout)
             print(PERL_FXNS, file=pout)              print(PERL_FXNS_A, file=pout)
             print('sub initialize', file=pout)             print('sub initialize', file=pout)
             print('{', file=pout)             print('{', file=pout)
             print('  my($self) = shift;', file=pout)              print('  my($self) = shift;', file=pout, end='')
             print('', file=pout)             print('', file=pout)
             print(''.join(perlInitSection), file=pout)             print(''.join(perlInitSection), file=pout)
             print('}', file=pout)              print('}\n', file=pout)
               print(PERL_FXNS_B, file=pout)
     except IOError as exc:     except IOError as exc:
         sys.stderr.write(exc.strerror)         sys.stderr.write(exc.strerror)
         sys.stderr.write('Unable to open a parameter vile.')         sys.stderr.write('Unable to open a parameter vile.')
Line 296  def writeFiles(base, cfile, mfile, pfile
Line 326  def writeFiles(base, cfile, mfile, pfile
  
     return rv     return rv
  
 def configureNet(cfgfile, cfile, mfile, pfile, base, keymap, addenda):  def configureNet(cfgfile, cfile, mfile, pfile, base, keymap):
     rv = bool(0)     rv = bool(0)
  
     defs = {}     defs = {}
Line 304  def configureNet(cfgfile, cfile, mfile,
Line 334  def configureNet(cfgfile, cfile, mfile,
     mDefs = list()     mDefs = list()
     perlConstSection = list()     perlConstSection = list()
     perlInitSection = list()     perlInitSection = list()
       addenda = {}
   
       # There are three parameters that are not configurable and must be set.
       addenda['a:USER'] = 'NULL'
       addenda['a:PASSWD'] = 'NULL'
       addenda['p:DSDS_SUPPORT'] = '0'
       addenda['a:BUILD_TYPE'] = 'NETDRMS' # Means a non-Stanford build. This will set two additional macros used by make:
                                           #   __LOCALIZED_DEFS__ and NETDRMS_BUILD. The former is to support legacy code
                                           #   which incorrectly used this macro, and the latter is for future use.
                                           #   __LOCALIZED_DEFS__ is deprecated and should not be used in new code.
  
     try:     try:
         with open(cfgfile, 'r') as fin:         with open(cfgfile, 'r') as fin:
             rv = parseConfig(fin, cfile, mfile, pfile, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection)              rv = parseConfig(fin, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection)
             if rv == bool(0):             if rv == bool(0):
                 # Must add a parameter for the SUMS_MANAGER UID (for some reason)                 # Must add a parameter for the SUMS_MANAGER UID (for some reason)
                 uidParam = {}                 uidParam = {}
                 rv = getMgrUIDLine(defs, uidParam)                 rv = getMgrUIDLine(defs, uidParam)
                 if rv == bool(0):                 if rv == bool(0):
                     rv = parseConfig(None, cfile, mfile, pfile, keymap, uidParam, defs, cDefs, mDefs, perlConstSection, perlInitSection)                      rv = parseConfig(None, keymap, uidParam, defs, cDefs, mDefs, perlConstSection, perlInitSection)
  
                 if rv == bool(0):                 if rv == bool(0):
                     rv = writeFiles(base, cfile, mfile, pfile, cDefs, mDefs, perlConstSection, perlInitSection)                     rv = writeFiles(base, cfile, mfile, pfile, cDefs, mDefs, perlConstSection, perlInitSection)
Line 321  def configureNet(cfgfile, cfile, mfile,
Line 361  def configureNet(cfgfile, cfile, mfile,
         sys.stderr.write(exc.strerror)         sys.stderr.write(exc.strerror)
         sys.stderr.write('Unable to read configuration file ' + cfgfile + '.')         sys.stderr.write('Unable to read configuration file ' + cfgfile + '.')
  
       return rv
  
 def configureSdp(cfgfile, cfile, mfile, pfile, base, keymap, addenda):  def configureSdp(cfgfile, cfile, mfile, pfile, base, keymap):
     rv = bool(0)     rv = bool(0)
  
     defs = {}     defs = {}
Line 330  def configureSdp(cfgfile, cfile, mfile,
Line 371  def configureSdp(cfgfile, cfile, mfile,
     mDefs = list()     mDefs = list()
     perlConstSection = list()     perlConstSection = list()
     perlInitSection = list()     perlInitSection = list()
       addenda = {}
   
       addenda['a:BUILD_TYPE'] = 'JSOC_SDP'
  
     try:     try:
         with open(cfgfile, 'r') as fin:         with open(cfgfile, 'r') as fin:
             rv = parseConfig(cfgfile, cfile, mfile, pfile, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection)              rv = parseConfig(cfgfile, keymap, addenda, defs, cDefs, mDefs, perlConstSection, perlInitSection)
             if rv == bool(0):             if rv == bool(0):
                   # Must add a parameter for the SUMS_MANAGER UID (for some reason)
                   uidParam = {}
                   rv = getMgrUIDLine(defs, uidParam)
                   if rv == bool(0):
                       rv = parseConfig(None, keymap, uidParam, defs, cDefs, mDefs, perlConstSection, perlInitSection)
   
                 rv = writeFiles(base, cfile, mfile, pfile, cDefs, mDefs, perlConstSection, perlInitSection)                 rv = writeFiles(base, cfile, mfile, pfile, cDefs, mDefs, perlConstSection, perlInitSection)
     except IOError as exc:     except IOError as exc:
         sys.stderr.write(exc.strerror)         sys.stderr.write(exc.strerror)
         sys.stderr.write('Unable to read configuration file ' + cfgfile + '.')         sys.stderr.write('Unable to read configuration file ' + cfgfile + '.')
  
       return rv
   
 # Beginning of program # Beginning of program
 rv = RET_SUCCESS rv = RET_SUCCESS
 net = bool(1) net = bool(1)
Line 368  if rv == RET_SUCCESS:
Line 420  if rv == RET_SUCCESS:
     pfile = optD['dir'] + '/' + optD['base'] + '.pm'     pfile = optD['dir'] + '/' + optD['base'] + '.pm'
  
     if net:     if net:
         addenda = {}  
   
         try:         try:
             with open(NET_CFGMAP, 'r') as fin:             with open(NET_CFGMAP, 'r') as fin:
                 regexpComm = re.compile(r"^\s*#")                 regexpComm = re.compile(r"^\s*#")
Line 392  if rv == RET_SUCCESS:
Line 442  if rv == RET_SUCCESS:
             sys.stderr.write('Unable to read configuration map-file ' + NET_CFGMAP + '.')             sys.stderr.write('Unable to read configuration map-file ' + NET_CFGMAP + '.')
             rv = bool(1)             rv = bool(1)
  
         # There are three parameters that are not configurable and must be set.  
         addenda['a:USER'] = 'NULL'  
         addenda['a:PASSWD'] = 'NULL'  
         addenda['p:DSDS_SUPPORT'] = '0'  
  
         # We also need to set the UID of the SUMS manager. We have the name of the         # We also need to set the UID of the SUMS manager. We have the name of the
         # SUMS manager (it is in the configuration file)         # SUMS manager (it is in the configuration file)
         configureNet(NET_CFG, cfile, mfile, pfile, optD['base'], keymap, addenda)          configureNet(NET_CFG, cfile, mfile, pfile, optD['base'], keymap)
     else:     else:
         configureSdp(SDP_CFG, cfile, mfile, pfile, optD['base'], {}, addenda)          configureSdp(SDP_CFG, cfile, mfile, pfile, optD['base'], {})
  
  
  


Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Karen Tian
Powered by
ViewCVS 0.9.4