Mercurial > p > roundup > code
comparison roundup/configuration.py @ 3155:57b60bda9473
Python 2.3 minimum version - bye bye roundup.rlog, you had a short life.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 14 Feb 2005 02:48:12 +0000 |
| parents | 519b92df37dc |
| children | 2913b42c0810 |
comparison
equal
deleted
inserted
replaced
| 3153:fdcba2ef2673 | 3155:57b60bda9473 |
|---|---|
| 1 # Roundup Issue Tracker configuration support | 1 # Roundup Issue Tracker configuration support |
| 2 # | 2 # |
| 3 # $Id: configuration.py,v 1.24 2005-01-13 05:02:18 richard Exp $ | 3 # $Id: configuration.py,v 1.25 2005-02-14 02:48:10 richard Exp $ |
| 4 # | 4 # |
| 5 __docformat__ = "restructuredtext" | 5 __docformat__ = "restructuredtext" |
| 6 | 6 |
| 7 import getopt | 7 import getopt |
| 8 import imp | 8 import imp |
| 9 import os | 9 import os |
| 10 import time | 10 import time |
| 11 import ConfigParser | 11 import ConfigParser |
| 12 | 12 import logging, logging.config |
| 13 from roundup import rlog | 13 import sys |
| 14 | |
| 14 # XXX i don't think this module needs string translation, does it? | 15 # XXX i don't think this module needs string translation, does it? |
| 15 | 16 |
| 16 ### Exceptions | 17 ### Exceptions |
| 17 | 18 |
| 18 class ConfigurationError(Exception): | 19 class ConfigurationError(Exception): |
| 1026 | 1027 |
| 1027 """ | 1028 """ |
| 1028 | 1029 |
| 1029 # module name for old style configuration | 1030 # module name for old style configuration |
| 1030 PYCONFIG = "config" | 1031 PYCONFIG = "config" |
| 1031 # placeholder so we can assign later | |
| 1032 logging = None | |
| 1033 # user configs | 1032 # user configs |
| 1034 ext = None | 1033 ext = None |
| 1035 detectors = None | 1034 detectors = None |
| 1036 | 1035 |
| 1037 def __init__(self, home_dir=None): | 1036 def __init__(self, home_dir=None): |
| 1038 Config.__init__(self, home_dir, SETTINGS) | 1037 Config.__init__(self, home_dir, SETTINGS) |
| 1039 self.logging = rlog.BasicLogging() | |
| 1040 # load the config if home_dir given | 1038 # load the config if home_dir given |
| 1041 if home_dir is None: | 1039 if home_dir is None: |
| 1042 self.init_logging() | 1040 self.init_logging() |
| 1043 | 1041 |
| 1044 def _get_unset_options(self): | 1042 def _get_unset_options(self): |
| 1064 self.init_logging() | 1062 self.init_logging() |
| 1065 | 1063 |
| 1066 def init_logging(self): | 1064 def init_logging(self): |
| 1067 _file = self["LOGGING_CONFIG"] | 1065 _file = self["LOGGING_CONFIG"] |
| 1068 if _file and os.path.isfile(_file): | 1066 if _file and os.path.isfile(_file): |
| 1069 try: | 1067 logging.config.fileConfig(_file) |
| 1070 import logging | 1068 return |
| 1071 _logging = logging | 1069 |
| 1072 except ImportError, _err: | 1070 _file = self["LOGGING_FILENAME"] |
| 1073 _option = self._get_option("LOGGING_CONFIG") | 1071 # set file & level on the root logger |
| 1074 raise OptionValueError(_option, _file, | 1072 logger = logging.getLogger() |
| 1075 "Python logging module is not available: %s" % _err) | 1073 if _file: |
| 1076 _logging.fileConfig(_file) | 1074 hdlr = logging.FileHandler(_file) |
| 1077 else: | 1075 else: |
| 1078 _logging = rlog.BasicLogging() | 1076 hdlr = logging.StreamHandler(sys.stdout) |
| 1079 _file = self["LOGGING_FILENAME"] | 1077 formatter = logging.Formatter( |
| 1080 if _file: | 1078 '%(asctime)s %(levelname)s %(message)s') |
| 1081 _logging.setFile(_file) | 1079 hdlr.setFormatter(formatter) |
| 1082 _logging.setLevel(self["LOGGING_LEVEL"] or "ERROR") | 1080 # no logging API to remove all existing handlers!?! |
| 1083 self.logging = _logging | 1081 logger.handlers = [hdlr] |
| 1082 logger.setLevel(logging._levelNames[self["LOGGING_LEVEL"] or "ERROR"]) | |
| 1084 | 1083 |
| 1085 def load(self, home_dir): | 1084 def load(self, home_dir): |
| 1086 """Load configuration from path designated by home_dir argument""" | 1085 """Load configuration from path designated by home_dir argument""" |
| 1087 if os.path.isfile(os.path.join(home_dir, self.INI_FILE)): | 1086 if os.path.isfile(os.path.join(home_dir, self.INI_FILE)): |
| 1088 self.load_ini(home_dir) | 1087 self.load_ini(home_dir) |
