Package: configuration
multi-level unified configuration for python consumptionyou have a (python) program that wants to read configuration from
configuration files (I currently support JSON and YAML) and also
from the command line [TODO: environment variables]you want to be able to serialize and deserialize configurationBasic UsageTheconfiguration.Configurationclass is an abstract base
class that extendsoptparse.OptionParser.  The form of the
configuration is dictated by setting theoptionsattribute on your
subclass.optionsis a dictionary of the form:{'name': {<value>}}nameis the name of the configuration option, andvalueis adictthat gives the form of the option.Configurationtransforms these options intoOptionParseroptions.Options forvalueinclude:help : what the option is about (translated to command line help)default: default value for the optionrequired: if a true value, this option must be present in the
configuration. Ifrequiredis a string, it will be displayed if
the option is not present. If the default is defined, you won’t
need required as the default value will be usedtype: type of the option. Used to control the parsing of the optionflags: a list that, if present, will be used for the command line
flags. Othwise, the option name prepended by--will be used.
To disable as a command line option, use an empty list[]In addition, you may extendConfigurationand have additional
useful items in thevaluedict foroptions.For an example, seehttp://k0s.org/mozilla/hg/configuration/file/c831eb58fb52/tests/example.py#l7Configuration FilesConfig files are useful for (IMHO) A. complicated setup;
B. reproducibility; C. being able to share run time configurations.
The latter is mostly useful if the configuration contains nothing
machine-specific (e.g. the path to an executable might vary from
machine to machine) or if the configuration is overridable from the
command line.configurationfeatures the ability to serialize (dump) and deserialize
(load) configuration from a pluggable set of formats.  By default,--dump<filename>will dump the resultant configuration (that
gathered from the command line options and loaded configuration files)
to a file of format dictate by the file extension (Example:--dumpmydumpfile.jsonwill use JSON format).  The flag for the
option, e.g.--dump, may be set via thedumpparameter toConfiguration’s constructor.Configurationinstances can also deserialize data.  The normal case of
using configuration is when you want to be able to read from
configuration files.  By default,Configurationinstances read
positional arguments for configuration files to be loaded.  If you
specify aloadargument to theConfigurationconstructor, this
option will be used instead.  Likewise, the file extension will be
used to determine the format.Theconfiguration packagerequiresjson``(``simplejsonon older python) andPyYAMLso
these serializers/deserializers are available if you install the package.Extending Configurationconfigurationis designed to be pluggable.  While you get a useful
set of behaviour out of the box, most of the handlers forconfigurationmay be manipulated to do what you want to do.Configuration’s constructor takes an argument,types, which is
a dictionary of callables keyed on type that translateConfiguration.optionsintooptparseoptions.  If one ofConfiguration.optionstype isn’t specified (or isNone), then
the default is used (configuration.base_cliunless you override this).
If not passed, aConfigurationinstance usesconfiguration.types.The callables intypesshould take the option name and value
dictionary and should return the args and keyword args necessary to
instantiate anoptparse.Option.Configuration’s constructor also accepts an option,configuration_providers, that is a list of
serializers/deserializers to use.  These should be objects with a list
ofextensionsto use, aread(filename)method that will load
configuration, and awrite(config, filename)method to write it.readshould return the read configuration.
Ifwriteis not present the provider cannot serialize.TODOAddhttp://k0s.org/hg/ConfigOptionParserand deprecate itSee Alsohttps://pypi.python.org/pypi/crumbs/,https://github.com/alunduil/crumbsJeff Hammelhttp://k0s.org/hg/configuration