Created
January 11, 2012 16:49
-
-
Save adngdb/1595565 to your computer and use it in GitHub Desktop.
ConfigMan dependency solving
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Example app to understand how ConfigMan can find all the configuration keys | |
an application needs. """ | |
from configman import ConfigurationManager, Namespace, RequiredConfig | |
from configman.converters import class_converter | |
class A(RequiredConfig): | |
"""Example class that can execute an action an has some required config.""" | |
required_config = Namespace() | |
required_config.add_option('output', | |
'Beautiful output', | |
'the postgres database transaction source') | |
def execute(self, config): | |
print config.output | |
class B(RequiredConfig): | |
"""Example class that can execute an action an has some required config.""" | |
required_config = Namespace() | |
required_config.add_option('output', | |
'Beautiful output', | |
'the postgres database transaction source') | |
required_config.add_option('prefix', | |
'OUTPUT: ', | |
'the postgres database transaction source') | |
def execute(self, config): | |
print config.prefix, config.output | |
# Create a basic namespace to choose which class to use | |
definition = Namespace() | |
definition.add_option('application', | |
doc='the fully qualified module or class of the ', | |
default='A', | |
from_string_converter=class_converter, | |
short_form='a', | |
) | |
# Create the context | |
c = ConfigurationManager(definition, | |
app_name='demo1', | |
app_description=__doc__) | |
config = c.get_config() | |
# Instanciate the right class and execute it's action | |
app = config.application() | |
app.execute(config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment