5.1.1. vlcp.config.config

Note

This document is generated from the source file.

View Source on GitHub

Created on 2015/6/25

author:hubo
class vlcp.config.config.ConfigTree

A basic config node. A node supports both attributes get/set and dict-like operations. When using dict-like interfaces, configurations in child nodes can directly be used:

node['child.childconfig'] = 42
node.child.childconfig  # 42
__contains__(key)

Support dict-like in operator

__delitem__(key)

Support dict-like deletion

__getitem__(key)

Support dict-like retrieval

__init__()

Initialize self. See help(type(self)) for accurate signature.

__iter__()

Support a dict-like iterate

__len__()

Return size of children stored in this node, either sub nodes or configuration values

__setitem__(key, value)

Support dict-like assignment

clear()

Support dict-like clear

config_items(sortkey=False)

Return all (key, value) tuples for configurations in this node, including configurations on children nodes.

config_keys(sortkey=False)

Return all configuration keys in this node, including configurations on children nodes.

config_value_items(sortkey=False)

Return (key, value) tuples for configuration directly stored in this node. Configurations in child nodes are not included.

config_value_keys(sortkey=False)

Return configuration keys directly stored in this node. Configurations in child nodes are not included.

get(key, defaultvalue=None)

Support dict-like get (return a default value if not found)

gettree(key, create=False)

Get a subtree node from the key (path relative to this node)

items()

Return (key, value) tuples for children in this node, either sub nodes or configuration values

keys()

Return all children in this node, either sub nodes or configuration values

loadconfig(keysuffix, obj)

Copy all configurations from this node into obj

setdefault(key, defaultvalue=None)

Support dict-like setdefault (create if not existed)

todict()

Convert this node to a dictionary tree.

withconfig(keysuffix)

Load configurations with this decorator

class vlcp.config.config.Configurable

Base class for a configurable object. Undefined attributes of a configurable object is mapped to global configurations. The attribute value of a configurable object is:

  1. The original attribute value if it is set on the instance or class
  2. The configuration value manager[self.configkey + ‘.’ + attrname] if exists
  3. The configuration value manager[parent.configkey + ‘.’ + attrname] if parent classes have configkey defined and configuration exists.
  4. The _default_<attrname> attribute value of the instance
  5. raises AttributeError

Attributes begins with ‘_’ is not mapped.

configkey and configbase attribute should be set on this class. Usually they are set by decorators @defaultconfig, @configbase or @config

__init__()

Initialize self. See help(type(self)) for accurate signature.

config_value_items(sortkey=False)

Return (key, value) tuples for all mapped configurations for this object

config_value_keys(sortkey=False)

Return all mapped configuration keys for this object

classmethod getConfigRoot(create=False)

Return the mapped configuration root node

classmethod getConfigurableParent()

Return the parent from which this class inherits configurations

class vlcp.config.config.Manager

Configuration manager. Use the global variable manager to access the configuration system.

__init__()

Initialize self. See help(type(self)) for accurate signature.

loadfrom(path)

Read configurations from path

loadfromfile(filelike)

Read configurations from a file-like object, or a sequence of strings. Old values are not cleared, if you want to reload the configurations completely, you should call clear() before using load* methods.

loadfromstr(string)

Read configurations from string

save(sortkey=True)

Save configurations to a list of strings

saveto(path, sortkey=True)

Save configurations to path

savetofile(filelike, sortkey=True)

Save configurations to a file-like object which supports writelines

savetostr(sortkey=True)

Save configurations to a single string

vlcp.config.config.config(key)

Decorator to map this class directly to a configuration node. It uses <parentbase>.key for configuration base and configuration mapping.

vlcp.config.config.configbase(key)

Decorator to set this class to configuration base class. A configuration base class uses <parentbase>.key. for its configuration base, and uses <parentbase>.key.default for configuration mapping.

vlcp.config.config.defaultconfig(cls)

Generate a default configuration mapping bases on the class name. If this class does not have a parent with configbase defined, it is set to a configuration base with configbase=<lowercase-name> and configkey=<lowercase-name>.default; otherwise it inherits configbase of its parent and set configkey=<parentbase>.<lowercase-name>

Refer to :ref::configurations for normal rules.