Package config
Configuration support functionality.
The global config
object
(ConfigParser.SafeConfigParser
instance) is initialized with
default configuration from the defaults.cfg file, which is located in
this package. In order to ensure that the config contains custom values,
you must call the init_config
function during application
initialization:
from coilmq.config import config, init_config
init_config('/path/to/config.cfg')
config.getint('listen_port')
Author:
"Hans Lellelid" <hans@xmpl.org>
Copyright:
Copyright 2009 Hans Lellelid
License:
Licensed under the Apache License, Version 2.0 (the
"License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS
IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
See the License for the specific language governing permissions and
limitations under the License.
|
init_config(config_file)
Initialize the configuration from a config file. |
|
|
|
init_logging(logfile=None,
loglevel=logging.INFO,
configfile=None)
Configures the logging using either basic filename + loglevel or
passed config file path. |
|
|
|
resolve_name(name)
Resolve a dotted name to some object (usually class, module, or
function). |
|
|
|
config = ConfigParser.SafeConfigParser()
|
Initialize the configuration from a config file.
The values in config_file will override those already loaded from the
default configuration file (defaults.cfg, in current package).
This method does not setup logging.
- Parameters:
config_file (str ) - The path to a configuration file.
- Raises:
ValueError - if the specified config_file could not be read.
|
init_logging(logfile=None,
loglevel=logging.INFO,
configfile=None)
|
|
Configures the logging using either basic filename + loglevel or
passed config file path.
This is performed separately from init_config() in order to support the case where logging
should happen independent of (usu. *after*) other aspects of the
configuration initialization. For example, if logging may need to be
initialized within a daemon context.
- Parameters:
logfile (str ) - An explicitly specified logfile destination. If this is
specified in addition to default logging, a warning will be
issued.
loglevel (int ) - Which level to use when logging to explicitly specified file or
stdout.
configfile (str ) - The path to a configuration file. This takes precedence over any
explicitly specified logfile/loglevel (but a warning will be
logged if both are specified). If the file is not specified or
does not exist annd no logfile was specified, then the
default.cfg configuration file will be used to initialize
logging.
|
Resolve a dotted name to some object (usually class, module, or
function).
Supported naming formats include:
-
path.to.module:method
-
path.to.module.ClassName
>>> resolve_name('coilmq.store.memory.MemoryQueue')
<class 'coilmq.store.memory.MemoryQueue'>
>>> t = resolve_name('coilmq.store.dbm.make_dbm')
>>> type(t)
<type 'function'>
>>> t.__name__
'make_dbm'
- Parameters:
name (str ) - The dotted name (e.g. path.to.MyClass)
- Returns:
- The resolved object (class, callable, etc.) or None if not found.
|