diff options
author | André Erdmann <dywi@mailerd.de> | 2012-07-03 19:42:53 +0200 |
---|---|---|
committer | André Erdmann <dywi@mailerd.de> | 2012-07-03 19:42:53 +0200 |
commit | 19da5ea18f1e5010b369ee259c4a4f7fd4d501aa (patch) | |
tree | 269c289b2c91bb0508df4b714478e4f3026d28be /roverlay | |
parent | DescriptionReader logging (diff) | |
download | R_overlay-19da5ea18f1e5010b369ee259c4a4f7fd4d501aa.tar.gz R_overlay-19da5ea18f1e5010b369ee259c4a4f7fd4d501aa.tar.bz2 R_overlay-19da5ea18f1e5010b369ee259c4a4f7fd4d501aa.zip |
roverlay, __init__
* using recipe/easylogger to set up logging
* config file is no longer loaded automatically
modified: roverlay/__init__.py
new file: roverlay/recipe/easylogger.py
Diffstat (limited to 'roverlay')
-rw-r--r-- | roverlay/__init__.py | 52 | ||||
-rw-r--r-- | roverlay/recipe/easylogger.py | 39 |
2 files changed, 71 insertions, 20 deletions
diff --git a/roverlay/__init__.py b/roverlay/__init__.py index e33811d..447c140 100644 --- a/roverlay/__init__.py +++ b/roverlay/__init__.py @@ -2,29 +2,41 @@ # Copyright 2006-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -import logging +import roverlay.config +import roverlay.recipe.easylogger -from roverlay import config +name = "R_overlay" +version = ( 0, 0, 1 ) +version_str = '.'.join ( ( str ( i ) for i in version ) ) +description_str = "R overlay creation " + version_str +license_str = '\n'.join (( + 'Copyright <fixthis>-2012 Gentoo Foundation', + 'Distributed under the terms of the GNU General Public License v2', +)) -config.loader().load_config ( 'R-overlay.conf' ) -config.loader().load_field_definition ( 'description_fields.conf' ) -logging.basicConfig ( - level=logging.DEBUG, - filename=config.get ( [ 'LOG', 'FILE', 'main' ], 'roverlay.log' ), - filemode='a', - format='%(asctime)s %(levelname)-8s %(name)-14s -- %(message)s', - datefmt='%F %H:%M:%S' -) +roverlay.recipe.easylogger.setup_initial() + +def load_config_file ( cfile, extraconf=None ): + """Loads the config, including the field definition file. + Sets up the logger afterwards. + (Don't call this method more than once.) + + arguments: + * cfile -- path to the config file + * extraconf -- a dict with additional config entries that will override + entries read from cfile + """ + roverlay.config.loader().load_config ( cfile ) + + if extraconf is not None: + roverlay.config.access().merge_with ( extraconf ) + + roverlay.recipe.easylogger.setup ( roverlay.config.access() ) + + fdef_f = config.get_or_fail ( "DESCRIPTION.field_definition_file" ) + roverlay.config.loader().load_field_definition ( fdef_f ) + -# add console output to the logger -ch = logging.StreamHandler() -ch.setLevel ( logging.DEBUG ) -ch.setFormatter ( - logging.Formatter ( '%(levelname)-8s %(name)-14s -- %(message)s' ) -) -logging.getLogger().addHandler ( ch ) -del ch -VERSION = "0.0-pre1" diff --git a/roverlay/recipe/easylogger.py b/roverlay/recipe/easylogger.py new file mode 100644 index 0000000..112d07b --- /dev/null +++ b/roverlay/recipe/easylogger.py @@ -0,0 +1,39 @@ +# R Overlay +# Copyright 2006-2012 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +import logging + +_STATUS = 0 + +def setup ( conf ): + global _STATUS + if _STATUS > 1: + return + + logging.basicConfig ( + level=logging.DEBUG, + filename=conf.get ( [ 'LOG', 'FILE', 'main' ], 'roverlay.log' ), + filemode='a', + format='%(asctime)s %(levelname)-8s %(name)-14s -- %(message)s', + datefmt='%F %H:%M:%S' + ) + + # add console output to the logger + ch = logging.StreamHandler() + ch.setLevel ( logging.DEBUG ) + ch.setFormatter ( + logging.Formatter ( '%(levelname)-8s %(name)-14s -- %(message)s' ) + ) + logging.getLogger().addHandler ( ch ) + + _STATUS = 2 + +def setup_initial(): + global _STATUS + if _STATUS > 0: + return + + pass + + _STATUS = 1 |