pryv.config
¶
This module defines the configuration interface. It reads the file file://~/.pryv/pryv.ini
and
exposes its values.
The Config
and ConfigSection
wrap the class
ConfigParser.ConfigParser
in order to enable one to access configuration section and options
directly from the code, i.e. using attribute notation. In addition, it handles automatically default
values.
-
class
pryv.config.
Config
(path='file://~/.pryv/pryv.ini')¶ Bases:
object
This class defines a configuration object. It is a wrapper around the standard
ConfigParser.ConfigParser
class.It is designed as a convenience class to access configuration sections and options from code and return default values dynamically.
Example:
config = pryv.config.Config() config.my_section.my_option # -> my-value
-
__init__
(path='file://~/.pryv/pryv.ini')¶ Creates a new instance of a configuration object. This method loads the configuration from the file
file://~/.pryv/pryv.ini
.Parameters: path ( str
) – The path to the configuration file.
-
get
(section_name)¶ Gets a section by its name.
Parameters: section_name ( str
) – The name of the section.Returns: A configuration section. Return type: ConfigSection
orNone
-
-
class
pryv.config.
ConfigSection
(name, options)¶ Bases:
object
This class defines a configuration section.
It is designed as a convenience class to access configuration options from code and set default values to options that are not present in the configuration file.
Example:
section = pryv.config.ConfigSection('my-section', {'my-option': 'my-value'}) section.my_option # -> my-value # Assuming my-other-option has for default value my-other-value section.my_other_option # -> my-other-value
-
__init__
(name, options)¶ Creates a new instance of a configuration section.
Parameters: - name (
str
) – The name of the section. - options (
dict
) – The options of the section.
- name (
-
set
(option_name, option_value)¶ Sets the value of the option with the given name.
Parameters: - option_name (
`str
) – The name of the option. - option_value – The value of the option.
- option_name (
-
-
pryv.config.
init
(path)¶ Initializes the configuration to read options from the file with the given path.
Note
The path can be either a path to a file on the local file system (i.e. not prefixed or using the
file://
prefix) or a file located on an AWS S3 bucket (i.e. using thes3://
prefix).Parameters: path ( str
) – The path to the configuration file.
-
pryv.config.
pythonize_name
(name)¶ Pythonizes an option name.
Example:
pythonize_name('my-option') # -> my_option
Parameters: name ( str
) – The name to pythonize.Returns: A pythonized name. Return type: str
-
pryv.config.
unpythonize_name
(name)¶ Unythonizes an attribute name.
Example:
unpythonize_name('my_option') # -> my-option
Parameters: name ( str
) – The name to unpythonize.Returns: An option name. Return type: str