comparison roundup/configuration.py @ 2619:4b4ca3bd086b

added logging support; fix FilePathOption: empty values are empty, not a relative directory paths.
author Alexander Smishlajev <a1s@users.sourceforge.net>
date Sun, 25 Jul 2004 12:44:16 +0000
parents 8b08558e30a0
children 92c820cfcc4a
comparison
equal deleted inserted replaced
2618:8b08558e30a0 2619:4b4ca3bd086b
1 # Roundup Issue Tracker configuration support 1 # Roundup Issue Tracker configuration support
2 # 2 #
3 # $Id: configuration.py,v 1.1 2004-07-25 11:29:40 a1s Exp $ 3 # $Id: configuration.py,v 1.2 2004-07-25 12:44:16 a1s Exp $
4 # 4 #
5 __docformat__ = "restructuredtext" 5 __docformat__ = "restructuredtext"
6 6
7 import imp 7 import imp
8 import os 8 import os
9 import time 9 import time
10 import ConfigParser 10 import ConfigParser
11 11
12 from roundup import instance, rlog
12 # XXX i don't think this module needs string translation, does it? 13 # XXX i don't think this module needs string translation, does it?
13 14
14 ### Exceptions 15 ### Exceptions
15 16
16 class ConfigurationError(Exception): 17 class ConfigurationError(Exception):
285 286
286 """ 287 """
287 288
288 def get(self): 289 def get(self):
289 _val = Option.get(self) 290 _val = Option.get(self)
290 if not os.path.isabs(_val): 291 if _val and not os.path.isabs(_val):
291 _val = os.path.join(self.config["TRACKER_HOME"], _val) 292 _val = os.path.join(self.config["TRACKER_HOME"], _val)
292 return _val 293 return _val
293 294
294 class FloatNumberOption(Option): 295 class FloatNumberOption(Option):
295 296
381 "The URL MUST include the cgi-bin part or anything else\n" 382 "The URL MUST include the cgi-bin part or anything else\n"
382 "that is required to get to the home page of the tracker.\n" 383 "that is required to get to the home page of the tracker.\n"
383 "You MUST include a trailing '/' in the URL."), 384 "You MUST include a trailing '/' in the URL."),
384 (MailAddressOption, "email", "issue_tracker", 385 (MailAddressOption, "email", "issue_tracker",
385 "Email address that mail to roundup should go to"), 386 "Email address that mail to roundup should go to"),
387 )),
388 ("logging", (
389 (FilePathOption, "config", "",
390 "Path to configuration file for standard Python logging module.\n"
391 "If this option is set, logging configuration is loaded\n"
392 "from specified file; options 'filename' and 'level'\n"
393 "in this section are ignored."),
394 (FilePathOption, "filename", "",
395 "Log file name for minimal logging facility built into Roundup.\n"
396 "If no file name specified, log messages are written on stderr.\n"
397 "If above 'config' option is set, this option has no effect."),
398 (Option, "level", "ERROR",
399 "Minimal severity level of messages written to log file.\n"
400 "If above 'config' option is set, this option has no effect.\n"
401 "Allowed values: DEBUG, INFO, WARNING, ERROR"),
386 )), 402 )),
387 # XXX This section covers two service areas: 403 # XXX This section covers two service areas:
388 # outgoing mail (domain, smtp parameters) 404 # outgoing mail (domain, smtp parameters)
389 # and creation of issues from incoming mail. 405 # and creation of issues from incoming mail.
390 # These things should be separated. 406 # These things should be separated.
477 sections = None 493 sections = None
478 # lists of option names for each section, in order 494 # lists of option names for each section, in order
479 section_options = None 495 section_options = None
480 # mapping from option names and aliases to Option instances 496 # mapping from option names and aliases to Option instances
481 options = None 497 options = None
498 # logging engine
499 logging = rlog.BasicLogging()
482 500
483 def __init__(self, tracker_home=None): 501 def __init__(self, tracker_home=None):
484 # initialize option containers: 502 # initialize option containers:
485 self.sections = [] 503 self.sections = []
486 self.section_options = {} 504 self.section_options = {}
493 _option = _class(self, _section, *_args) 511 _option = _class(self, _section, *_args)
494 self.add_option(_option) 512 self.add_option(_option)
495 # load the config if tracker_home given 513 # load the config if tracker_home given
496 if tracker_home is not None: 514 if tracker_home is not None:
497 self.load(tracker_home) 515 self.load(tracker_home)
516 else:
517 self.init_logging()
498 518
499 def add_option(self, option): 519 def add_option(self, option):
500 """Adopt a new Option object""" 520 """Adopt a new Option object"""
501 _section = option.section 521 _section = option.section
502 _name = option.setting 522 _name = option.setting
513 533
514 def reset(self): 534 def reset(self):
515 """Set all options to their default values""" 535 """Set all options to their default values"""
516 for _option in self.items(): 536 for _option in self.items():
517 _option.reset() 537 _option.reset()
538 self.init_logging()
539
540 def init_logging(self):
541 _file = self["LOGGING_CONFIG"]
542 if _file and os.path.isfile(_file):
543 try:
544 import logging
545 _logging = logging
546 except ImportError, msg:
547 raise instance.TrackerError, \
548 'Python logging module unavailable: %s' % msg
549 _logging.fileConfig(_file)
550 else:
551 _logging = rlog.BasicLogging()
552 _file = self["LOGGING_FILENAME"]
553 if _file:
554 _logging.setFile(_file)
555 _logging.setLevel(self["LOGGING_LEVEL"] or "ERROR")
556 self.logging = _logging
518 557
519 # option and section locators (used in option access methods) 558 # option and section locators (used in option access methods)
520 559
521 def _get_option(self, name): 560 def _get_option(self, name):
522 try: 561 try:
544 # .ini file loaded ok. set the options, starting from TRACKER_HOME 583 # .ini file loaded ok. set the options, starting from TRACKER_HOME
545 self.reset() 584 self.reset()
546 self.TRACKER_HOME = tracker_home 585 self.TRACKER_HOME = tracker_home
547 for _option in self.items(): 586 for _option in self.items():
548 _option.load_ini(_config) 587 _option.load_ini(_config)
588 self.init_logging()
549 589
550 def load_pyconfig(self, tracker_home): 590 def load_pyconfig(self, tracker_home):
551 """Set options from config.py file in given tracker_home directory""" 591 """Set options from config.py file in given tracker_home directory"""
552 # try to locate and import the module 592 # try to locate and import the module
553 _mod_fp = None 593 _mod_fp = None
564 # module loaded ok. set the options, starting from TRACKER_HOME 604 # module loaded ok. set the options, starting from TRACKER_HOME
565 self.reset() 605 self.reset()
566 self.TRACKER_HOME = tracker_home 606 self.TRACKER_HOME = tracker_home
567 for _option in self.items(): 607 for _option in self.items():
568 _option.load_pyconfig(_config) 608 _option.load_pyconfig(_config)
609 self.init_logging()
569 # backward compatibility: 610 # backward compatibility:
570 # SMTP login parameters were specified as a tuple in old style configs 611 # SMTP login parameters were specified as a tuple in old style configs
571 # convert them to new plain string options 612 # convert them to new plain string options
572 _mailuser = getattr(_config, "MAILUSER", ()) 613 _mailuser = getattr(_config, "MAILUSER", ())
573 if len(_mailuser) > 0: 614 if len(_mailuser) > 0:

Roundup Issue Tracker: http://roundup-tracker.org/