CFG

This is the main module that interprets DIRAC cfg format

class DIRAC.Core.Utilities.CFG.CFG

Bases: object

__init__()

Constructor

addKey(**kwargs)
appendToOption(**kwargs)
applyModifications(modList, parentSection='')

Apply modifications to a CFG

Parameters:modList (List) – Modifications from a getModifications call
Returns:True/False
clone(**kwargs)
copyKey(**kwargs)
createNewSection(**kwargs)
deleteKey(**kwargs)
existsKey(key)

Check if an option/section with that name exists

Parameters:key (string) – Name of the option/section to check
Returns:Boolean with the result
getAsCFG(path='')

Return subsection as CFG object.

Parameters:path (str) – Path to the section
Returns:CFG object, of path is not found the CFG is empty
getAsDict(path='')

Get the contents below a given path as a dict

Parameters:path (string) – Path to retrieve as dict
Returns:Dictionary containing the data
getComment(**kwargs)
getModifications(newerCfg, ignoreMask=None, parentPath='', ignoreOrder=False, ignoreComments=False)

Compare two cfgs

Parameters:
  • newerCfg (CFG) – Cfg to compare with
  • ignoreMask (list) – List of paths to ignore
  • parentPath (str) – Start from this path
  • ignoreOrder – Do not return changes only in ordering
  • ignoreComments – Do not return changes for changed commens
Returns:

A list of modifications

getOption(opName, defaultValue=None)

Get option value with default applied

Parameters:
  • opName (string) – Path to the option to retrieve
  • defaultValue (optional (any python type)) – Default value for the option if the option is not defined. If the option is defined, the value will be returned casted to the type of defaultValue if it is defined.
Returns:

Value of the option casted to defaultValue type, or defaultValue

getRecursive(**kwargs)
isOption(**kwargs)
isSection(**kwargs)
listAll()

List all sections and options

Returns:List with names of all options and subsections
listOptions(**kwargs)
listSections(**kwargs)
loadFromBuffer(**kwargs)
loadFromDict(**kwargs)
loadFromFile(fileName)

Load the contents of the CFG from a file

Parameters:fileName (string) – File name to load the contents from
Returns:This CFG
mergeWith(**kwargs)
renameKey(**kwargs)
reset(**kwargs)
serialize(**kwargs)
setComment(**kwargs)
setOption(**kwargs)
sortAlphabetically(ascending=True)

Order this cfg alphabetically returns True if modified

sortByKey(key=None, reverse=False)

Order this cfg by function refered in key, default is None corresponds to alphabetic sort returns True if modified

writeToFile(fileName)

Write the contents of the cfg to file

Parameters:fileName (string) – Name of the file to write the cfg to
Returns:True/False