OpenQuizz
Une application de gestion des contenus pédagogiques
GitConfigParser Class Reference
Inheritance diagram for GitConfigParser:
Collaboration diagram for GitConfigParser:

Public Member Functions

def __init__ (self, file_or_files=None, read_only=True, merge_includes=True, config_level=None, repo=None)
 
def __del__ (self)
 
def __enter__ (self)
 
def __exit__ (self, exception_type, exception_value, traceback)
 
def release (self)
 
def optionxform (self, optionstr)
 
def read (self)
 
def items (self, section_name)
 
def items_all (self, section_name)
 
def write (self)
 
def add_section (self, section)
 
def read_only (self)
 
def get_value (self, section, option, default=None)
 
def get_values (self, section, option, default=None)
 
def set_value (self, section, option, value)
 
def add_value (self, section, option, value)
 
def rename_section (self, section, new_name)
 
- Public Member Functions inherited from MetaParserBuilder
def __new__ (cls, name, bases, clsdict)
 

Static Public Attributes

 t_lock
 
 re_comment
 
 optvalueonly_source
 
 OPTVALUEONLY
 
 OPTCRE
 

Detailed Description

Implements specifics required to read git style configuration files.

This variation behaves much like the git.config command such that the configuration
will be read on demand based on the filepath given during initialization.

The changes will automatically be written once the instance goes out of scope, but
can be triggered manually as well.

The configuration file will be locked if you intend to change values preventing other
instances to write concurrently.

:note:
    The config is case-sensitive even when queried, hence section and option names
    must match perfectly.
    If used as a context manager, will release the locked file.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  file_or_files = None,
  read_only = True,
  merge_includes = True,
  config_level = None,
  repo = None 
)
Initialize a configuration reader to read the given file_or_files and to
possibly allow changes to it by setting read_only False

:param file_or_files:
    A single file path or file objects or multiple of these

:param read_only:
    If True, the ConfigParser may only read the data , but not change it.
    If False, only a single file path or file object may be given. We will write back the changes
    when they happen, or when the ConfigParser is released. This will not happen if other
    configuration files have been included
:param merge_includes: if True, we will read files mentioned in [include] sections and merge their
    contents into ours. This makes it impossible to write back an individual configuration file.
    Thus, if you want to modify a single configuration file, turn this off to leave the original
    dataset unaltered when reading it.
:param repo: Reference to repository to use if [includeIf] sections are found in configuration files.

◆ __del__()

def __del__ (   self)
Write pending changes if required and release locks

Member Function Documentation

◆ __enter__()

def __enter__ (   self)

◆ __exit__()

def __exit__ (   self,
  exception_type,
  exception_value,
  traceback 
)

◆ add_section()

def add_section (   self,
  section 
)
Assures added options will stay in order

◆ add_value()

def add_value (   self,
  section,
  option,
  value 
)
Adds a value for the given option in section.
It will create the section if required, and will not throw as opposed to the default
ConfigParser 'set' method. The value becomes the new value of the option as returned
by 'get_value', and appends to the list of values returned by 'get_values`'.

:param section: Name of the section in which the option resides or should reside
:param option: Name of the option

:param value: Value to add to option. It must be a string or convertible
    to a string
:return: this instance

◆ get_value()

def get_value (   self,
  section,
  option,
  default = None 
)
Get an option's value.

If multiple values are specified for this option in the section, the
last one specified is returned.

:param default:
    If not None, the given default value will be returned in case
    the option did not exist
:return: a properly typed value, either int, float or string

:raise TypeError: in case the value could not be understood
    Otherwise the exceptions known to the ConfigParser will be raised.

◆ get_values()

def get_values (   self,
  section,
  option,
  default = None 
)
Get an option's values.

If multiple values are specified for this option in the section, all are
returned.

:param default:
    If not None, a list containing the given default value will be
    returned in case the option did not exist
:return: a list of properly typed values, either int, float or string

:raise TypeError: in case the value could not be understood
    Otherwise the exceptions known to the ConfigParser will be raised.

◆ items()

def items (   self,
  section_name 
)
:return: list((option, value), ...) pairs of all items in the given section

◆ items_all()

def items_all (   self,
  section_name 
)
:return: list((option, [values...]), ...) pairs of all items in the given section

◆ optionxform()

def optionxform (   self,
  optionstr 
)
Do not transform options in any way when writing

◆ read()

def read (   self)
Reads the data stored in the files we have been initialized with. It will
ignore files that cannot be read, possibly leaving an empty configuration

:return: Nothing
:raise IOError: if a file cannot be handled

◆ read_only()

def read_only (   self)
:return: True if this instance may change the configuration file

◆ release()

def release (   self)
Flush changes and release the configuration write lock. This instance must not be used anymore afterwards.
In Python 3, it's required to explicitly release locks and flush changes, as __del__ is not called
deterministically anymore.

◆ rename_section()

def rename_section (   self,
  section,
  new_name 
)
rename the given section to new_name
:raise ValueError: if section doesn't exit
:raise ValueError: if a section with new_name does already exist
:return: this instance

◆ set_value()

def set_value (   self,
  section,
  option,
  value 
)
Sets the given option in section to the given value.
It will create the section if required, and will not throw as opposed to the default
ConfigParser 'set' method.

:param section: Name of the section in which the option resides or should reside
:param option: Name of the options whose value to set

:param value: Value to set the option to. It must be a string or convertible
    to a string
:return: this instance

◆ write()

def write (   self)
Write changes to our file, if there are changes at all

:raise IOError: if this is a read-only writer instance or if we could not obtain
    a file lock

Reimplemented in SubmoduleConfigParser.

Field Documentation

◆ OPTCRE

OPTCRE
static

◆ OPTVALUEONLY

OPTVALUEONLY
static

◆ optvalueonly_source

optvalueonly_source
static

◆ re_comment

re_comment
static

◆ t_lock

t_lock
static

The documentation for this class was generated from the following file: