Table Of Contents

Previous topic

The soclib_cc.config module

Next topic

Configuration spool

This Page

Configuration objects

The Config base object

class soclib_cc.config.objects.Config

This is the base configuration object. It handles all the attribute dereferencing features of the soclib configuration tool. Example session:

>>> from soclib_cc.config.objects import *
>>> c = Config(foo = "foo", bar = ["%(foo)s_value", "other_value"], baz = 42)
>>> c.foo
'foo'
>>> c.baz
42
>>> c.bar
['foo_value', 'other_value']
>>> c2 = Config(parent = c, foo = "zip")
>>> c2.foo
'zip'
>>> c2.bar
['zip_value', 'other_value']
>>> c2.baz
42
>>> c2["bar"]
['%(foo)s_value', 'other_value']
__init__(parent = None, **kwargs)

Create a new Config object with an optional parent to retrieve default values from. All other parameters are fed to the configuration entry values.

Parameters:
  • parent – Parent Config object to inherit from, if any
  • kwargs – Key/value list of parameters to set in this config entry
__getitem__(key)

Returns the corresponding configuration value, without expanding %(..)s hacks.

Parameters:key – Key to retrieve value for. If not found in current config, walk through parents.
Raises :KeyError if not found
set(key, value)

Set corresponding configuration value

__getattr__(key)

Returns the corresponding configuration value, expanding %(..)s hacks.

Parameters:key – Key to retrieve value for. If not found in current config, walk through parents.
Raises :AttributeError if not found
__setattr__(key, value)

Set corresponding configuration value, only possible if the key was already defined in object:

>>> c = Config(foo = 1)
>>> c.foo = 2
>>> c.bar = 3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "soclib_cc/config/objects.py", line 151, in __setattr__
    raise AttributeError("You cant add a new attribute afterwards")
AttributeError: You cant add a new attribute afterwards
Parameters:
  • key – Name of config entry to add
  • value – Value of config entry to add
Raises :

AttributeError if setting this key is not permitted.

parent

Pointer to the parent Config object.

pformat(indent = '')

A recursive method for pretty-printing of the configuration object value

Parameters:indent – Indentation prefix of output
Returns:a string containing the configuration values
get_flags(*flags)

A getter helper for flags, where we need a concatenation of <something>_cflags and cflags. Concatenes all lists found named after flags. Silently ignored if not found.

Parameters:flags – list of keys to retrieve
Returns:concatenation of all the found lists

Example:

>>> c = Config(foo = ['a', 'b'], bar = ['c', 'd'])
>>> c.get_flags('foo', 'bar', 'baz')
['a', 'b', 'c', 'd']
classmethod lock()

Make all the Config objects read-only.

classmethod unlock()

Make all the Config objects read-write.

The inherited objects

class soclib_cc.config.objects.Toolchain(soclib_cc.config.objects.Config)

A configuration object with specific features for toolchain support.

get_tool(name, mode)

Retrieves a tool in the tool map. Tools are referenced with a special key format: tool_<mode>_<name>. mode is optional.

Example:

>>> t = Toolchain(tool_foo = "abc", tool_debug_foo = "def")
>>> t.get_tool("foo", "debug")
['def']
>>> t.get_tool("foo", "other")
['abc']
class soclib_cc.config.objects.Library(soclib_cc.config.objects.Config)

A configuration object with specific features for a Library.

Libraries should always contain a name key.

The Build environment

class soclib_cc.config.objects.BuildEnv(soclib_cc.config.objects.Config)

A configuration object with specific features for a build environment. A build environment contains a set of libraries, a toolchain, and other flags.

get_library(name)

Retrieves library by library name. i.e. get the Library object in the libraries list matching name.

Parameters:name – Name to match
Returns:a matching Library object.

Example:

>>> l = Library(name = "foo", val = 42)
>>> l2 = Library(name = "bar", val = 4096)
>>> b = BuildEnv(libraries = [l, l2])
>>> b.get_library("foo").val
42
getTool(name, mode = "")

Retrieves a tool through the toolchain object’s soclib_cc.config.objects.Toolchain.get_tool() method for given name and mode.

getCflags(mode)

Retrieves the concatenation of the cflags field from all libraries, toolchain, and build environment attributes. Also concatenates the <mode>_cflags attribute value if available.

Example:

>>> l = Library(name = "foo", cflags = ["-Ifoo"])
>>> l2 = Library(name = "bar", cflags = ["-Ibar"], debug_cflags = ["-DBAR_DEBUG"])
>>> t = Toolchain(cflags = ["-Itoolchain"])
>>> b = BuildEnv(libraries = [l, l2], toolchain = t)
>>> b.getCflags("release")
['-Ifoo', '-Ibar', '-Itoolchain']
>>> b.getCflags("debug")
['-Ifoo', '-DBAR_DEBUG', '-Ibar', '-Itoolchain']
getLibs(mode)

Retrieves the concatenation of the libs field from all libraries, toolchain, and build environment attributes. Also concatenates the <mode>_libs attribute value if available.

This works exactly like soclib_cc.config.objects.BuildEnv.getCflags() method.

reposFile(name, mode = None)

Create an unique absolute filename based on a passed relative name and mode.

Parameters:
  • name – a relative file name
  • mode – a mode prefix
Returns:

An absolute filename in the spool.

Example:

>>> b = BuildEnv(repos = "/tmp")
>>> b.reposFile("foo.o")
'/tmp/release/foo.o'
>>> b.reposFile("foo.o", "debug")
'/tmp/debug/foo.o'