iotile.core.dev.config

Manager for typed configuration variables

ConfigManager allows plugins to register typed config variables and allows users to then set those variables. Config variables can optionally have default values. Plugins to iotile-core can register their own config variables under their own namespace by registering an entry_point named ‘iotile.config_variables’.

The object pointed to by the entry point should be a function that returns a 2-tuple with a string and a list that maps a namespace prefix to a list of 4-tuples with format:

[name, type, description, default_value]

If there is no default value, a 3-tuple can be used with just name, type and description.

Module Contents

MISSING
ConfigVariable
class ConfigManager

Bases:object

A class for managing typed configuration variables

ConfigManager can be used to querying which config variables are defined and to set or get the currently defined variables.

_load_providers(self)

Load all config_variables providers using pkg_resources

_load_functions(self)

Load all config functions that should be bound to this ConfigManager

Config functions allow you to add functions that will appear under ConfigManager but call your specified function. This is useful for adding complex configuration behavior that is callable from the iotile command line tool

_format_variable(self, name, var)

Format a helpful string describing a config variable

Args:
name (string): The prefixed name of the config variable var (ConfigVariable): the variable to format
Returns:
string: The formatted string in the form name (type): (default %s) description
list(self, glob)

List all matching config variables

The glob parameter should be a wildcard expression like: build:* to find all config variables defined with a build prefix.

Returns:
string[]: A list of string descriptions containing descriptions and
type information.
get(self, name)

Get the current value of a config variable

remove(self, name)

Remove any currently defined values for the named variable

set(self, name, value)

Set the current avlue of a config variable

describe(self, name)

Describe a config variable by name

Returns:
string: A short description of what the variable is used for
add_variable(self, name, var_type, desc, default=MISSING)

Add a temporary variable to the config variable manager

This function is mainly useful for testing since it does not persistently store information about the variable.

Args:

name (string): The name of the variable var_type (string): The type of the variable. This should be a type

known to the type_system.

desc (string): The description of what this variable is for default (string): An optional default value for the variable

add_function(self, name, callable)

Add a config function to the config variable manager

Config functions are like config variables but are functions rather than variables. Sometimes you want to expose configuration but you really need a function to actually do it. For example, let’s say you want to store a github OAUTH token on behalf of a user. You would like a config function like link_github that walks the user through logging in to github and getting a token then you would like to save that token into the config manager like normal.

add_function lets you bind a method to ConfigManager dynamically. The function should be a normal function with its first argument as self and it is turned into a bound method on this instance of config manager.

Args:

name (string): The attribute name for this function callable (callable): A function with first argument self

that will be bound to this ConfigManager object as a method.