Mercurial > p > roundup > code
comparison roundup/configuration.py @ 3431:26dc6b92ac26
Config, CoreConfig: accept setting overrides in constructor
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Sat, 03 Dec 2005 11:21:17 +0000 |
| parents | 2b27c92d64dc |
| children | be505af06586 |
comparison
equal
deleted
inserted
replaced
| 3430:d54df26b1a7e | 3431:26dc6b92ac26 |
|---|---|
| 1 # Roundup Issue Tracker configuration support | 1 # Roundup Issue Tracker configuration support |
| 2 # | 2 # |
| 3 # $Id: configuration.py,v 1.28 2005-12-03 09:31:00 a1s Exp $ | 3 # $Id: configuration.py,v 1.29 2005-12-03 11:21:17 a1s Exp $ |
| 4 # | 4 # |
| 5 __docformat__ = "restructuredtext" | 5 __docformat__ = "restructuredtext" |
| 6 | 6 |
| 7 import getopt | 7 import getopt |
| 8 import imp | 8 import imp |
| 660 # mapping from option names and aliases to Option instances | 660 # mapping from option names and aliases to Option instances |
| 661 options = None | 661 options = None |
| 662 # actual name of the config file. set on load. | 662 # actual name of the config file. set on load. |
| 663 filepath = os.path.join(HOME, INI_FILE) | 663 filepath = os.path.join(HOME, INI_FILE) |
| 664 | 664 |
| 665 def __init__(self, config_path=None, layout=None): | 665 def __init__(self, config_path=None, layout=None, settings={}): |
| 666 """Initialize confing instance | 666 """Initialize confing instance |
| 667 | 667 |
| 668 Parameters: | 668 Parameters: |
| 669 config_path: | 669 config_path: |
| 670 optional directory or file name of the config file. | 670 optional directory or file name of the config file. |
| 672 If config_path is a directory name, use default base name | 672 If config_path is a directory name, use default base name |
| 673 of the config file. | 673 of the config file. |
| 674 layout: | 674 layout: |
| 675 optional configuration layout, a sequence of | 675 optional configuration layout, a sequence of |
| 676 section definitions suitable for .add_section() | 676 section definitions suitable for .add_section() |
| 677 settings: | |
| 678 optional setting overrides (dictionary). | |
| 679 The overrides are applied after loading config file. | |
| 677 | 680 |
| 678 """ | 681 """ |
| 679 # initialize option containers: | 682 # initialize option containers: |
| 680 self.sections = [] | 683 self.sections = [] |
| 681 self.section_descriptions = {} | 684 self.section_descriptions = {} |
| 685 if layout: | 688 if layout: |
| 686 for section in layout: | 689 for section in layout: |
| 687 self.add_section(*section) | 690 self.add_section(*section) |
| 688 if config_path is not None: | 691 if config_path is not None: |
| 689 self.load(config_path) | 692 self.load(config_path) |
| 693 for (name, value) in settings.items(): | |
| 694 self[name.upper()] = value | |
| 690 | 695 |
| 691 def add_section(self, section, options, description=None): | 696 def add_section(self, section, options, description=None): |
| 692 """Define new config section | 697 """Define new config section |
| 693 | 698 |
| 694 Parameters: | 699 Parameters: |
| 1077 PYCONFIG = "config" | 1082 PYCONFIG = "config" |
| 1078 # user configs | 1083 # user configs |
| 1079 ext = None | 1084 ext = None |
| 1080 detectors = None | 1085 detectors = None |
| 1081 | 1086 |
| 1082 def __init__(self, home_dir=None): | 1087 def __init__(self, home_dir=None, settings={}): |
| 1083 Config.__init__(self, home_dir, SETTINGS) | 1088 Config.__init__(self, home_dir, layout=SETTINGS, settings=settings) |
| 1084 # load the config if home_dir given | 1089 # load the config if home_dir given |
| 1085 if home_dir is None: | 1090 if home_dir is None: |
| 1086 self.init_logging() | 1091 self.init_logging() |
| 1087 | 1092 |
| 1088 def _get_unset_options(self): | 1093 def _get_unset_options(self): |
