Library: configuration

From Yombo
Jump to: navigation, search
configuration
Commonly Used Yes
Status Active

Summary
View and set various system configuration items.

Introduction

The gateway configurations are stored in the yombo.ini can be accessed and managed through the configuration library. The configuration library can be referenced from magic attribute as self._Configs. An example of looking up a configuration item within the "core" section:

def somefunction(self):
        v4ip_address = self._Configs.get('core', 'localipaddress_v4')

See also

Hooks

Usage

Sections and Options

Configurations relating to each other are grouped into a secion, while an individual configuration is known as an option. For example, all items relating to the web interface are grouped together in the webinterface section.

Common Functions

For complete list of functions, parameters, exceptions raised, returns, and additional examples, see: Configuration @ Yombo Python API

  • get(section, option, default, set_if_missing) [doc] [source] - Get a configuration option. This returns a static value of the configuration at the time it's being called.
  • get2(section, option, default, set_if_missing) [doc] [source] - Get a callable that always gets the live value. Useful when reading a configuration will be long lived.
  • set(section, option, value) [doc] [source] - Sets a configuration value to a given value.

Examples

The easiest way to get a configuration item is to simply use the get function or call the library as a dictionary, using two hashes (##) as a seperator between the section and the option being requested:

v4ip_address = self._Configs.get('mqtt', 'server_listen_ip')
# is the same as:E
v4ip_address = self._Configs('mqtt##server_listen_ip')

If a configuration item will be referenced throughout the life of the runtime of the gateway software, you can get a callable version that will always return the current value. This allows the configuration item to be updated without worry that the module using stale information. **Notice that the function is get2 vs get.** As an additional benefit, a new value can be assigned using the callable.

listen_port = self._Configs.get2('mqtt', 'server_listen_port')
print "The current server listen IP address is: %s" % listen_port()
# Lets change the port number.
listen_port(set=10101)

To set a configuration value, use the set function:

self._Configs.set('mqtt', 'server_listen_port', 10101)


This page was last edited on 30 April 2019.