extended commit (see note)
- Slight overhaul of init() system; added ``edbob.init_modules()`` function. - Added ``read_service()`` method to ``AppConfigParser`` class, for use with Windows services. - Added generic ``Service`` class to ``edbob.win32`` module. (File monitor now inherits from it.) - Tweaked ``edbob.db`` initialization somewhat. (``Base.metadata`` no longer binds to ``edbob.db.engine``.) - Fixed guest role bug in ``edbob.db.auth.has_permission()`` function. - Added "automagical" enumeration support for database extensions. - Added ``EMAIL_PREFERENCE`` enum to ``contact`` database extension. - Tweaked ``edbob.pyramid.includeme()``. - Tweaked ``people`` Pyramid views.
This commit is contained in:
parent
526ff5dd6b
commit
c7e0bfef6a
18 changed files with 457 additions and 248 deletions
|
@ -38,7 +38,9 @@ from edbob.configuration import (
|
|||
from edbob.exceptions import InitError
|
||||
|
||||
|
||||
__all__ = ['init']
|
||||
__all__ = ['init', 'init_modules', 'inited']
|
||||
|
||||
inited = []
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -80,22 +82,40 @@ def init(appname='edbob', *args, **kwargs):
|
|||
else:
|
||||
config_paths = default_system_paths(appname) + default_user_paths(appname)
|
||||
|
||||
shell = bool(kwargs.get('shell'))
|
||||
for paths in config_paths:
|
||||
config.read(paths, recurse=not shell)
|
||||
service = kwargs.get('service')
|
||||
if service:
|
||||
config.read_service(service, config_paths)
|
||||
else:
|
||||
shell = kwargs.get('shell', False)
|
||||
for paths in config_paths:
|
||||
config.read(paths, recurse=not shell)
|
||||
config.configure_logging()
|
||||
|
||||
default_modules = 'edbob.time'
|
||||
modules = config.get('edbob', 'init', default=default_modules)
|
||||
if modules:
|
||||
for name in modules.split(','):
|
||||
name = name.strip()
|
||||
modules = modules.split(',')
|
||||
init_modules(modules, config)
|
||||
|
||||
edbob.graft(edbob, locals(), 'config')
|
||||
inited.append('edbob')
|
||||
|
||||
|
||||
def init_modules(names, config=None):
|
||||
"""
|
||||
Initialize the given modules. ``names`` should be a sequence of strings,
|
||||
each of which should be a dotted module name. If ``config`` is not
|
||||
specified, :attr:`edbob.config` is assumed.
|
||||
"""
|
||||
|
||||
if config is None:
|
||||
config = edbob.config
|
||||
|
||||
for name in names:
|
||||
name = name.strip()
|
||||
if name not in inited:
|
||||
module = __import__(name, globals(), locals(), fromlist=['init'])
|
||||
if not hasattr(module, 'init'):
|
||||
raise InitError(module)
|
||||
getattr(module, 'init')(config)
|
||||
# config.inited.append(name)
|
||||
|
||||
# config.inited.append('edbob')
|
||||
edbob.graft(edbob, locals(), 'config')
|
||||
edbob.inited = True
|
||||
inited.append(name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue