LocalConfiguration

This is the guy that parses and interprets the local configuration options.

class DIRAC.ConfigurationSystem.Client.LocalConfiguration.LocalConfiguration(defaultSectionPath='')

Bases: object

Main class to interface with Configuration of a running DIRAC Component.

For most cases this is handled via
  • DIRAC.Core.Base.Script class for scripts

  • dirac-agent for agents

  • dirac-service for services

__init__(defaultSectionPath='')
addCFGFile(filePath)

Load additional .cfg file to be parsed

addDefaultEntry(optionPath, value)

Define a default value for a Configuration data option

addMandatoryEntry(optionPath)

Define a mandatory Configuration data option for the parsing of the command line

deleteOption(optionPath)

Remove a Configuration Option from the local Configuration

disableCS()

Do not contact Configuration Server upon initialization

disableParsingCommandLine()
enableCS()

Force the connection the Configuration Server

(And incidentally reinitialize the ObjectLoader and logger)

getDebugMode()
getExtraCLICFGFiles()

Retrieve list of parsed .cfg files

getPositionalArguments(group=False)

Retrieve list of command line positional arguments

Parameters:

group (bool) – to return grouped arguments as they were registered

Returns:

list

getUnprocessedSwitches()

Retrieve list of command line switches without a callback function

initialize(*, returnErrors=False)

Entrypoint used by DIRAC.initialize

TODO: This is currently a hack that returns a list of errors for so it can be used by __addUserDataToConfiguration. This entire module should be refactored and simplified with Script.parseCommandLine.

isCSEnabled()

Retrieve current status of the connection to Configuration Server

loadUserData()

This is the magic method that reads the command line and processes it It is used by the Script Base class and the dirac-service and dirac-agent scripts Before being called: - any additional switches to be processed - mandatory and default configuration configuration options must be defined.

registerCmdArg(description, mandatory=True, values=None, default=None)

Register a new command line argument

Example:

# String description type describe simple argument, e.g.:
registerCmdArg('SingleArg: my single argument')

# Tuple description type describe argument,
# which may be replaced by one of those described, e.g.:
registerCmdArg(('ThisArg: my this argument', 'ThatArg: my that argument'))

# List description type describe an argument that may have more than one value
registerCmdArg(['ListArg: my single argument'])

Result:

Usage:

  command [options] ... SingleArg <ThisArg|ThatArg> ListArg [ListArg]

Arguments:

  SingleArg: my single argument
  ThisArg:   my this argument
  ThatArg:   my that argument
  ListArg:   my list of arguments
Parameters:
  • description (str, tuple or list) – argument description

  • mandatory (bool) – an argument can be mandatory or optional

  • values (list) – list of the accepted values

  • default (object) – default value

registerCmdOpt(shortOption, longOption, helpString, function=False)

Register a new command line option. The options must be unique and do not coincide with the basic options.

Parameters:
  • shortOption (str) – short option name. If the command accepts only long options, then should be (“”). If such a character is followed by a ‘:’, the option requires an argument.

  • longOption (str) – long option name. If such a character is followed by a ‘=’, the option requires an argument.

  • helpString (str) – option description

  • function – the callback function to be called with the passed option argument. if False, the argument can be retrieved using getUnprocessedSwitches().

setConfigurationForAgent(agentName)

Declare this is a DIRAC agent

setConfigurationForExecutor(executorName)

Declare this is a DIRAC agent

setConfigurationForScript(scriptName)

Declare this is a DIRAC script

setConfigurationForServer(serviceName)

Declare this is a DIRAC service

setConfigurationForTornado()

Declare this is a Tornado component

setConfigurationForWeb(webName)

Declare this is a DIRAC agent

setUsageMessage(usageMsg)

Define and parse message to be display by the showHelp method.

Parameters:

usageMsg (str) – script description that can contain Usage, Example, Arguments, Options blocks

showHelp(dummy=False, exitCode=0)

Printout help message including a Usage message if defined via setUsageMessage method

Parameters:
  • dummy (str) – dummy text

  • exitCode (int) – exit code

showLicense(dummy=False)

Print license

syncRemoteConfiguration(strict=False)

Force a Resync with Configuration Server Under normal conditions this is triggered by an access to any configuration data.