Last active
August 29, 2015 14:15
-
-
Save snare/b835e0aa96d315736f4f to your computer and use it in GitHub Desktop.
This file contains 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
# kwarg/object style | |
env = Environment( | |
# config/main environment directory | |
dir=Directory('~/.myproject', children=[ | |
# config file within that directory, defaults loaded from a file | |
# inside the package | |
ConfigFile('config', default=PackageFile('config/default.cfg')) | |
# user plugin directory, plugins loaded automatically | |
PluginDirectory('plugins') | |
]), | |
# package plugin directory, plugins loaded automatically. use nested | |
# PackageDirectory to imply relative to package root | |
plugin_dir=PluginDirectory(PackageDirectory('plugins')) | |
# log directory | |
log_dir=Directory('/var/log/myproject', children=[ | |
# auto-config a log file handler to point to these file, maybe | |
# provide other logging config somewhere else in the environment spec? | |
LogFile('project.log', log_level='INFO'), | |
LogFile('errors.log', log_level='ERROR') | |
]), | |
# runtime stuff dir (cache) | |
run_dir=Directory('/var/run/myproject', cleanup=True, children=[ | |
File('sock', cleanup=True), | |
File('lock', create=True, cleanup=True) | |
]) | |
# any keyword parameter is stored with that name in the environment root | |
# string is just treated as Directory(string) with defaults | |
widget_dir='~/widgets' | |
) | |
# ConfigFile object loaded into a Config object. 'dir' param treated specially | |
# and files specified within 'dir' are loaded into the env root | |
env.config.some_setting | |
env['config'].some_setting | |
# also addressable under 'dir' param the environment was initialised with | |
env.dir.config | |
# plugins all loaded into env.plugin_mgr, convenience method to access | |
# plugins (this already exists) | |
env.plugin_mgr.plugins | |
env.plugins | |
# run directory | |
env.run_dir.sock.path | |
# list widgets directory - this is kinda why I think Directory is more than | |
# an implementation detail. | |
env.widget_dir.list() | |
env.widget_dir.write('xxx', 'some data') | |
env.widget_dir.path_to('xxx') | |
# equivalent dictionary spec style | |
env = Environment({ | |
'dir': { | |
'path': '~/.myproject', | |
'children': { | |
'config': { | |
'type': 'config', | |
'default': { | |
'path': 'env1/default.cfg', | |
'rel_to': 'pkg', | |
'pkg': 'tests' | |
} | |
}, | |
'local_plugins': { | |
'type': 'plugin_dir', | |
'name': 'plugins' | |
} | |
} | |
}, | |
'plugin_dir': { | |
'type': 'plugin_dir', | |
'path': 'plugins', | |
'rel_to': 'pkg', | |
'pkg': 'tests' | |
}, | |
'log_dir': { | |
'path': '/var/log/myproject', | |
'children': { | |
'project.log': { | |
'type': 'log', | |
'log_level': 'INFO' | |
}, | |
'error.log': { | |
'type': 'log', | |
'log_level': 'ERROR' | |
} | |
} | |
}, | |
'run_dir': { | |
'path': '/var/run/myproject', | |
'cleanup': True | |
'children': { | |
'sock': { | |
'type': 'raw', | |
'cleanup': True | |
}, | |
'lock': { | |
'type': 'raw', | |
'create': True, | |
'cleanup': True | |
} | |
} | |
}, | |
'widget_dir': { | |
'path': '~/widgets' | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment