convert initialization module to unix format
This commit is contained in:
parent
5710acb6f5
commit
b939bc42aa
1 changed files with 98 additions and 98 deletions
|
@ -1,98 +1,98 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# edbob -- Pythonic Software Framework
|
# edbob -- Pythonic Software Framework
|
||||||
# Copyright © 2010-2012 Lance Edgar
|
# Copyright © 2010-2012 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of edbob.
|
# This file is part of edbob.
|
||||||
#
|
#
|
||||||
# edbob is free software: you can redistribute it and/or modify it under the
|
# edbob is free software: you can redistribute it and/or modify it under the
|
||||||
# terms of the GNU Affero General Public License as published by the Free
|
# terms of the GNU Affero General Public License as published by the Free
|
||||||
# Software Foundation, either version 3 of the License, or (at your option)
|
# Software Foundation, either version 3 of the License, or (at your option)
|
||||||
# any later version.
|
# any later version.
|
||||||
#
|
#
|
||||||
# edbob is distributed in the hope that it will be useful, but WITHOUT ANY
|
# edbob is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
||||||
# more details.
|
# more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with edbob. If not, see <http://www.gnu.org/licenses/>.
|
# along with edbob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
"""
|
"""
|
||||||
``edbob.initialization`` -- Initialization Framework
|
``edbob.initialization`` -- Initialization Framework
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import edbob
|
import edbob
|
||||||
from edbob.configuration import (
|
from edbob.configuration import (
|
||||||
AppConfigParser,
|
AppConfigParser,
|
||||||
default_system_paths,
|
default_system_paths,
|
||||||
default_user_paths,
|
default_user_paths,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['init']
|
__all__ = ['init']
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def init(appname='edbob', *args, **kwargs):
|
def init(appname='edbob', *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Initializes the edbob framework, typically by first reading some config
|
Initializes the edbob framework, typically by first reading some config
|
||||||
file(s) to determine which interfaces to engage. This must normally be
|
file(s) to determine which interfaces to engage. This must normally be
|
||||||
called prior to doing anything really useful, as it is responsible for
|
called prior to doing anything really useful, as it is responsible for
|
||||||
extending the live API in-place.
|
extending the live API in-place.
|
||||||
|
|
||||||
The meaning of ``args`` is as follows:
|
The meaning of ``args`` is as follows:
|
||||||
|
|
||||||
If ``args`` is empty, the ``EDBOB_CONFIG`` environment variable is first
|
If ``args`` is empty, the ``EDBOB_CONFIG`` environment variable is first
|
||||||
consulted. If it is nonempty, then its value is split according to
|
consulted. If it is nonempty, then its value is split according to
|
||||||
``os.pathsep`` and the resulting sequence is passed to
|
``os.pathsep`` and the resulting sequence is passed to
|
||||||
``edbob.config.read()``.
|
``edbob.config.read()``.
|
||||||
|
|
||||||
If both ``args`` and ``EDBOB_CONFIG`` are empty, the "standard" locations
|
If both ``args`` and ``EDBOB_CONFIG`` are empty, the "standard" locations
|
||||||
are assumed, and the results of calling both
|
are assumed, and the results of calling both
|
||||||
:func:`edbob.configuration.default_system_paths()` and
|
:func:`edbob.configuration.default_system_paths()` and
|
||||||
:func:`edbob.configuration.default_user_paths()` are passed on to
|
:func:`edbob.configuration.default_user_paths()` are passed on to
|
||||||
``edbob.config.read()``.
|
``edbob.config.read()``.
|
||||||
|
|
||||||
Any other values in ``args`` will be passed directly to
|
Any other values in ``args`` will be passed directly to
|
||||||
``edbob.config.read()`` and so will be interpreted there. Basically they
|
``edbob.config.read()`` and so will be interpreted there. Basically they
|
||||||
are assumed to be either strings, or sequences of strings, which represent
|
are assumed to be either strings, or sequences of strings, which represent
|
||||||
paths to various config files, each being read in the order in which it
|
paths to various config files, each being read in the order in which it
|
||||||
appears within ``args``. (Configuration is thereby cascaded such that the
|
appears within ``args``. (Configuration is thereby cascaded such that the
|
||||||
file read last will override those before it.)
|
file read last will override those before it.)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
config = AppConfigParser(appname)
|
config = AppConfigParser(appname)
|
||||||
|
|
||||||
if args:
|
if args:
|
||||||
config_paths = list(args)
|
config_paths = list(args)
|
||||||
elif os.environ.get('EDBOB_CONFIG'):
|
elif os.environ.get('EDBOB_CONFIG'):
|
||||||
config_paths = os.environ['EDBOB_CONFIG'].split(os.pathsep)
|
config_paths = os.environ['EDBOB_CONFIG'].split(os.pathsep)
|
||||||
else:
|
else:
|
||||||
config_paths = default_system_paths(appname) + default_user_paths(appname)
|
config_paths = default_system_paths(appname) + default_user_paths(appname)
|
||||||
|
|
||||||
shell = bool(kwargs.get('shell'))
|
shell = bool(kwargs.get('shell'))
|
||||||
for paths in config_paths:
|
for paths in config_paths:
|
||||||
config.read(paths, recurse=not shell)
|
config.read(paths, recurse=not shell)
|
||||||
config.configure_logging()
|
config.configure_logging()
|
||||||
|
|
||||||
default_modules = 'edbob.time'
|
default_modules = 'edbob.time'
|
||||||
modules = config.get('edbob', 'init', default=default_modules)
|
modules = config.get('edbob', 'init', default=default_modules)
|
||||||
if modules:
|
if modules:
|
||||||
for name in modules.split(','):
|
for name in modules.split(','):
|
||||||
name = name.strip()
|
name = name.strip()
|
||||||
module = __import__(name, globals(), locals(), fromlist=['init'])
|
module = __import__(name, globals(), locals(), fromlist=['init'])
|
||||||
getattr(module, 'init')(config)
|
getattr(module, 'init')(config)
|
||||||
# config.inited.append(name)
|
# config.inited.append(name)
|
||||||
|
|
||||||
# config.inited.append('edbob')
|
# config.inited.append('edbob')
|
||||||
edbob.graft(edbob, locals(), 'config')
|
edbob.graft(edbob, locals(), 'config')
|
||||||
edbob.inited = True
|
edbob.inited = True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue