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

Comparing localize.py (file contents):
Revision 1.17 by arta, Fri Apr 18 19:14:54 2014 UTC vs.
Revision 1.18 by arta, Wed May 7 18:45:36 2014 UTC

# Line 74 | Line 74 | PERL_FXNS_B = """sub get
74   }
75   1;"""
76  
77 + PY_BINPATH = '#/usr/bin/python\n'
78 +
79 + PY_FXNS_A = """
80 + class DRMSParams:
81 +    def __init__(self):
82 +        self.params = {}
83 +        self.initialize()
84 +        
85 +    def __del__(self):
86 +        del self.params
87 +        
88 +    def initialize(self):
89 + """
90 +
91 + PY_FXNS_B = """    def get(self, name):
92 +        if name in self.params:
93 +            return self.parms[name]
94 +        else:
95 +            return None
96 + """
97 +
98   SUMRM_COMMENT = """# This is the configuration file for the sum_rm program. It was auto-generated by the DRMS master configure script.
99   # It controls the behavior of the sum_rm program, and is loaded each time sum_rm runs. To change the
100   # parameter values in this configuration file, modify config.local, then re-run configure. This configuration
# Line 220 | Line 241 | def createPerlConst(key, val, keyColLen,
241          status = bool(0)
242          return 'use constant ' + key + ' => ' + spaces + val + ';\n'
243  
244 + def createPyConst(key, val, keyColLen, status):
245 +    if keyColLen < len(key):
246 +        status = bool(1)
247 +        return None
248 +    else:
249 +        nsp = keyColLen - len(key)
250 +        spaces = str()
251 +        for isp in range(nsp):
252 +            spaces += ' '
253 +        status = bool(0)
254 +        return key + ' = ' + spaces + val + '\n'
255 +
256   def isSupportedPlat(plat):
257      regexp = re.compile(r"\s*(^x86_64|^ia32|^ia64|^avx)", re.IGNORECASE)
258      matchobj = regexp.match(plat);
# Line 255 | Line 288 | def processMakeParam(mDefs, key, val, pl
288                  machDict[varMach] = {}
289              machDict[varMach][varName] = varValu
290  
291 < def processParam(cfgfile, line, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, platDict, machDict, section):
291 > def processParam(cfgfile, line, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, pyConstSection, pyInitSection, platDict, machDict, section):
292      status = 0
293              
294      if ''.join(section) == 'defs' or not cfgfile:
# Line 314 | Line 347 | def processParam(cfgfile, line, regexpQu
347                  # Save const info to a string
348                  perlConstSection.extend(list(createPerlConst(key, "'" + val + "'", 40, status)))
349                  
350 +                # Python file
351 +                pyConstSection.extend(list(createPyConst(key, "'" + val + "'", 40, status)))
352 +                
353                  if status:
354                      raise Exception('paramNameTooLong', key)
355                  
# Line 322 | Line 358 | def processParam(cfgfile, line, regexpQu
358                  # we can refer to those in the init section. The key variable holds the
359                  # name of the constant.
360                  perlInitSection.extend(list("\n  $self->{_paramsH}->{'" + key + "'} = " + key + ';'))
361 +                
362 +                # The amount of indenting matters! This is Python.
363 +                pyInitSection.extend(list("        self.params['" + key + "'] = " + key + '\n'))
364              else:
365                  # No quote qualifier
366                  raise Exception('missingQuoteQual', key)
# Line 415 | Line 454 | def determineSection(line, regexpDefs, r
454   # projMkRules is the list containing the make_basic.mk content.
455   # projRules is the list containing the Rules.mk content.
456   # projTargert is the list containing the target.mk content.
457 < def parseConfig(fin, keymap, addenda, defs, cDefs, mDefsGen, mDefsMake, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection):
457 > def parseConfig(fin, keymap, addenda, defs, cDefs, mDefsGen, mDefsMake, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection, pyConstSection, pyInitSection):
458      rv = bool(0)
459      
460      # Open required config file (config.local)
# Line 476 | Line 515 | def parseConfig(fin, keymap, addenda, de
515                      # Intentional fall through to next if statement
516                  if section == 'defs' or section == 'make':
517                      iscfg = bool(1)
518 <                    ppRet = processParam(iscfg, line, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, platDict, machDict, section)
518 >                    ppRet = processParam(iscfg, line, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, pyConstSection, pyInitSection, platDict, machDict, section)
519                      
520                      if ppRet:
521                          break
# Line 560 | Line 599 | def parseConfig(fin, keymap, addenda, de
599          iscfg = bool(0)
600          for key in addenda:
601              item = key + ' ' + addenda[key]
602 <            ppRet = processParam(iscfg, item, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, platDict, machDict, 'defs')
602 >            ppRet = processParam(iscfg, item, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, pyConstSection, pyInitSection, platDict, machDict, 'defs')
603              if ppRet:
604                  break;
605  
# Line 722 | Line 761 | def configureComps(defs, mDefs):
761  
762      return rv
763  
764 < def writeParamsFiles(base, cfile, mfile, pfile, cDefs, mDefsGen, mDefsMake, mDefsComps, perlConstSection, perlInitSection):
764 > def writeParamsFiles(base, cfile, mfile, pfile, pyfile, cDefs, mDefsGen, mDefsMake, mDefsComps, perlConstSection, perlInitSection, pyConstSection, pyInitSection):
765      rv = bool(0)
766  
767      # Merge mDefsGen, mDefsMake, and mDefsComps into a single string with compiler configuration first, general parameters next, then
# Line 730 | Line 769 | def writeParamsFiles(base, cfile, mfile,
769      mDefs = '\n# Compiler Selection\n' + ''.join(mDefsComps) + '\n\n# General Parameters\n' + ''.join(mDefsGen) + '\n\n# Parameters to Configure make\n' + ''.join(mDefsMake)
770      
771      try:
772 <        with open(cfile, 'w') as cout, open(mfile, 'w') as mout, open(pfile, 'w') as pout:
772 >        with open(cfile, 'w') as cout, open(mfile, 'w') as mout, open(pfile, 'w') as pout, open(pyfile, 'w') as pyout:
773              # C file of macros
774              print(C_PREFIX, file=cout)
775              print('/* This file contains a set of preprocessor macros - one for each configuration parameter. */\n', file=cout)
# Line 759 | Line 798 | def writeParamsFiles(base, cfile, mfile,
798              print(''.join(perlInitSection), file=pout)
799              print('}\n', file=pout)
800              print(PERL_FXNS_B, file=pout)
801 +
802 +            # Python module
803 +            print(PY_BINPATH, file=pyout)
804 +            print(PREFIX, file=pyout)
805 +            print('# This file contains a set of constants - one for each configuration parameter.\n', file=pyout)
806 +            print(''.join(pyConstSection), file=pyout)
807 +            print(PY_FXNS_A, file=pyout, end='')
808 +            print(''.join(pyInitSection), file=pyout)
809 +            print(PY_FXNS_B, file=pyout)
810 +
811      except IOError as exc:
812          type, value, traceback = sys.exc_info()
813          print(exc.strerror, file=sys.stderr)
# Line 921 | Line 970 | def generateSumRmCfg(defs):
970  
971      return rv
972  
973 < def configureNet(cfgfile, cfile, mfile, pfile, pCfile, pMfile, pRfile, pTfile, base, keymap, createSumRmCfg):
973 > def configureNet(cfgfile, cfile, mfile, pfile, pyfile, pCfile, pMfile, pRfile, pTfile, base, keymap, createSumRmCfg):
974      rv = bool(0)
975      
976      defs = {}
# Line 935 | Line 984 | def configureNet(cfgfile, cfile, mfile,
984      projTarget = list()
985      perlConstSection = list()
986      perlInitSection = list()
987 +    pyConstSection = list()
988 +    pyInitSection = list()
989      addenda = {}
990      
991      # There are three parameters that were not included in the original config.local parameter set, for some reason.
# Line 952 | Line 1003 | def configureNet(cfgfile, cfile, mfile,
1003      try:
1004          with open(cfgfile, 'r') as fin:
1005              # Process configuration parameters
1006 <            rv = parseConfig(fin, keymap, addenda, defs, cDefs, mDefsGen, mDefsMake, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection)
1006 >            rv = parseConfig(fin, keymap, addenda, defs, cDefs, mDefsGen, mDefsMake, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection, pyConstSection, pyInitSection)
1007              if not rv:
1008                  # Must add a parameter for the SUMS_MANAGER UID (for some reason). This must be done after the
1009                  # config file is processed since an input to getMgrUIDLine() is one of the config file's
# Line 960 | Line 1011 | def configureNet(cfgfile, cfile, mfile,
1011                  uidParam = {}
1012                  rv = getMgrUIDLine(defs, uidParam)
1013                  if rv == bool(0):
1014 <                    rv = parseConfig(None, keymap, uidParam, defs, cDefs, mDefsGen, None, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection)
1014 >                    rv = parseConfig(None, keymap, uidParam, defs, cDefs, mDefsGen, None, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection, pyConstSection, pyInitSection)
1015              # Configure the compiler-selection make variables.
1016              if not rv:
1017                  rv = configureComps(defs, mDefsComps)
1018  
1019              # Write out the parameter files.
1020              if not rv:
1021 <                rv = writeParamsFiles(base, cfile, mfile, pfile, cDefs, mDefsGen, mDefsMake, mDefsComps, perlConstSection, perlInitSection)
1021 >                rv = writeParamsFiles(base, cfile, mfile, pfile, pyfile, cDefs, mDefsGen, mDefsMake, mDefsComps, perlConstSection, perlInitSection, pyConstSection, pyInitSection)
1022  
1023              # Write out the project-specific make files (make_basic.mk, Rules.mk, and target.mk).
1024              if not rv:
# Line 1004 | Line 1055 | def configureNet(cfgfile, cfile, mfile,
1055          
1056      return rv
1057  
1058 < def configureSdp(cfgfile, cfile, mfile, pfile, pCfile, pMfile, pRfile, pTfile, base):
1058 > def configureSdp(cfgfile, cfile, mfile, pfile, pyfile, pCfile, pMfile, pRfile, pTfile, base):
1059      rv = bool(0)
1060      
1061      defs = {}
# Line 1018 | Line 1069 | def configureSdp(cfgfile, cfile, mfile,
1069      mDefsComps = list()
1070      perlConstSection = list()
1071      perlInitSection = list()
1072 +    pyConstSection = list()
1073 +    pyInitSection = list()
1074 +
1075      addenda = {}
1076      
1077      # There are three parameters that were not included in the original config.local parameter set, for some reason.
# Line 1031 | Line 1085 | def configureSdp(cfgfile, cfile, mfile,
1085      
1086      try:
1087          with open(cfgfile, 'r') as fin:
1088 <            rv = parseConfig(fin, None, addenda, defs, cDefs, mDefsGen, mDefsMake, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection)
1088 >            rv = parseConfig(fin, None, addenda, defs, cDefs, mDefsGen, mDefsMake, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection, pyConstSection, pyInitSection)
1089              
1090              if not rv:
1091                  # Must add a parameter for the SUMS_MANAGER UID (for some reason)
1092                  uidParam = {}
1093                  rv = getMgrUIDLine(defs, uidParam)
1094                  if not rv:
1095 <                    rv = parseConfig(None, None, uidParam, defs, cDefs, mDefsGen, None, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection)
1095 >                    rv = parseConfig(None, None, uidParam, defs, cDefs, mDefsGen, None, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection, pyConstSection, pyInitSection)
1096  
1097                  # Configure the compiler-selection make variables.
1098                  if not rv:
# Line 1046 | Line 1100 | def configureSdp(cfgfile, cfile, mfile,
1100                  
1101                  # Write out the parameter files.
1102                  if not rv:
1103 <                    rv = writeParamsFiles(base, cfile, mfile, pfile, cDefs, mDefsGen, mDefsMake, mDefsComps, perlConstSection, perlInitSection)
1103 >                    rv = writeParamsFiles(base, cfile, mfile, pfile, pyfile, cDefs, mDefsGen, mDefsMake, mDefsComps, perlConstSection, perlInitSection, pyConstSection, pyInitSection)
1104  
1105                  # Write out the project-specific make files (make_basic.mk, Rules.mk, and target.mk).
1106                  if not rv:
# Line 1112 | Line 1166 | if rv == RET_SUCCESS:
1166      cfile = optD['dir'] + '/' + optD['base'] + '.h'
1167      mfile = optD['dir'] + '/' + optD['base'] + '.mk'
1168      pfile = optD['dir'] + '/' + optD['base'] + '.pm'
1169 +    pyfile = optD['dir'] + '/' + optD['base'] + '.py'
1170      pCfile = optD['dir'] + '/configure'
1171      pMfile = optD['dir'] + '/make_basic.mk'
1172      pRfile = optD['dir'] + '/Rules.mk'
# Line 1142 | Line 1197 | if rv == RET_SUCCESS:
1197  
1198          # We also need to set the UID of the SUMS manager. We have the name of the
1199          # SUMS manager (it is in the configuration file)
1200 <        configureNet(NET_CFG, cfile, mfile, pfile, pCfile, pMfile, pRfile, pTfile, optD['base'], keymap, 'server' in optD)
1200 >        configureNet(NET_CFG, cfile, mfile, pfile, pyfile, pCfile, pMfile, pRfile, pTfile, optD['base'], keymap, 'server' in optD)
1201      else:
1202          # A Stanford user can override the parameters in configsdp.txt by copying that file to config.local,
1203          # and then editing config.local. So, if config.local exists, use that.
1204          if os.path.isfile(cdir + '/' + NET_CFG):
1205 <            configureSdp(NET_CFG, cfile, mfile, pfile, pCfile, pMfile, pRfile, pTfile, optD['base'])
1205 >            configureSdp(NET_CFG, cfile, mfile, pfile, pyfile, pCfile, pMfile, pRfile, pTfile, optD['base'])
1206          else:
1207 <            configureSdp(SDP_CFG, cfile, mfile, pfile, pCfile, pMfile, pRfile, pTfile, optD['base'])
1207 >            configureSdp(SDP_CFG, cfile, mfile, pfile, pyfile, pCfile, pMfile, pRfile, pTfile, optD['base'])

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines