Пример #1
0
    def loadConfig(self, configname, overrideargs = None):
        """
        Load the configuration file
        """
        ## If the configuration is alredy an object it doesn't need to be loaded from the file.
        if isinstance(configname, Configuration):
            self.configuration = configname
            valid, configmsg = self.validateConfig()
            if not valid:
                configmsg += "\nThe documentation about the CRAB configuration file can be found in"
                configmsg += " https://twiki.cern.ch/twiki/bin/view/CMSPublic/CRAB3ConfigurationFile"
                raise ConfigurationException(configmsg)
            return

        if not os.path.isfile(configname):
            raise ConfigurationException("CRAB configuration file %s not found." % (configname))
        self.logger.info("Will use CRAB configuration file %s" % (configname))
        try:
            self.logger.debug("Loading CRAB configuration file.")
            self.configuration = loadConfigurationFile(os.path.abspath(configname))
            ## Overwrite configuration parameters passed as arguments in the command line.
            if overrideargs:
                for singlearg in overrideargs:
                    ## The next line is needed, because we allow the config to be passed as argument
                    ## instead via the --config option.
                    if singlearg == configname: continue
                    if len(singlearg.split('=',1)) == 1:
                        self.logger.info("Wrong format in command-line argument '%s'. Expected format is <section-name>.<parameter-name>=<parameter-value>." % (singlearg))
                        if len(singlearg) > 1 and singlearg[0] == '-':
                            self.logger.info("If the argument '%s' is an option to the %s command, try 'crab %s %s [value for %s option (if required)] [arguments]'." \
                                             % (singlearg, self.__class__.__name__, self.__class__.__name__, singlearg, singlearg))
                        raise ConfigurationException("ERROR: Wrong command-line format.")
                    fullparname, parval = singlearg.split('=',1)
                    # now supporting just one sub params, eg: Data.inputFiles, User.email, ...
                    parnames = fullparname.split('.', 1)
                    if len(parnames) == 1:
                        self.logger.info("Wrong format in command-line argument '%s'. Expected format is <section-name>.<parameter-name>=<parameter-value>." % (singlearg))
                        raise ConfigurationException("ERROR: Wrong command-line format.")
                    self.configuration.section_(parnames[0])
                    type = configParametersInfo.get(fullparname, {}).get('type', 'undefined')
                    if type in ['undefined', 'StringType']:
                        setattr(getattr(self.configuration, parnames[0]), parnames[1], literal_eval("\'%s\'" % parval))
                        self.logger.debug("Overriden parameter %s with '%s'" % (fullparname, parval))
                    else:
                        setattr(getattr(self.configuration, parnames[0]), parnames[1], literal_eval("%s" % parval))
                        self.logger.debug("Overriden parameter %s with %s" % (fullparname, parval))
            valid, configmsg = self.validateConfig() ## Subclasses of SubCommand overwrite this method if needed.
        except RuntimeError as re:
            configmsg  = "Error while loading CRAB configuration:\n%s" % (self._extractReason(configname, re))
            configmsg += "\nPlease refer to https://twiki.cern.ch/twiki/bin/view/CMSPublic/CRAB3CommonErrors#Syntax_error_in_CRAB_configurati"
            configmsg += "\nSee the ./crab.log file for more details."
            configmsg += "\nThe documentation about the CRAB configuration file can be found in"
            configmsg += " https://twiki.cern.ch/twiki/bin/view/CMSPublic/CRAB3ConfigurationFile"
            raise ConfigurationException(configmsg)
        else:
            if not valid:
                configmsg += "\nThe documentation about the CRAB configuration file can be found in"
                configmsg += " https://twiki.cern.ch/twiki/bin/view/CMSPublic/CRAB3ConfigurationFile"
                raise ConfigurationException(configmsg)
Пример #2
0
    def loadConfig(self, configname, overrideargs = None):
        """
        Load the configuration file
        """
        ## If the configuration is alredy an object it doesn't need to be loaded from the file.
        if isinstance(configname, Configuration):
            self.configuration = configname
            valid, configmsg = self.validateConfig()
            if not valid:
                configmsg += "\nThe documentation about the CRAB configuration file can be found in"
                configmsg += " https://twiki.cern.ch/twiki/bin/view/CMSPublic/CRAB3ConfigurationFile"
                raise ConfigurationException(configmsg)
            return

        if not os.path.isfile(configname):
            raise ConfigurationException("CRAB configuration file %s not found." % (configname))
        self.logger.info("Will use CRAB configuration file %s" % (configname))
        try:
            self.logger.debug("Loading CRAB configuration file.")
            self.configuration = loadConfigurationFile(os.path.abspath(configname))
            ## Overwrite configuration parameters passed as arguments in the command line.
            if overrideargs:
                for singlearg in overrideargs:
                    ## The next line is needed, because we allow the config to be passed as argument
                    ## instead via the --config option.
                    if singlearg == configname: continue
                    if len(singlearg.split('=',1)) == 1:
                        self.logger.info("Wrong format in command-line argument '%s'. Expected format is <section-name>.<parameter-name>=<parameter-value>." % (singlearg))
                        if len(singlearg) > 1 and singlearg[0] == '-':
                            self.logger.info("If the argument '%s' is an option to the %s command, try 'crab %s %s [value for %s option (if required)] [arguments]'." \
                                             % (singlearg, self.__class__.__name__, self.__class__.__name__, singlearg, singlearg))
                        raise ConfigurationException("ERROR: Wrong command-line format.")
                    fullparname, parval = singlearg.split('=',1)
                    # now supporting just one sub params, eg: Data.inputFiles, User.email, ...
                    parnames = fullparname.split('.', 1)
                    if len(parnames) == 1:
                        self.logger.info("Wrong format in command-line argument '%s'. Expected format is <section-name>.<parameter-name>=<parameter-value>." % (singlearg))
                        raise ConfigurationException("ERROR: Wrong command-line format.")
                    self.configuration.section_(parnames[0])
                    type = configParametersInfo.get(fullparname, {}).get('type', 'undefined')
                    if type in ['undefined', 'StringType']:
                        setattr(getattr(self.configuration, parnames[0]), parnames[1], literal_eval("\'%s\'" % parval))
                        self.logger.debug("Overriden parameter %s with '%s'" % (fullparname, parval))
                    else:
                        setattr(getattr(self.configuration, parnames[0]), parnames[1], literal_eval("%s" % parval))
                        self.logger.debug("Overriden parameter %s with %s" % (fullparname, parval))
            valid, configmsg = self.validateConfig() ## Subclasses of SubCommand overwrite this method if needed.
        except RuntimeError as re:
            configmsg  = "Error while loading CRAB configuration:\n%s" % (self._extractReason(configname, re))
            configmsg += "\nPlease refer to https://twiki.cern.ch/twiki/bin/view/CMSPublic/CRAB3CommonErrors#Syntax_error_in_CRAB_configurati"
            configmsg += "\nSee the ./crab.log file for more details."
            configmsg += "\nThe documentation about the CRAB configuration file can be found in"
            configmsg += " https://twiki.cern.ch/twiki/bin/view/CMSPublic/CRAB3ConfigurationFile"
            raise ConfigurationException(configmsg)
        else:
            if not valid:
                configmsg += "\nThe documentation about the CRAB configuration file can be found in"
                configmsg += " https://twiki.cern.ch/twiki/bin/view/CMSPublic/CRAB3ConfigurationFile"
                raise ConfigurationException(configmsg)