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

   1 arta  1.15 #!/usr/bin/python
   2 arta  1.1  
   3 arta  1.13 # When run with the -s flag, localize.py configures the SUMS-server component of NetDRMS.
   4 arta  1.15 from __future__ import print_function
   5 arta  1.1  import sys
   6            import getopt
   7            import re
   8 arta  1.6  import os
   9            import stat
  10 arta  1.13 import filecmp
  11 arta  1.6  import xml.etree.ElementTree as ET
  12 arta  1.1  from subprocess import check_output, CalledProcessError
  13            
  14            # Constants
  15            VERS_FILE = 'jsoc_version.h'
  16            SDP_CFG = 'configsdp.txt'
  17            NET_CFG = 'config.local'
  18            NET_CFGMAP = 'config.local.map'
  19            RET_SUCCESS = 0
  20            RET_NOTDRMS = 1
  21            
  22 arta  1.2  PREFIX = """# This file was auto-generated by localize.py. Please do not edit it directly (running
  23            # configure will run localize.py, which will then overwrite any edits manually performed).
  24            """
  25 arta  1.1  
  26 arta  1.2  C_PREFIX = """/* This file was auto-generated by localize.py. Please do not edit it directly (running
  27             * configure will run localize.py, which will then overwrite any edits manually performed). */
  28 arta  1.1  """
  29            
  30 arta  1.2  PERL_BINPATH = '#!/usr/bin/perl\n'
  31            
  32            PERL_INTIAL = """package drmsparams;
  33                
  34            use warnings;
  35            use strict;
  36            """
  37            
  38            PERL_FXNS_A = """sub new
  39 arta  1.1  {
  40                my($clname) = shift;
  41                
  42                my($self) = 
  43                {
  44                    _paramsH => undef
  45                };
  46                
  47                bless($self, $clname);
  48 arta  1.9      $self->{_paramsH} = {};
  49                $self->initialize();
  50 arta  1.1      
  51                return $self;
  52            }
  53                
  54            sub DESTROY
  55            {
  56                my($self) = shift;
  57            }
  58 arta  1.2  """
  59            
  60            PERL_FXNS_B = """sub get
  61            {
  62                my($self) = shift;
  63                my($name) = shift;
  64                my($rv);
  65 arta  1.1      
  66 arta  1.2      if (exists($self->{_paramsH}->{$name}))
  67                {
  68                    return $self->{_paramsH}->{$name};
  69                }
  70                else
  71                {
  72                    return undef;
  73                }
  74            }
  75            1;"""
  76 arta  1.1  
  77 arta  1.13 SUMRM_COMMENT = """# This is the configuration file for the sum_rm program. It was auto-generated by the DRMS master configure script.
  78            # It controls the behavior of the sum_rm program, and is loaded each time sum_rm runs. To change the
  79            # parameter values in this configuration file, modify config.local, then re-run configure. This configuration
  80            # file will be updated only if parameters affecting it are modified. If such changes are made to config.local,
  81            # please make sure that the sum_rm service is disabled while configure in running.
  82            """
  83            
  84            SUMRM_DOC = """# sum_rm removes end-of-life SUMS data files to prevent disk-partitions from becomming 100% full. 
  85            # sum_svc, the main SUMS service, starts this daemon when it is launched. Within an infinite loop, sum_rm sleeps
  86            # for SLEEP number of seconds (defined below). When it awakes, it loads the sum_rm configuration file. For each SU,
  87            # it then examines the 'effective_date' column within the sum_partn_alloc table of the SUMS database. It does so by
  88            # sorting all SUs by effective date (this date is actually an expiration date - the SU is good until the end of that day),
  89            # and then, starting with the SU with the oldest effective date, it deletes the SUs. It continues deleting SUs until one
  90            # of three conditions is met:
  91            #
  92            #   (a) The disk has at least PART_PERCENT_FREE percent free space.
  93            #   (b) All SUs have effective_date values in the future.
  94            #   (c) At least 600 SUs have been deleted (this is defined in the LIMIT statement in the file SUMLIB_RmDoX.pgc).
  95            #
  96            # After sum_rm stops deleteing SUs, it then sleeps for SLEEP seconds, completing the first iteration of the
  97            # infinite loop.
  98 arta  1.13 """
  99            
 100            SUMRM_PARTN_PERCENT_FREE = """
 101            # This is the percentage at which all disk partitions are to be kept free.
 102            # If not specified, this defaults to 3. For example, setting PART_PERCENT_FREE = 5 will allow all partitions to
 103            # fill to 95% full. Dividing the number of unused blocks by the total number of blocks, and rounding up,
 104            # will result in the number specified by PART_PERCENT_FREE.
 105            #
 106            # NOTE : This behavior was previously controlled by the MAX_FREE_{n} family of parameters. {n} referred to the
 107            # disk-partition number and the value of parameter MAX_FREE_{n} was the MINIMUM number of free MB in the
 108            # partition [No clue why the word MAX was used]. As of NetDRMS 7.0, MAX_FREE_{n} has no effect."""
 109            
 110            SUMRM_SLEEP = """
 111            # The value is the number of seconds to sleep between iterations of the main loop in sum_rm."""
 112            
 113            SUMRM_LOG = """
 114            # The value is the log file (opened only at sum_rm startup; the sum_rm pid is appended to this file name)."""
 115            
 116            SUMRM_MAIL = """
 117            # The value is the email address of the recipient to be notified in case of a problem."""
 118            
 119 arta  1.13 SUMRM_NOOP = """
 120            # If the value is set to anything other than 0, then sum_rm is rendered inactive. Otherwise, sum_rm is active."""
 121            
 122            SUMRM_USER = """
 123            # The value designates the linux user who is allowed to run sum_rm."""
 124            
 125            SUMRM_NORUN = """
 126            # This pair of paramters defines a window of time, during which sum_rm will become torpid - in this
 127            # window, sum_rm will not scan for SUs to delete, not will it delete any SUs. Each value is an integer, 0-23, that
 128            # represents an hour of the day. For example, if NORUN_START=8 and NORUN_STOP=10, then between 8am and 10am
 129            # local time, sum_rm will be dormant. To disable this behavior, set both parameters to the same value."""
 130 arta  1.6  
 131            RULESPREFIX = """# Standard things
 132            sp 		:= $(sp).x
 133            dirstack_$(sp)	:= $(d)
 134            d		:= $(dir)
 135            """
 136            
 137            RULESSUFFIX = """dir	:= $(d)/example
 138            -include		$(SRCDIR)/$(dir)/Rules.mk
 139            dir	:= $(d)/cookbook
 140            -include		$(SRCDIR)/$(dir)/Rules.mk
 141            dir	:= $(d)/myproj
 142            -include		$(SRCDIR)/$(dir)/Rules.mk
 143            
 144            # Standard things
 145            d		:= $(dirstack_$(sp))
 146            sp		:= $(basename $(sp))
 147            """
 148            
 149            TARGETPREFIX = """$(PROJOBJDIR):\n\t+@[ -d $@ ] || mkdir -p $@"""
 150            
 151 arta  1.3  ICC_MAJOR = 9
 152            ICC_MINOR = 0
 153            GCC_MAJOR = 3
 154            GCC_MINOR = 0
 155            IFORT_MAJOR = 9
 156            IFORT_MINOR = 0
 157            GFORT_MAJOR = 4
 158            GFORT_MINOR = 2
 159            
 160            
 161 arta  1.1  # Read arguments
 162            #  d - localization directory
 163            #  b - base name of all parameter files (e.g., -b drmsparams --> drmsparams.h, drmsparams.mk, drmsparams.pm, etc.)
 164 arta  1.13 #  s - configure a NetDRMS server (i.e., SUMS server). Otherwise, do client configuration only. A server
 165            #      configuration will modify something that only the production user has access to. An example is the sum_rm.cfg
 166            #      file. To modify that file, the user running configure must be running configure on the SUMS-server host, and
 167            #      must have write permission on sum_rm.cfg.
 168 arta  1.1  def GetArgs(args):
 169                rv = bool(0)
 170                optD = {}
 171                
 172                try:
 173 arta  1.13         opts, remainder = getopt.getopt(args, "hd:b:s",["dir=", "base="])
 174 arta  1.1      except getopt.GetoptError:
 175                    print('Usage:')
 176                    print('localize.py [-h] -d <localization directory> -b <parameter file base>')
 177                    rv = bool(1)
 178                
 179                if rv == bool(0):
 180                    for opt, arg in opts:
 181                        if opt == '-h':
 182                            print('localize.py [-h] -d <localization directory> -b <parameter file base>')
 183                        elif opt in ("-d", "--dir"):
 184                            regexp = re.compile(r"(\S+)/?")
 185                            matchobj = regexp.match(arg)
 186                            if matchobj is None:
 187                                rv = bool(1)
 188                            else:
 189                                optD['dir'] = matchobj.group(1)
 190                        elif opt in ("-b", "--base"):
 191                            optD['base'] = arg
 192 arta  1.13             elif opt in ("-s"):
 193                            optD['server'] = ""
 194 arta  1.1              else:
 195                            optD[opt] = arg
 196            	
 197                return optD
 198            
 199            def createMacroStr(key, val, keyColLen, status):
 200                if keyColLen < len(key):
 201                    status = bool(1)
 202                    return None
 203                else:
 204                    nsp = keyColLen - len(key)
 205                    spaces = str()
 206                    for isp in range(nsp):
 207                        spaces += ' '
 208                    status = bool(0)
 209                    return '#define ' + key + spaces + val + '\n'
 210            
 211            def createPerlConst(key, val, keyColLen, status):
 212                if keyColLen < len(key):
 213                    status = bool(1)
 214                    return None
 215 arta  1.1      else:
 216                    nsp = keyColLen - len(key)
 217                    spaces = str()
 218                    for isp in range(nsp):
 219                        spaces += ' '
 220                    status = bool(0)
 221                    return 'use constant ' + key + ' => ' + spaces + val + ';\n'
 222            
 223 arta  1.3  def isSupportedPlat(plat):
 224                regexp = re.compile(r"\s*(^x86_64|^ia32|^ia64|^avx)", re.IGNORECASE)
 225                matchobj = regexp.match(plat);
 226                    
 227                if not matchobj is None:
 228                    return bool(1);
 229                else:
 230                    return bool(0);
 231            
 232 arta  1.6  def processMakeParam(mDefs, key, val, platDict, machDict):
 233 arta  1.3      varMach = None
 234                regexp = re.compile(r"(\S+):(\S+)")
 235                matchobj = regexp.match(key)
 236                if not matchobj is None:
 237                    varName = matchobj.group(1)
 238                    varMach = matchobj.group(2)
 239                else:
 240                    varName = key
 241                
 242                varValu = val
 243                    
 244                if varMach is None:
 245                    mDefs.extend(list('\n' + varName + ' = ' + varValu))
 246                else:
 247                    if isSupportedPlat(varMach):
 248                        # The guard will compare varValu to $JSOC_MACHINE.
 249                        if not varMach in platDict:
 250                            platDict[varMach] = {}
 251                        platDict[varMach][varName] = varValu
 252                    else:
 253                        # The guard will compare varValu to $MACHINETYPE (this is just the hostname of the machine on which localize.py is running).
 254 arta  1.3              if not varMach in machDict:
 255                            machDict[varMach] = {}
 256                        machDict[varMach][varName] = varValu
 257            
 258 arta  1.6  def processParam(cfgfile, line, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, platDict, machDict, section):
 259 arta  1.1      status = 0
 260                        
 261                if ''.join(section) == 'defs' or not cfgfile:
 262                    matchobj = regexp.match(line)
 263                    if not matchobj is None:
 264                        # We have a key-value line
 265                        keyCfgSp = matchobj.group(1)
 266                        val = matchobj.group(2)
 267                        
 268                        # Must map the indirect name to the actual name
 269                        if keymap:
 270                            # Map to actual name only if the keymap is not empty (which signifies NA).
 271                            if keyCfgSp in keymap:
 272                                key = keymap[keyCfgSp]
 273                            elif keyCfgSp == 'LOCAL_CONFIG_SET' or keyCfgSp == 'DRMS_SAMPLE_NAMESPACE':
 274 arta  1.6                      # Ignore parameters that are not useful and shouldn't have been there in the first place. But
 275                                # they have been released to the world, so we have to account for them.
 276 arta  1.1                      return bool(0)
 277                            elif not cfgfile:
 278                                # Should not be doing mapping for addenda
 279                                key = keyCfgSp
 280                            else:
 281                                raise Exception('badKeyMapKey', keyCfgSp)
 282                        else:
 283                            key = keyCfgSp
 284                        
 285                        matchobj = regexpQuote.match(key)
 286                        if not matchobj is None:
 287                            quote = matchobj.group(1)
 288                            key = matchobj.group(2)
 289            
 290                            # master defs dictionary
 291                            defs[key] = val
 292                            
 293                            # C header file
 294                            if quote == "q":
 295                                # Add double-quotes
 296                                cDefs.extend(list(createMacroStr(key, '"' + val + '"', 40, status)))
 297 arta  1.1                  elif quote == "p":
 298                                # Add parentheses
 299                                cDefs.extend(list(createMacroStr(key, '(' + val + ')', 40, status)))
 300                            elif quote == "a":
 301                                # Leave as-is
 302                                cDefs.extend(list(createMacroStr(key, val, 40, status)))
 303                            else:
 304                                # Unknown quote type
 305                                raise Exception('badQuoteQual', key)
 306                            
 307                            if status:
 308                                raise Exception('paramNameTooLong', key)
 309                            
 310                            # Make file - val should never be quoted; just use as is
 311 arta  1.4                  mDefsGen.extend(list('\n' + key + ' = ' + val))
 312 arta  1.1                  
 313                            # Perl file - val should ALWAYS be single-quote quoted
 314                            # Save const info to a string
 315                            perlConstSection.extend(list(createPerlConst(key, "'" + val + "'", 40, status)))
 316                            
 317                            if status:
 318                                raise Exception('paramNameTooLong', key)
 319                            
 320                            # Save initialization information as a string. Now that we've defined
 321                            # constants (the names of which are the parameter names) 
 322                            # we can refer to those in the init section. The key variable holds the
 323                            # name of the constant.
 324 arta  1.9                  perlInitSection.extend(list("\n  $self->{_paramsH}->{'" + key + "'} = " + key + ';'))
 325 arta  1.1              else:
 326                            # No quote qualifier
 327                            raise Exception('missingQuoteQual', key)
 328 arta  1.3      elif ''.join(section) == 'make' and cfgfile:
 329                    # Configure the remaining make variables defined in the __MAKE__ section of the configuration file. Third-party
 330                    # library make variables are specified in the __MAKE__ section.
 331                    matchobj = regexp.match(line)
 332                    if not matchobj is None:
 333                        # We have a key-value line
 334                        key = matchobj.group(1)
 335                        val = matchobj.group(2)
 336            
 337                        # This information is for making make variables only. We do not need to worry about quoting any values
 338                        defs[key] = val
 339 arta  1.4              processMakeParam(mDefsMake, key, val, platDict, machDict)
 340 arta  1.1      
 341                return bool(0)
 342            
 343            # We have some extraneous line or a newline - ignore.
 344            
 345 arta  1.6  def processXML(xml, projRules, projTarget):
 346                rv = bool(0)
 347                
 348                # <projects>
 349                root = ET.fromstring(xml)
 350                
 351                # Iterate through each proj child.
 352                for proj in root.iter('proj'):
 353                    # Rules.mk
 354                    nameElem = proj.find('name')
 355                    rulesStr = 'dir     := $(d)/' + nameElem.text + '\n-include          $(SRCDIR)/$(dir)/Rules.mk\n'
 356                    
 357                    # make doesn't support logical operations in ifeq conditionals (you can't do ifeq (A AND B)), 
 358                    # so we need to write:
 359                    #   ifeq (A)
 360                    #      ifeq (B)
 361                    #        <do something>
 362                    #      endif
 363                    #   endif
 364                        
 365                    rulesPref = '';
 366 arta  1.6          rulesSuff = '';
 367                
 368                    filters = proj.find('filters')
 369                    if filters is not None:
 370                        for filter in filters.findall('filter'):
 371                            rulesPref += 'ifeq ($(' + filter.find('name').text + '),' + filter.find('value').text + ')\n'
 372                            rulesSuff += 'endif\n'
 373                        
 374                    if len(rulesPref) > 0 and len(rulesSuff) > 0:
 375                        projRules.extend(list(rulesPref))
 376                        projRules.extend(list(rulesStr))
 377                        projRules.extend(list(rulesSuff))
 378                    else:
 379                        projRules.extend(list(rulesStr))
 380                    
 381                    # target.mk
 382                    subdirs = proj.find('subdirs')
 383                    if subdirs is not None:
 384                        for subdir in subdirs.findall('subdir'):
 385                            targetStr = '\n\t+@[ -d $@/' + nameElem.text + '/' + subdir.text + ' ] || mkdir -p $@/' + nameElem.text + '/' + subdir.text
 386                            projTarget.extend(list(targetStr))
 387 arta  1.6  
 388                return rv
 389            
 390            def determineSection(line, regexpDefs, regexpMake, regexpProjMkRules, regexpProj, regexpProjCfg):
 391                matchobj = regexpDefs.match(line)
 392                if not matchobj is None:
 393                    return 'defs'
 394                    
 395                matchobj = regexpMake.match(line)
 396                if not matchobj is None:
 397                    return 'make'
 398                    
 399                matchobj = regexpProjMkRules.match(line)
 400                if not matchobj is None:
 401                    return 'projmkrules'
 402                    
 403                matchobj = regexpProj.match(line)
 404                if not matchobj is None:
 405                    return 'proj'
 406                    
 407                matchobj = regexpProjCfg.match(line)
 408 arta  1.6      if not matchobj is None:
 409                    return 'projcfg'
 410            
 411                return None
 412            
 413 arta  1.1  # defs is a dictionary containing all parameters (should they be needed in this script)
 414 arta  1.6  # projCfg is the list containing the configure script content.
 415            # projMkRules is the list containing the make_basic.mk content.
 416            # projRules is the list containing the Rules.mk content.
 417            # projTargert is the list containing the target.mk content.
 418            def parseConfig(fin, keymap, addenda, defs, cDefs, mDefsGen, mDefsMake, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection):
 419 arta  1.1      rv = bool(0)
 420                
 421                # Open required config file (config.local)
 422                try:
 423                    # Examine each line, looking for key=value pairs.
 424                    regexpDefs = re.compile(r"^__DEFS__")
 425                    regexpMake = re.compile(r"^__MAKE__")
 426 arta  1.6          regexpProjMkRules = re.compile(r"__PROJ_MK_RULES__")
 427                    regexpProj = re.compile(r"^__PROJ__")
 428                    regexpProjCfg = re.compile(r"^__PROJCFG__")
 429 arta  1.1          regexpComm = re.compile(r"^\s*#")
 430 arta  1.6          regexpSp = re.compile(r"^s*$")
 431 arta  1.1          regexpQuote = re.compile(r"^\s*(\w):(.+)")
 432 arta  1.6          regexpCustMkBeg = re.compile(r"^_CUST_")
 433                    regexpCustMkEnd = re.compile(r"^_ENDCUST_")
 434                    regexpDiv = re.compile(r"^__")
 435 arta  1.11         regexp = re.compile(r"^\s*(\S+)\s+(\S.*)")
 436 arta  1.1          
 437 arta  1.3          platDict = {}
 438                    machDict = {}
 439 arta  1.6          
 440                    xml = None
 441 arta  1.1          
 442                    # Process the parameters in the configuration file
 443                    if not fin is None:
 444                        for line in fin:
 445 arta  1.6                  matchobj = regexpComm.match(line)
 446                            if not matchobj is None:
 447                                # Skip comment line
 448                                continue
 449                            
 450                            matchobj = regexpSp.match(line)
 451                            if not matchobj is None:
 452                                # Skip whitespace line
 453                                continue
 454 arta  1.1              
 455 arta  1.6                  newSection = determineSection(line, regexpDefs, regexpMake, regexpProjMkRules, regexpProj, regexpProjCfg)
 456                            if not newSection is None:
 457                                section = newSection
 458                
 459                            if section == 'make':
 460 arta  1.10 
 461 arta  1.6                      # There are some blocks of lines in the __MAKE__ section that must be copied ver batim to the output make file. 
 462                                # The blocks are defined by _CUST_/_ENDCUST_ tags.
 463                                matchobj = regexpCustMkBeg.match(line)
 464                                    
 465                                if not matchobj is None:
 466                                    mDefsMake.extend(list('\n'))
 467                                    for line in fin:
 468                                        matchobj = regexpCustMkEnd.match(line)
 469                                        if not matchobj is None:
 470                                            break;
 471                                        mDefsMake.extend(list(line))
 472                                    newSection = determineSection(line, regexpDefs, regexpMake, regexpProjMkRules, regexpProj, regexpProjCfg)
 473                                    if not newSection is None:
 474                                        section = newSection
 475                                    continue
 476                                # Intentional fall through to next if statement
 477                            if section == 'defs' or section == 'make':
 478                                iscfg = bool(1)
 479                                ppRet = processParam(iscfg, line, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, platDict, machDict, section)
 480 arta  1.10                     
 481 arta  1.6                      if ppRet:
 482 arta  1.10                         break
 483 arta  1.6                  elif section == 'projcfg':
 484                                # Copy the line ver batim to the projCfg list (configure)
 485                                for line in fin:
 486                                    matchobj = regexpDiv.match(line)
 487                                    if not matchobj is None:
 488                                        break;
 489                                    projCfg.extend(list(line))
 490                                newSection = determineSection(line, regexpDefs, regexpMake, regexpProjMkRules, regexpProj, regexpProjCfg)
 491                                if not newSection is None:
 492                                    section = newSection
 493                                continue
 494                            elif section == 'projmkrules':
 495                                # Copy the line ver batim to the projMkRules list (make_basic.mk)
 496                                for line in fin:
 497                                    matchobj = regexpDiv.match(line)
 498                                    if not matchobj is None:
 499                                        break;
 500                                    projMkRules.extend(list(line))
 501                                newSection = determineSection(line, regexpDefs, regexpMake, regexpProjMkRules, regexpProj, regexpProjCfg)
 502                                if not newSection is None:
 503                                    section = newSection
 504 arta  1.6                      continue
 505                            elif section == 'proj':
 506                                # Must parse xml and use the project-specific information to populate the Rules.mk and target.mk files.
 507                                # Collect all xml lines for now, then process after file-read loop.
 508                                if xml is None:
 509                                    xml = line
 510                                else:
 511                                    xml += line
 512                            else:
 513 arta  1.10                     # Unknown section
 514 arta  1.6                      raise Exception('unknownSection', section)
 515 arta  1.1      except Exception as exc:
 516 arta  1.17         if len(exc.args) >= 2:
 517                        msg = exc.args[0]
 518                    else:
 519                        # re-raise the exception
 520                        raise
 521 arta  1.1          if msg == 'badKeyMapKey':
 522                        # If we are here, then there was a non-empty keymap, and the parameter came from
 523                        # the configuration file.
 524 arta  1.6              violator = exc.args[1]
 525 arta  1.17             print('Unknown parameter name ' + "'" + violator + "'" + ' in ' + fin.name + '.', file=sys.stderr)
 526 arta  1.1              rv = bool(1)
 527                    elif msg == 'badQuoteQual':
 528                        # The bad quote qualifier came from the configuration file, not the addenda, since
 529                        # we will have fixed any bad qualifiers in the addenda (which is populated by code).
 530 arta  1.6              violator = exc.args[1]
 531 arta  1.17             print('Unknown quote qualifier ' + "'" + violator + "'" + ' in ' + fin.name + '.', file=sys.stderr)
 532 arta  1.1              rv = bool(1)
 533                    elif msg == 'missingQuoteQual':
 534 arta  1.6              violator = exc.args[1]
 535 arta  1.17             print('Missing quote qualifier for parameter ' + "'" + violator + "'" + ' in ' + fin.name + '.', file=sys.stderr)
 536 arta  1.1              rv = bool(1)
 537                    elif msg == 'paramNameTooLong':
 538 arta  1.6              violator = exc.args[1]
 539 arta  1.1              print('Macro name ' + "'" + violator + "' is too long.", file=sys.stderr)
 540                        rv = bool(1)
 541 arta  1.6          elif msg == 'unknownSection':
 542                        violator = exc.args[1]
 543                        print('Unknown section ' + "'" + violator + "' in configuration file.", file=sys.stderr)
 544                        rv = bool(1)
 545 arta  1.1          else:
 546                        # re-raise the exception
 547                        raise
 548            
 549 arta  1.6      if not rv:
 550                    if not xml is None:
 551                        # Process xml.
 552                        projRules.extend(list(RULESPREFIX))
 553                        projTarget.extend(list(TARGETPREFIX))            
 554                        rv = processXML(xml, projRules, projTarget)
 555                        projRules.extend(RULESSUFFIX)
 556            
 557                # Process addenda - these are parameters that are not configurable and must be set in the 
 558                # NetDRMS build.
 559                if not rv:
 560                    iscfg = bool(0)
 561                    for key in addenda:
 562                        item = key + ' ' + addenda[key]
 563                        ppRet = processParam(iscfg, item, regexpQuote, regexp, keymap, defs, cDefs, mDefsGen, mDefsMake, perlConstSection, perlInitSection, platDict, machDict, 'defs')
 564                        if ppRet:
 565                            break;
 566            
 567 arta  1.4      # Put information collected in platDict and machDict into mDefs. Must do this here, and not in processParam, since
 568                # we need to parse all platform-specific make variables before grouping them into platform categories.
 569 arta  1.3      if not rv:
 570                    for plat in platDict:
 571 arta  1.4              mDefsMake.extend(list('\nifeq ($(JSOC_MACHINE), linux_' + plat.lower() + ')'))
 572 arta  1.3              for var in platDict[plat]:
 573 arta  1.4                  mDefsMake.extend(list('\n' + var + ' = ' + platDict[plat][var]))
 574                        mDefsMake.extend(list('\nendif\n'))
 575 arta  1.3                               
 576                if not rv:
 577                    for mach in machDict:
 578 arta  1.4              mDefsMake.extend(list('\nifeq ($(MACHTYPE), ' + mach + ')'))
 579 arta  1.7              for var in machDict[mach]:
 580                            mDefsMake.extend(list('\n' + var + ' = ' + machDict[mach][var]))
 581 arta  1.4              mDefsMake.extend(list('\nendif\n'))
 582 arta  1.1      return rv
 583            
 584            def getMgrUIDLine(defs, uidParam):
 585                rv = bool(0)
 586                
 587                cmd = 'id -u ' + defs['SUMS_MANAGER']
 588                try:
 589                    ret = check_output(cmd, shell=True)
 590                    uidParam['q:SUMS_MANAGER_UID'] = ret.decode("utf-8")
 591                except ValueError:
 592                    print('Unable to run cmd: ' + cmd + '.')
 593                    rv = bool(1)
 594                except CalledProcessError:
 595                    print('Command ' + "'" + cmd + "'" + ' ran improperly.')
 596                    rv = bool(1)
 597            
 598                return rv
 599            
 600 arta  1.3  def isVersion(maj, min, majDef, minDef):
 601                res = 0
 602                
 603                if maj > majDef or (maj == majDef and min >= minDef):
 604                    res = 1
 605                
 606                return res
 607            
 608            def configureComps(defs, mDefs):
 609                rv = bool(0)
 610 arta  1.6      autoConfig = bool(1)
 611            
 612                if 'AUTOSELCOMP' in defs:
 613                    autoConfig = (not defs['AUTOSELCOMP'] == '0')
 614 arta  1.3      
 615                if autoConfig:
 616                    hasicc = bool(0)
 617                    hasgcc = bool(0)
 618                    hasifort = bool(0)
 619                    hasgfort = bool(0)
 620                    
 621                    # Try icc.
 622 arta  1.12         cmd = 'icc --version 2>&1'
 623 arta  1.3          try:
 624                        ret = check_output(cmd, shell=True)
 625                        ret = ret.decode("utf-8")
 626                    except CalledProcessError:
 627                        print('Command ' + "'" + cmd + "'" + ' ran improperly.')
 628                        rv = bool(1)
 629                    
 630 arta  1.6          if not rv:
 631 arta  1.12             regexp = re.compile(r"\s*\S+\s+\S+\s+(\d+)[.](\d+)", re.DOTALL)
 632 arta  1.3              matchobj = regexp.match(ret)
 633                        if matchobj is None:
 634                            raise Exception('unexpectedIccRet', ret)
 635                        else:
 636                            major = matchobj.group(1)
 637                            minor = matchobj.group(2)
 638                            if isVersion(int(major), int(minor), ICC_MAJOR, ICC_MINOR):
 639                                hasicc = bool(1)
 640                        
 641                    # Try gcc.
 642                    if not hasicc:
 643                        cmd = 'gcc -v 2>&1'
 644                        try:
 645                            ret = check_output(cmd, shell=True)
 646                            ret = ret.decode("utf-8")
 647                        except CalledProcessError:
 648                            print('Command ' + "'" + cmd + "'" + ' ran improperly.')
 649                            rv = bool(1)
 650            
 651                        if rv == bool(0):
 652                            regexp = re.compile(r".+gcc\s+version\s+(\d+)\.(\d+)", re.DOTALL)
 653 arta  1.3                  matchobj = regexp.match(ret)
 654                            if matchobj is None:
 655                                raise Exception('unexpectedGccRet', ret)
 656                            else:
 657                                major = matchobj.group(1)
 658                                minor = matchobj.group(2)
 659                                if isVersion(int(major), int(minor), GCC_MAJOR, GCC_MINOR):
 660                                    hasgcc = bool(1)
 661            
 662                    # Try ifort.
 663 arta  1.12         cmd = 'ifort --version 2>&1'
 664 arta  1.3          try:
 665                        ret = check_output(cmd, shell=True)
 666                        ret = ret.decode("utf-8")
 667                    except CalledProcessError:
 668                        print('Command ' + "'" + cmd + "'" + ' ran improperly.')
 669                        rv = bool(1)
 670            
 671 arta  1.6          if not rv:
 672 arta  1.12             regexp = re.compile(r"\s*\S+\s+\S+\s+(\d+)\.(\d+)", re.DOTALL)
 673 arta  1.3              matchobj = regexp.match(ret)
 674                        if matchobj is None:
 675                            raise Exception('unexpectedIfortRet', ret)
 676                        else:
 677                            major = matchobj.group(1)
 678                            minor = matchobj.group(2)
 679                            if isVersion(int(major), int(minor), IFORT_MAJOR, IFORT_MINOR):
 680                                hasifort = bool(1)
 681                    
 682                    # Try gfortran
 683                    if not hasifort:
 684                        cmd = 'gfortran -v 2>&1'
 685                        try:
 686                            ret = check_output(cmd, shell=True)
 687                            ret = ret.decode("utf-8")
 688                        except CalledProcessError:
 689                            print('Command ' + "'" + cmd + "'" + ' ran improperly.')
 690                            rv = bool(1)
 691            
 692                        if rv == bool(0):
 693                            regexp = re.compile(r".+gcc\s+version\s+(\d+)\.(\d+)", re.DOTALL)
 694 arta  1.3                  matchobj = regexp.match(ret)
 695                            if matchobj is None:
 696                                raise Exception('unexpectedGfortranRet', ret)
 697                            else:
 698                                major = matchobj.group(1)
 699                                minor = matchobj.group(2)
 700                                if isVersion(int(major), int(minor), GFORT_MAJOR, GFORT_MINOR):
 701                                    hasgfort = bool(1)
 702                    
 703                    # Append the compiler make variables to the make file 
 704                    if not hasicc and not hasgcc:
 705                        print('Fatal error: Acceptable C compiler not found! You will be unable to build the DRMS library.', file=sys.stderr)
 706                        rv = bool(1)
 707                    elif hasicc:
 708                        mDefs.extend(list('\nCOMPILER = icc'))
 709                    else:
 710                        mDefs.extend(list('\nCOMPILER = gcc'))
 711            
 712                    if not hasifort and not hasgfort:
 713                        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)
 714                    elif hasifort:
 715 arta  1.3              mDefs.extend(list('\nFCOMPILER = ifort'))
 716                    else:
 717                        mDefs.extend(list('\nFCOMPILER = gfortran'))
 718                
 719                    # Environment overrides. These get written, regardless of the disposition of auto-configuration.
 720 arta  1.9          mDefs.extend(list('\nifneq ($(JSOC_COMPILER),)\n  COMPILER = $(JSOC_COMPILER)\nendif'))
 721                    mDefs.extend(list('\nifneq ($(JSOC_FCOMPILER),)\n  FCOMPILER = $(JSOC_FCOMPILER)\nendif'))
 722 arta  1.3  
 723                return rv
 724            
 725 arta  1.6  def writeParamsFiles(base, cfile, mfile, pfile, cDefs, mDefsGen, mDefsMake, mDefsComps, perlConstSection, perlInitSection):
 726 arta  1.1      rv = bool(0)
 727 arta  1.4  
 728                # Merge mDefsGen, mDefsMake, and mDefsComps into a single string with compiler configuration first, general parameters next, then
 729                # make-specific make variables (e.g., third-party library information) last.
 730                mDefs = '\n# Compiler Selection\n' + ''.join(mDefsComps) + '\n\n# General Parameters\n' + ''.join(mDefsGen) + '\n\n# Parameters to Configure make\n' + ''.join(mDefsMake)
 731 arta  1.1      
 732                try:
 733                    with open(cfile, 'w') as cout, open(mfile, 'w') as mout, open(pfile, 'w') as pout:
 734                        # C file of macros
 735 arta  1.2              print(C_PREFIX, file=cout)
 736                        print('/* This file contains a set of preprocessor macros - one for each configuration parameter. */\n', file=cout)
 737 arta  1.1              buf = '__' + base.upper() + '_H'
 738                        print('#ifndef ' + buf, file=cout)
 739                        print('#define ' + buf, file=cout)
 740                        print(''.join(cDefs), file=cout)
 741                        print('#endif', file=cout)
 742                        
 743                        # Make file of make variables
 744 arta  1.2              print(PREFIX, file=mout)
 745 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)
 746                        print(mDefs, file=mout)
 747 arta  1.1              
 748 arta  1.2              # Perl module
 749                        print(PERL_BINPATH, file=pout)
 750                        print(PREFIX, file=pout)
 751                        print('# This file contains a set of constants - one for each configuration parameter.\n', file=pout)
 752                        print(PERL_INTIAL, file=pout)
 753 arta  1.1              print(''.join(perlConstSection), file=pout)
 754 arta  1.2              print(PERL_FXNS_A, file=pout)
 755 arta  1.1              print('sub initialize', file=pout)
 756                        print('{', file=pout)
 757 arta  1.2              print('  my($self) = shift;', file=pout, end='')
 758 arta  1.1              print('', file=pout)
 759                        print(''.join(perlInitSection), file=pout)
 760 arta  1.2              print('}\n', file=pout)
 761                        print(PERL_FXNS_B, file=pout)
 762 arta  1.1      except IOError as exc:
 763 arta  1.6          type, value, traceback = sys.exc_info()
 764                    print(exc.strerror, file=sys.stderr)
 765                    print('Unable to open ' + "'" + value.filename + "'.", file=sys.stderr)        
 766                    rv = bool(1)
 767            
 768                return rv
 769            
 770            def writeProjFiles(pCfile, pMfile, pRfile, pTfile, projCfg, projMkRules, projRules, projTarget):
 771                rv = bool(0)
 772            
 773                try:
 774                    if projCfg:
 775                        with open(pCfile, 'w') as cout:
 776                            # configure
 777                            print(''.join(projCfg), file=cout)
 778                    
 779                    if projMkRules:
 780                        with open(pMfile, 'w') as mout:
 781                            # make_basic.mk
 782                            print(PREFIX, file=mout)
 783                            print(''.join(projMkRules), file=mout)
 784 arta  1.6      
 785                    if projRules:
 786                        with open(pRfile, 'w') as rout:
 787                            # Rules.mk
 788                            print(PREFIX, file=rout)
 789                            print(''.join(projRules), file=rout)
 790                    
 791                    if projTarget:
 792                        with open(pTfile, 'w') as tout:
 793                            # target.mk
 794                            print(PREFIX, file=tout)
 795 arta  1.10                 print(''.join(projTarget), file=tout)
 796 arta  1.6      except IOError as exc:
 797                    type, value, traceback = sys.exc_info()
 798                    print(exc.strerror, file=sys.stderr)
 799                    print('Unable to open ' + "'" + value.filename + "'.", file=sys.stderr)
 800 arta  1.1          rv = bool(1)
 801            
 802 arta  1.6      if not rv:
 803 arta  1.10         if os.path.exists(pCfile):
 804                        try:
 805                            os.chmod(pCfile, stat.S_IRWXU | stat.S_IRGRP | stat.S_IROTH)
 806                        except OSError as exc:
 807                            type, value, traceback = sys.exc_info()
 808                            print('Unable to chmod file ' + "'" + value.filename + "'.", file=sys.stderr)
 809                            print(exc.strerror, file=sys.stderr)
 810                            rv = bool(1)
 811 arta  1.6  
 812 arta  1.1      return rv
 813 arta  1.3  
 814 arta  1.13 def generateSumRmCfg(defs):
 815                rv = bool(0)
 816                # ACK! Remember that Rick renamed these parameters. The ones in config.local are the aliases - do not use those.
 817                # Use the ones that those map to (defined in config.local.map).
 818                cFileTmp = defs['SUMLOG_BASEDIR'] + '/' + '.sum_rm.cfg.tmp'
 819                cFile = defs['SUMLOG_BASEDIR'] + '/' + 'sum_rm.cfg'
 820            
 821                # Write a temporary file sum_rm configuration file.
 822                try:
 823                    with open(cFileTmp, 'w') as fout:
 824                        # Print comment at the top of the configuration file.
 825                        print(SUMRM_COMMENT, file=fout)
 826                        print(SUMRM_DOC, file=fout)
 827                        print(SUMRM_PARTN_PERCENT_FREE, file=fout)
 828                        if 'SUMRM_PART_PERCENT_FREE' in defs:
 829                            print('PART_PERCENT_FREE=' + defs['SUMRM_PART_PERCENT_FREE'], file=fout)
 830                        else:
 831                            print('PART_PERCENT_FREE=3', file=fout)
 832            
 833                        print(SUMRM_SLEEP, file=fout)
 834                        if 'SUMRM_SLEEP' in defs:
 835 arta  1.13                 print('SLEEP=' + defs['SUMRM_SLEEP'], file=fout)
 836                        else:
 837                            print('SLEEP=300', file=fout)
 838            
 839                        print(SUMRM_LOG, file=fout)
 840                        if 'SUMRM_LOG' in defs:
 841                            print('LOG=' + defs['SUMRM_LOG'], file=fout)
 842                        else:
 843                            print('LOG=/tmp/sum_rm.log', file=fout)
 844            
 845                        print(SUMRM_MAIL, file=fout)
 846                        # No default for mail - don't send nothing to nobody unless the operator has asked for notifications.
 847                        if 'SUMRM_MAIL' in defs:
 848                            print('MAIL=' + defs['SUMRM_MAIL'], file=fout)
 849                        else:
 850                            print('# MAIL=president@whitehouse.gov', file=fout)
 851            
 852                        print(SUMRM_NOOP, file=fout)
 853                        if 'SUMRM_NOOP' in defs:
 854                            print('NOOP=' + defs['SUMRM_NOOP'], file=fout)
 855                        else:
 856 arta  1.13                 print('NOOP=0', file=fout)
 857            
 858                        print(SUMRM_USER, file=fout)
 859                        if 'SUMRM_USER' in defs:
 860                            print('USER=' + defs['SUMRM_USER'], file=fout)
 861                        else:
 862                            print('USER=production', file=fout)
 863            
 864                        print(SUMRM_NORUN, file=fout)
 865                        # Default norun window is to have no such window. This can be accomplished by simply not providing either argument.
 866                        if 'SUMRM_NORUN_START' in defs or 'SUMRM_NORUN_STOP' in defs:
 867                            if 'SUMRM_NORUN_START' in defs:
 868                                print('NORUN_START=' + defs['SUMRM_NORUN_START'], file=fout)
 869                            else:
 870                                print('NORUN_START=0', file=fout)
 871                            if 'SUMRM_NORUN_STOP' in defs:
 872                                print('NORUN_STOP=' + defs['SUMRM_NORUN_STOP'], file=fout)
 873                            else:
 874                                print('NORUN_STOP=0', file=fout)
 875                        else:
 876                            print('# NORUN_START=0', file=fout)
 877 arta  1.13                 print('# NORUN_STOP=0', file=fout)
 878                        
 879                except OSError:
 880                    print('Unable to open sum_rm temporary configuration file ' + cFileTmp + 'for writing.', file=sys.stderr)
 881                    rv = bool(1)
 882            
 883                # If the content of the temporary file differs from the content of the existing configuration file, then overwrite
 884                # the original file. Otherwise, delete the temporary file
 885                if not rv:
 886                    try:
 887                        if filecmp.cmp(cFile, cFileTmp):
 888                            # Files identical - delete temporary file
 889                            try:
 890                                os.remove(cFileTmp)
 891                            
 892                            except OSError as exc:
 893                                print('Unable to remove temporary file ' + exc.filename + '.', file=sys.stderr)
 894                                print(exc.strerr, file=sys.stderr)
 895                        else:
 896                            # Replace original with temporary file
 897                            try:
 898 arta  1.13                     os.rename(cFileTmp, cFile)
 899            
 900                            except OSError as exc:
 901                                print('Unable to update sum_rm configuration file ' + cFile + '.', file=sys.stderr)
 902                                print(exc.strerr, file=sys.stderr)
 903                                rv = bool(1)
 904                    except OSError as exc:
 905                        # One of the files doesn't exist.
 906                        if exc.filename == cFile:
 907                            # We are ok - there might be no configuration file yet.
 908                            # Replace original with temporary file
 909                            try:
 910                                os.rename(cFileTmp, cFile)
 911            
 912                            except OSError as exc:
 913                                print('Unable to update sum_rm configuration file ' + cFile + '.', file=sys.stderr)
 914                                print(exc.strerr, file=sys.stderr)
 915                                rv = bool(1)
 916                        else:
 917                            # There is a problem with the temp file - bail.
 918                            print('Unable to update sum_rm configuration file ' + cFile + '.', file=sys.stderr)
 919 arta  1.13                 print(exc.strerr, file=sys.stderr)
 920                            rv = bool(1)
 921            
 922                return rv
 923            
 924            def configureNet(cfgfile, cfile, mfile, pfile, pCfile, pMfile, pRfile, pTfile, base, keymap, createSumRmCfg):
 925 arta  1.1      rv = bool(0)
 926                
 927                defs = {}
 928                cDefs = list()
 929 arta  1.4      mDefsGen = list()
 930                mDefsMake = list()
 931                mDefsComps = list()
 932 arta  1.6      projCfg = list()
 933                projMkRules = list()
 934                projRules = list()
 935                projTarget = list()
 936 arta  1.1      perlConstSection = list()
 937                perlInitSection = list()
 938 arta  1.2      addenda = {}
 939                
 940 arta  1.6      # There are three parameters that were not included in the original config.local parameter set, for some reason.
 941                # Due to this omission, then are not configurable, and must be set in the script.
 942 arta  1.2      addenda['a:USER'] = 'NULL'
 943                addenda['a:PASSWD'] = 'NULL'
 944                addenda['p:DSDS_SUPPORT'] = '0'
 945 arta  1.6      
 946                # This parameter is not configurable. BUILD_TYPE is used to distinguish between a NetDRMS and an JSOC-SDP build.
 947 arta  1.2      addenda['a:BUILD_TYPE'] = 'NETDRMS' # Means a non-Stanford build. This will set two additional macros used by make:
 948                                                    #   __LOCALIZED_DEFS__ and NETDRMS_BUILD. The former is to support legacy code
 949                                                    #   which incorrectly used this macro, and the latter is for future use. 
 950                                                    #   __LOCALIZED_DEFS__ is deprecated and should not be used in new code.
 951 arta  1.1  
 952                try:
 953                    with open(cfgfile, 'r') as fin:
 954 arta  1.3              # Process configuration parameters
 955 arta  1.6              rv = parseConfig(fin, keymap, addenda, defs, cDefs, mDefsGen, mDefsMake, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection)
 956                        if not rv:
 957 arta  1.3                  # Must add a parameter for the SUMS_MANAGER UID (for some reason). This must be done after the
 958                            # config file is processed since an input to getMgrUIDLine() is one of the config file's
 959                            # parameter values.
 960 arta  1.1                  uidParam = {}
 961                            rv = getMgrUIDLine(defs, uidParam)
 962                            if rv == bool(0):
 963 arta  1.6                      rv = parseConfig(None, keymap, uidParam, defs, cDefs, mDefsGen, None, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection)
 964 arta  1.3              # Configure the compiler-selection make variables.
 965 arta  1.6              if not rv:
 966 arta  1.4                  rv = configureComps(defs, mDefsComps)
 967 arta  1.1  
 968 arta  1.3              # Write out the parameter files.
 969 arta  1.6              if not rv:
 970                            rv = writeParamsFiles(base, cfile, mfile, pfile, cDefs, mDefsGen, mDefsMake, mDefsComps, perlConstSection, perlInitSection)
 971 arta  1.13 
 972 arta  1.6              # Write out the project-specific make files (make_basic.mk, Rules.mk, and target.mk).
 973                        if not rv:
 974                            rv = writeProjFiles(pCfile, pMfile, pRfile, pTfile, projCfg, projMkRules, projRules, projTarget)
 975 arta  1.13 
 976                        # Write out the sum_rm.cfg file.
 977                        if not rv and createSumRmCfg:
 978                            rv = generateSumRmCfg(defs)
 979 arta  1.1      except IOError as exc:
 980 arta  1.6          print(exc.strerror, file=sys.stderr)
 981                    print('Unable to read configuration file ' + cfgfile + '.', file=sys.stderr)
 982 arta  1.3      except Exception as exc:
 983 arta  1.16         if len(exc.args) >= 2:
 984 arta  1.14             type, msg = exc.args
 985                    else:
 986                        # re-raise the exception
 987                        raise
 988            
 989 arta  1.3          if type == 'unexpectedIccRet':
 990                        print('icc -V returned this unexpected message:\n' + msg, file=sys.stderr)
 991                        rv = bool(1)
 992                    elif type == 'unexpectedGccRet':
 993                        print('gcc -v returned this unexpected message:\n' + msg, file=sys.stderr)
 994                        rv = bool(1)
 995                    elif type == 'unexpectedIfortRet':
 996                        print('ifort -V returned this unexpected message:\n' + msg, file=sys.stderr)
 997                        rv = bool(1)
 998                    elif type == 'unexpectedGfortranRet':
 999                        print('gfortran -v returned this unexpected message:\n' + msg, file=sys.stderr)
1000                        rv = bool(1)
1001                    else:
1002                        # re-raise the exception
1003                        raise
1004 arta  1.1          
1005 arta  1.2      return rv
1006 arta  1.1  
1007 arta  1.6  def configureSdp(cfgfile, cfile, mfile, pfile, pCfile, pMfile, pRfile, pTfile, base):
1008 arta  1.1      rv = bool(0)
1009                
1010                defs = {}
1011                cDefs = list()
1012 arta  1.5      mDefsGen = list()
1013                mDefsMake = list()
1014 arta  1.6      projCfg = list()
1015                projMkRules = list()
1016                projRules = list()
1017                projTarget = list()
1018 arta  1.5      mDefsComps = list()
1019 arta  1.1      perlConstSection = list()
1020                perlInitSection = list()
1021 arta  1.2      addenda = {}
1022                
1023 arta  1.6      # There are three parameters that were not included in the original config.local parameter set, for some reason.
1024                # Due to this omission, then are not configurable, and must be set in the script.
1025 arta  1.5      addenda['a:USER'] = 'NULL'
1026                addenda['a:PASSWD'] = 'NULL'
1027                addenda['p:DSDS_SUPPORT'] = '1'
1028 arta  1.6      
1029                # This parameter is not configurable. BUILD_TYPE is used to distinguish between a NetDRMS and an JSOC-SDP build.
1030 arta  1.5      addenda['a:BUILD_TYPE'] = 'JSOC_SDP' # Means a Stanford build. This will set one additional macro used by make: JSOC_SDP_BUILD.
1031 arta  1.1      
1032                try:
1033                    with open(cfgfile, 'r') as fin:
1034 arta  1.6              rv = parseConfig(fin, None, addenda, defs, cDefs, mDefsGen, mDefsMake, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection)
1035                        
1036                        if not rv:
1037 arta  1.2                  # Must add a parameter for the SUMS_MANAGER UID (for some reason)
1038                            uidParam = {}
1039                            rv = getMgrUIDLine(defs, uidParam)
1040 arta  1.6                  if not rv:
1041                                rv = parseConfig(None, None, uidParam, defs, cDefs, mDefsGen, None, projCfg, projMkRules, projRules, projTarget, perlConstSection, perlInitSection)
1042            
1043 arta  1.5                  # Configure the compiler-selection make variables.
1044 arta  1.6                  if not rv:
1045 arta  1.5                      rv = configureComps(defs, mDefsComps)
1046 arta  1.3                  
1047 arta  1.6                  # Write out the parameter files.
1048                            if not rv:
1049                                rv = writeParamsFiles(base, cfile, mfile, pfile, cDefs, mDefsGen, mDefsMake, mDefsComps, perlConstSection, perlInitSection)
1050            
1051                            # Write out the project-specific make files (make_basic.mk, Rules.mk, and target.mk).
1052                            if not rv:
1053                                rv = writeProjFiles(pCfile, pMfile, pRfile, pTfile, projCfg, projMkRules, projRules, projTarget)
1054 arta  1.13 
1055                            # At Stanford, skip the creation of the sum_rm configuration file. config.local will still
1056                            # have the SUMRM parameters, but they will not be used.
1057 arta  1.1      except IOError as exc:
1058 arta  1.6          print(exc.strerror, file=sys.stderr)
1059                    print('Unable to read configuration file ' + cfgfile + '.', file=sys.stderr)
1060 arta  1.5      except Exception as exc:
1061 arta  1.17         if len(exc.args) >= 2:
1062                        type = exc.args[0]
1063                    else:
1064                        # re-raise the exception
1065                        raise
1066                    
1067 arta  1.5          if type == 'unexpectedIccRet':
1068 arta  1.6              msg = exc.args[1]
1069 arta  1.5              print('icc -V returned this unexpected message:\n' + msg, file=sys.stderr)
1070                        rv = bool(1)
1071                    elif type == 'unexpectedGccRet':
1072 arta  1.6              msg = exc.args[1]
1073 arta  1.5              print('gcc -v returned this unexpected message:\n' + msg, file=sys.stderr)
1074                        rv = bool(1)
1075                    elif type == 'unexpectedIfortRet':
1076 arta  1.6              msg = exc.args[1]
1077 arta  1.5              print('ifort -V returned this unexpected message:\n' + msg, file=sys.stderr)
1078                        rv = bool(1)
1079                    elif type == 'unexpectedGfortranRet':
1080 arta  1.6              msg = exc.args[1]
1081 arta  1.5              print('gfortran -v returned this unexpected message:\n' + msg, file=sys.stderr)
1082                        rv = bool(1)
1083                    else:
1084                        # re-raise the exception
1085                        raise
1086                    
1087 arta  1.2      return rv
1088            
1089 arta  1.1  # Beginning of program
1090            rv = RET_SUCCESS
1091            net = bool(1)
1092            
1093            # Parse arguments
1094            if __name__ == "__main__":
1095                optD = GetArgs(sys.argv[1:])
1096            
1097            if not(optD is None):
1098                # Ensure we are configuring a DRMS tree
1099                cdir = os.path.realpath(os.getcwd())
1100                versfile = cdir + '/base/' + VERS_FILE
1101            
1102                if not os.path.isfile(versfile):
1103                    rv = RET_NOTDRMS
1104            
1105            # Determine whether we are localizing a Stanford build, or a NetDRMS build. If configsdp.txt exists, then
1106            # it is a Stanford build, otherwise it is a NetDRMS build.
1107            if rv == RET_SUCCESS:
1108                stanfordFile = cdir + '/' + SDP_CFG
1109                if os.path.isfile(stanfordFile):
1110 arta  1.1          net = bool(0)
1111                
1112                cfile = optD['dir'] + '/' + optD['base'] + '.h'
1113                mfile = optD['dir'] + '/' + optD['base'] + '.mk'
1114                pfile = optD['dir'] + '/' + optD['base'] + '.pm'
1115 arta  1.6      pCfile = optD['dir'] + '/configure'
1116                pMfile = optD['dir'] + '/make_basic.mk'
1117                pRfile = optD['dir'] + '/Rules.mk'
1118                pTfile = optD['dir'] + '/target.mk'
1119 arta  1.1  
1120                if net:
1121                    try:
1122                        with open(NET_CFGMAP, 'r') as fin:
1123                            regexpComm = re.compile(r"^\s*#")
1124                            regexp = re.compile(r"^\s*(\S+)\s+(\w:\S+)")
1125                            # Must map from config.local namespace to DRMS namespace (e.g., the names used for the C macros)
1126                            keymap = {}
1127                            for line in fin:
1128                                matchobj = regexpComm.match(line)
1129                                if not matchobj is None:
1130                                    # Skip comment line
1131                                    continue
1132            
1133                                matchobj = regexp.match(line)
1134                                if not(matchobj is None):
1135                                    # We have a key-value line
1136                                    key = matchobj.group(1)
1137                                    val = matchobj.group(2)
1138                                    keymap[key] = val
1139                    except OSError:
1140 arta  1.1              sys.stderr.write('Unable to read configuration map-file ' + NET_CFGMAP + '.')
1141                        rv = bool(1)
1142            
1143                    # We also need to set the UID of the SUMS manager. We have the name of the
1144                    # SUMS manager (it is in the configuration file)
1145 arta  1.13         configureNet(NET_CFG, cfile, mfile, pfile, pCfile, pMfile, pRfile, pTfile, optD['base'], keymap, 'server' in optD)
1146 arta  1.1      else:
1147 arta  1.8          # A Stanford user can override the parameters in configsdp.txt by copying that file to config.local, 
1148                    # and then editing config.local. So, if config.local exists, use that.
1149                    if os.path.isfile(cdir + '/' + NET_CFG):
1150                        configureSdp(NET_CFG, cfile, mfile, pfile, pCfile, pMfile, pRfile, pTfile, optD['base'])
1151                    else:
1152                        configureSdp(SDP_CFG, cfile, mfile, pfile, pCfile, pMfile, pRfile, pTfile, optD['base'])

Karen Tian
Powered by
ViewCVS 0.9.4