Beispiel #1
0
    def parseArguments (self):
        """Parses command line arguments. Parsing starts just after
the name of the configuration script. Parsing will fail if
there is not 'xxxx.py'"""
        self._currentlyParsing = True
        foundPy = False
        printStatus = False
        help = False
        singleAssign = True
        args = sys.argv if (hasattr(sys,'argv') and sys.argv) else []
        for arg in args:
            if not arg: continue
            if not foundPy and arg.endswith ('.py'):
                foundPy = True
                continue
            if not foundPy:
                continue
            # If we're here, then we can parse to our hearts content.
            # So, is this a command or a declaration?
            if arg.count('='):
                # declaration
                name, value = arg.split ('=', 1)
                if name.count('_'):
                    # name with command
                    name, command = name.split ('_', 1)
                    command = command.lower()
                    if command == 'load':
                        self.loadFromFile (name, value)
                        continue
                    if command == 'clear':
                        self.clearList (name)
                        continue
                    # If we're here, then I don't recognize this command
                    print "Unknown command '%s' in '%s_%s" % \
                          (command, name, command)
                    raise RuntimeError, "Illegal parsing command"
                else:
                    # just a name and value
                    if not self._register.has_key (name):
                        print "Error: '%s' not registered." \
                              % name
                        raise RuntimeError, "Unknown variable"
                    if VarParsing.multiplicity.singleton == \
                           self._register[name]:
                        # singleton
                        if self._beenSet.get (name) and singleAssign:
                            print "Variable '%s' assigned multiple times. Use" \
                                  , "'multipleAssign' command to avoid"
                            raise RuntimeError, "Multiple assignment"
                        self._beenSet[name] = True
                        self.setDefault (name, value)
                    else:
                        # list
                        self.setDefault (name, value)
            else:
                # commands
                if arg.count('_'):
                    # name modifier
                    name, command = arg.split ('_', 1)
                    command = command.lower()
                    if not self._register.has_key (name):
                        print "Error: '%s' not registered." \
                              % name
                        raise RuntimeError, "Unknown variable"
                    if command == 'clear':
                        self.clearList (name)
                        continue
                    # if we're still here, complain that we don't
                    # understand this command:
                    print "Do not understand '%s' in '%s'" % (command, arg)
                    raise RuntimeError, "Unknown command"
                else:
                    # simple command
                    command = arg.lower()
                    if command == 'help' or command == '--help':
                        help = True
                    elif command == 'print' or command == '--print':
                        printStatus = True
                    elif command == 'noprint' or command == '--noprint':
                        printStatus = False
                    else:
                        # We don't understand this command
                        print "Do not understand command '%s'" % (arg)
                        raise RuntimeError, "Unknown command"
            # else if declaration
        ###########################
        # Post-loading processing #
        ###########################
        # sections
        if self._register.has_key ('totalSections') and \
           self._register.has_key ('section') and \
           self._register.has_key ('inputFiles') and \
           self.totalSections and self.section:
            # copy list
            oldInputFiles = self.inputFiles
            # clear list
            self.clearList ('inputFiles')
            # used old list to make list
            self.inputFiles = sectionNofTotal (oldInputFiles,
                                               self.section,
                                               self.totalSections)
        # storePrepend
        if self._register.has_key ('storePrepend') and \
           self._register.has_key ('inputFiles') and \
           self.storePrepend:
            storeRE = re.compile (r'^/store/')
            newFileList = []
            for filename in self.inputFiles:
                if storeRE.match (filename):
                    filename = self.storePrepend + filename
                newFileList.append (filename)
            # clear old list
            self.clearList ('inputFiles')
            # set new list as list
            self.inputFiles = newFileList
        # filePrepend
        if self._register.has_key ('filePrepend') and \
           self._register.has_key ('inputFiles') and \
           self.filePrepend:
            newFileList = []
            for filename in self.inputFiles:
                filename = self.filePrepend + filename
                newFileList.append (filename)
            # clear old list
            self.clearList ('inputFiles')
            # set new list as list
            self.inputFiles = newFileList
        if help:
            self.help()
        if printStatus:
            print self
        self._currentlyParsing = False
            print "  Added %d files from %s ..." % (len(fileNames), root)
        ## sort by job number
        fileNames.sort(key = lambda f: int(f.split("_")[-3]) )
        options.inputFiles = ["file:" + f for f in fileNames]

    if options._register.has_key('totalSections') and \
        options._register.has_key('section') and \
        options._register.has_key('inputFiles') and \
        options.totalSections and options.section:
        # copy list
        oldInputFiles = options.inputFiles
        # clear list
        options.clearList('inputFiles')
        # used old list to make list
        options.inputFiles = sectionNofTotal(oldInputFiles,
                                             options.section,
                                             options.totalSections)
        print "  Processing %d files (section %d of %d) ... " % \
            (len(options.inputFiles), options.section, options.totalSections)


#if options.maxEvents < 0:
  #options.outputFile = options.outputFile.split(".")[0] + "_" + options.dataset.replace("/", "_")

#if options.firstFile != 1 or options.lastFile != 0:
  #first = options.firstFile - 1
  #last = options.lastFile
  #options.outputFile = options.outputFile.split(".")[0] + "_%d-%d" % (first+1, last)
  #newInputFiles = options.inputFiles[first:last]
  #del options.inputFiles[:]
  #options.inputFiles = newInputFiles[:]
Beispiel #3
0
 def parseArguments(self):
     """Parses command line arguments.  Parsing starts just after
     the name of the configuration script.  Parsing will fail if
     there is not 'xxxx.py'"""
     self._currentlyParsing = True
     foundPy = False
     printStatus = False
     help = False
     singleAssign = True
     args = sys.argv if (hasattr(sys, 'argv') and sys.argv) else []
     for arg in args:
         if not arg: continue
         if not foundPy and arg.endswith('.py'):
             foundPy = True
             continue
         if not foundPy:
             continue
         # If we're here, then we can parse to our hearts content.
         # So, is this a command or a declaration?
         if arg.count('='):
             # declaration
             name, value = arg.split('=', 1)
             if name.count('_'):
                 # name with command
                 name, command = name.split('_', 1)
                 command = command.lower()
                 if command == 'load':
                     self.loadFromFile(name, value)
                     continue
                 if command == 'clear':
                     self.clearList(name)
                     continue
                 # If we're here, then I don't recognize this command
                 print "Unknown command '%s' in '%s_%s" % \
                       (command, name, command)
                 raise RuntimeError, "Illegal parsing command"
             else:
                 # just a name and value
                 if not self._register.has_key(name):
                     print "Error:  '%s' not registered." \
                           % name
                     raise RuntimeError, "Unknown variable"
                 if VarParsing.multiplicity.singleton == \
                        self._register[name]:
                     # singleton
                     if self._beenSet.get(name) and singleAssign:
                         print "Variable '%s' assigned multiple times. Use" \
                               , "'multipleAssign' command to avoid"
                         raise RuntimeError, "Multiple assignment"
                     self._beenSet[name] = True
                     self.setDefault(name, value)
                 else:
                     # list
                     self.setDefault(name, value)
         else:
             # commands
             if arg.count('_'):
                 # name modifier
                 name, command = arg.split('_', 1)
                 command = command.lower()
                 if not self._register.has_key(name):
                     print "Error:  '%s' not registered." \
                           % name
                     raise RuntimeError, "Unknown variable"
                 if command == 'clear':
                     self.clearList(name)
                     continue
                 # if we're still here, complain that we don't
                 # understand this command:
                 print "Do not understand '%s' in '%s'" % (command, arg)
                 raise RuntimeError, "Unknown command"
             else:
                 # simple command
                 command = arg.lower()
                 if command == 'help' or command == '--help':
                     help = True
                 elif command == 'print' or command == '--print':
                     printStatus = True
                 elif command == 'noprint' or command == '--noprint':
                     printStatus = False
                 else:
                     # We don't understand this command
                     print "Do not understand command '%s'" % (arg)
                     raise RuntimeError, "Unknown command"
         # else if declaration
     ###########################
     # Post-loading processing #
     ###########################
     # sections
     if self._register.has_key ('totalSections') and \
        self._register.has_key ('section') and \
        self._register.has_key ('inputFiles') and \
        self.totalSections and self.section:
         # copy list
         oldInputFiles = self.inputFiles
         # clear list
         self.clearList('inputFiles')
         # used old list to make list
         self.inputFiles = sectionNofTotal(oldInputFiles, self.section,
                                           self.totalSections)
     # storePrepend
     if self._register.has_key ('storePrepend') and \
        self._register.has_key ('inputFiles') and \
        self.storePrepend:
         storeRE = re.compile(r'^/store/')
         newFileList = []
         for filename in self.inputFiles:
             if storeRE.match(filename):
                 filename = self.storePrepend + filename
             newFileList.append(filename)
         # clear old list
         self.clearList('inputFiles')
         # set new list as list
         self.inputFiles = newFileList
     # filePrepend
     if self._register.has_key ('filePrepend') and \
        self._register.has_key ('inputFiles') and \
        self.filePrepend:
         newFileList = []
         for filename in self.inputFiles:
             filename = self.filePrepend + filename
             newFileList.append(filename)
         # clear old list
         self.clearList('inputFiles')
         # set new list as list
         self.inputFiles = newFileList
     if help:
         self.help()
     if printStatus:
         print self
     self._currentlyParsing = False
Beispiel #4
0
 def parseArguments(self):
     """Parses command line arguments.  Parsing starts just after
     the name of the configuration script.  Parsing will fail if
     there is not 'xxxx.py'"""
     self._currentlyParsing = True
     foundPy = False
     printStatus = False
     help = False
     singleAssign = True
     for arg in sys.argv:
         if not foundPy and arg.endswith(".py"):
             foundPy = True
             continue
         if not foundPy:
             continue
         # If we're here, then we can parse to our hearts content.
         # So, is this a command or a declaration?
         if arg.count("="):
             # declaration
             name, value = arg.split("=", 1)
             if name.count("_"):
                 # name with command
                 name, command = name.split("_", 1)
                 command = command.lower()
                 if command == "load":
                     self.loadFromFile(name, value)
                     continue
                 if command == "clear":
                     self.clearList(name)
                     continue
                 # If we're here, then I don't recognize this command
                 print "Unknown command '%s' in '%s_%s" % (command, name, command)
                 raise RuntimeError, "Illegal parsing command"
             else:
                 # just a name and value
                 if not self._register.has_key(name):
                     print "Error:  '%s' not registered." % name
                     raise RuntimeError, "Unknown variable"
                 if VarParsing.multiplicity.singleton == self._register[name]:
                     # singleton
                     if self._beenSet.get(name) and singleAssign:
                         print "Variable '%s' assigned multiple times. Use", "'multipleAssign' command to avoid"
                         raise RuntimeError, "Multiple assignment"
                     self._beenSet[name] = True
                     self.setDefault(name, value)
                 else:
                     # list
                     ## JV: Added line below so that can check in jobOptions
                     ## not to override command line options
                     self._beenSet[name] = True
                     self.setDefault(name, value)
         else:
             # commands
             if arg.count("_"):
                 # name modifier
                 name, command = arg.split("_", 1)
                 command = command.lower()
                 if not self._register.has_key(name):
                     print "Error:  '%s' not registered." % name
                     raise RuntimeError, "Unknown variable"
                 if command == "clear":
                     self.clearList(name)
                     continue
                 # if we're still here, complain that we don't
                 # understand this command:
                 print "Do not understand '%s' in '%s'" % (command, arg)
                 raise RuntimeError, "Unknown command"
             else:
                 # simple command
                 command = arg.lower()
                 if command == "help" or command == "--help":
                     help = True
                 elif command == "print" or command == "--print":
                     printStatus = True
                 elif command == "noprint" or command == "--noprint":
                     printStatus = False
                 else:
                     # We don't understand this command
                     print "Do not understand command '%s'" % (arg)
                     raise RuntimeError, "Unknown command"
         # else if declaration
     ###########################
     # Post-loading processing #
     ###########################
     # sections
     if (
         self._register.has_key("totalSections")
         and self._register.has_key("section")
         and self._register.has_key("inputFiles")
         and self.totalSections
         and self.section
     ):
         # copy list
         oldInputFiles = self.inputFiles
         # clear list
         self.clearList("inputFiles")
         # used old list to make list
         self.inputFiles = sectionNofTotal(oldInputFiles, self.section, self.totalSections)
     # storePrepend
     if self._register.has_key("storePrepend") and self._register.has_key("inputFiles") and self.storePrepend:
         storeRE = re.compile(r"^/store/")
         newFileList = []
         for filename in self.inputFiles:
             if storeRE.match(filename):
                 filename = self.storePrepend + filename
             newFileList.append(filename)
         # clear old list
         self.clearList("inputFiles")
         # set new list as list
         self.inputFiles = newFileList
     # make sure found the py file
     if not foundPy:
         print "VarParsing.parseArguments() Failure: No configuration " + "file found ending in .py."
         raise RuntimeError, "Invalid configuration ending"
     if help:
         self.help()
     if printStatus:
         print self
     self._currentlyParsing = False