blinkenxmas.config

The blinkenxmas.config module defines classes to handle parsing the stored configuration of Blinken` Xmas, and to layer the parsed command line arguments on top of this.

Functions

blinkenxmas.config.get_parser(config, **kwargs)[source]

Given config, a ConfigParser containing the stored application configuration (presumably returned by get_config()), and any keyword arguments that should be passed to the argument parser, constructions and returns a ConfigArgumentParser instance with the command line parameters common to all the applications.

blinkenxmas.config.get_config()[source]

Load the default configuration from the project resources, defining the valid sections and keys from the default (amalgamating the example leds sections into a template “leds:*” section).

Returns a ConfigParser instance with the stored configuration loaded.

Classes

class blinkenxmas.config.ConfigArgumentParser(*args, **kwargs)[source]

A variant of ArgumentParser that links arguments to specified keys in a ConfigParser instance.

add_argument(*args, section=None, key=None, **kwargs)[source]

Adds section and key parameters. These link the new argument to the specified configuration entry.

The default for the argument can be specified directly as usual, or can be read from the configuration (see set_defaults()). When arguments are parsed, the value assigned to this argument will be copied to the associated configuration entry.

add_argument_group(title=None, description=None, section=None)[source]

Adds a new argument group object and returns it.

The new argument group will likewise accept section and key parameters on its add_argument() method. The section parameter will default to the value of the section parameter passed to this method (but may be explicitly overridden).

of_type(type)[source]

Return a set of (section, key) tuples listing all configuration items which were defined as being of the specified type (with the type keyword passed to add_argument().

set_defaults_from(config)[source]

Sets defaults for all arguments from their associated configuration entries in config.

update_config(config, namespace)[source]

Copy values from namespace (presumably the result of calling something like parse_args()) to config. Note that namespace values will be converted to str implicitly.

Type conversions

blinkenxmas.config.port(s)[source]

Convert the str s into a port number. s may contain an integer representation (in which case the conversion is trivial), or a str containing a registered port name, in which case getservbyname will be used to convert it to a port number (usually via NSS).

blinkenxmas.config.boolean(s)[source]

Convert the string s to a bool. A typical set of case insensitive strings are accepted: “yes”, “y”, “true”, “t”, and “1” are converted to True, while “no”, “n”, “false”, “f”, and “0” convert to False. Other values will result in ValueError.

blinkenxmas.config.resolution(s)[source]

Convert the string s into a tuple of (width, height).

blinkenxmas.config.rotation(s)[source]

Convert the string s into a rotation in degrees. Values which are not multiples of 90 are rejected with ValueError.

blinkenxmas.config.strips(s)[source]

Convert the str s, which must contain a comma-separated list of integers, into an iterable of range objects, each containing a number of elements specified by the input string. For example:

>>> list(strips('1,2,3'))
[range(0, 2), range(1, 3), range(3, 6)]
>>> list(strips('50,100'))
[range(0, 50), range(50, 150)]