Edgewall Software

Changeset 2335

Show
Ignore:
Timestamp:
10/08/2005 11:13:05 PM (3 years ago)
Author:
cmlenz
Message:
  • Change the configuration for disabling components: instead of a [disabled_components] section that lists all components to be disabled, you can now enable/disable components in a [components] section. This also means that plugins need to be explicitly enabled for every environment. Closes #2019.
  • Support a global trac.ini configuration file (by default in $prefix/share/trac/conf). Closes #1051. Thanks to Alec Thomas for the patch.
Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/scripts/trac-postinstall.py

    r1745 r2335  
    1414    prefix = sysconfig.get_config_var('prefix') 
    1515 
     16    conf_dir = os.path.join(prefix, 'share', 'trac', 'conf') 
    1617    templates_dir = os.path.join(prefix, 'share', 'trac', 'templates') 
    1718    htdocs_dir = os.path.join(prefix, 'share', 'trac', 'htdocs') 
     
    2526# This file was autogenerated when installing Trac %(version)s. 
    2627# 
     28__default_conf_dir__ = %(conf)r 
    2729__default_templates_dir__ = %(templates)r 
    2830__default_htdocs_dir__ = %(htdocs)r 
     
    3032__default_macros_dir__ = %(macros)r 
    3133 
    32 """ % {'version': trac.__version__, 'templates': templates_dir, 
    33        'htdocs': htdocs_dir, 'wiki': wiki_dir, 'macros': macros_dir}) 
     34""" % {'version': trac.__version__, 'conf': conf_dir, 
     35       'templates': templates_dir, 'htdocs': htdocs_dir, 
     36       'wiki': wiki_dir, 'macros': macros_dir}) 
    3437    fd.close() 
    3538 
  • trunk/setup.py

    r2244 r2335  
    3232 
    3333     def siteconfig(self): 
     34         conf_dir = os.path.join(self.prefix, 'share', 'trac', 'conf') 
    3435         templates_dir = os.path.join(self.prefix, 'share', 'trac', 'templates') 
    3536         htdocs_dir = os.path.join(self.prefix, 'share', 'trac', 'htdocs') 
    3637         wiki_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-default') 
    3738         macros_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-macros') 
    38          f = open(_p('trac/siteconfig.py'),'w') 
     39         f = open(_p('trac/siteconfig.py'), 'w') 
    3940         f.write(""" 
    4041# PLEASE DO NOT EDIT THIS FILE! 
    4142# This file was autogenerated when installing %(trac)s %(ver)s. 
    4243# 
     44__default_conf_dir__ = %(conf)r 
    4345__default_templates_dir__ = %(templates)r 
    4446__default_htdocs_dir__ = %(htdocs)r 
     
    4648__default_macros_dir__ = %(macros)r 
    4749 
    48 """ % {'trac':PACKAGE, 'ver':VERSION, 'templates':_p(templates_dir), 
    49        'htdocs':_p(htdocs_dir), 'wiki':_p(wiki_dir), 'macros':_p(macros_dir)}) 
     50""" % {'trac': PACKAGE, 'ver': VERSION, 'conf': _p(conf_dir), 
     51       'templates': _p(templates_dir), 'htdocs': _p(htdocs_dir), 
     52       'wiki': _p(wiki_dir), 'macros': _p(macros_dir)}) 
    5053         f.close() 
    5154 
     
    132135                mode |= 044 
    133136                os.chmod(path, mode) 
    134  
    135137 
    136138# Our custom bdist_wininst 
  • trunk/trac/config.py

    r2127 r2335  
    1818 
    1919from ConfigParser import ConfigParser 
    20 import os.path 
     20import os 
     21import sys 
    2122 
    2223 
    2324class Configuration: 
    24     """ 
    25     Thin layer over ConfigParser from the Python standard library. 
     25    """Thin layer over `ConfigParser` from the Python standard library. 
     26 
    2627    In addition to providing some convenience methods, the class remembers 
    2728    the last modification time of the configuration file, and reparses it 
     
    3031 
    3132    def __init__(self, filename): 
     33        self._defaults = {} 
    3234        self.filename = filename 
    3335        self.parser = ConfigParser() 
    34         self.__defaults = {} 
    35         self.__lastmtime = 0 
     36        self._lastmtime = 0 
     37        self.site_filename = os.path.join(default_dir('conf'), 'trac.ini') 
     38        self.site_parser = ConfigParser() 
     39        self._lastsitemtime = 0 
    3640        self.parse_if_needed() 
    3741 
     
    3943        if not self.parser.has_option(section, name): 
    4044            if default is None: 
    41                 return self.__defaults.get((section, name), '') 
     45                return self._defaults.get((section, name), '') 
    4246            return default 
    4347        return self.parser.get(section, name) 
    4448 
    4549    def setdefault(self, section, name, value): 
    46         self.__defaults[(section, name)] = value 
     50        if (section, name) not in self._defaults: 
     51            self._defaults[(section, name)] = value 
    4752 
    4853    def set(self, section, name, value): 
    49         """ 
    50         Changes a config value, these changes are _not_ persistent unless saved 
    51         with `save()`. 
     54        """Change a configuration value. 
     55         
     56        These changes are not persistent unless saved with `save()`. 
    5257        """ 
    5358        if not self.parser.has_section(section): 
     
    5661 
    5762    def options(self, section): 
    58         if not self.parser.has_section(section): 
    59             return [] 
    60         try: 
    61             return self.parser.items(section) 
    62         except AttributeError: 
    63             options = [] 
     63        options = [] 
     64        if self.parser.has_section(section): 
    6465            for option in self.parser.options(section): 
    6566                options.append((option, self.parser.get(section, option))) 
    66             return options 
     67        for option, value in self._defaults.iteritems(): 
     68            if option[0] == section: 
     69                if not [exists for exists in options if exists[0] == option[1]]: 
     70                    options.append((option[1], value)) 
     71        return options 
    6772 
    6873    def __contains__(self, name): 
     
    7984        if not self.filename: 
    8085            return 
    81         self.parser.write(open(self.filename, 'w')) 
     86        fileobj = file(self.filename, 'w') 
     87        try: 
     88            self.parser.write(fileobj) 
     89        finally: 
     90            fileobj.close() 
    8291 
    8392    def parse_if_needed(self): 
     93        # Merge global configuration option into _defaults 
     94        if os.path.isfile(self.site_filename): 
     95            modtime = os.path.getmtime(self.site_filename) 
     96            if modtime > self._lastsitemtime: 
     97                self.site_parser.read(self.site_filename) 
     98                for section in self.site_parser.sections(): 
     99                    for option in self.site_parser.options(section): 
     100                        value = self.site_parser.get(section, option) 
     101                        self._defaults[(section, option)] = value 
     102                self._lastsitemtime = modtime 
     103 
    84104        if not self.filename: 
    85105            return 
    86106        modtime = os.path.getmtime(self.filename) 
    87         if modtime > self.__lastmtime: 
    88             self.parser.readfp(open(self.filename)) 
    89             self.__lastmtime = modtime 
     107        if modtime > self._lastmtime: 
     108            self.parser.read(self.filename) 
     109            self._lastmtime = modtime 
    90110 
    91111 
     
    97117        # This is not a regular install with a generated siteconfig.py file, 
    98118        # so try to figure out the directory based on common setups 
    99         import os.path, sys 
    100119        special_dirs = {'wiki': 'wiki-default', 'macros': 'wiki-macros'} 
    101120        dirname = special_dirs.get(name, name) 
  • trunk/trac/env.py

    r2260 r2335  
    1717from __future__ import generators 
    1818 
     19import os 
     20 
    1921from trac import db, db_default, util 
    2022from trac.config import Configuration 
     
    2224                      ExtensionPoint, TracError 
    2325 
    24 import os 
    25 import os.path 
    26  
    2726__all__ = ['Environment', 'IEnvironmentSetupParticipant', 'open_environment'] 
    2827 
     
    3736 
    3837    def environment_needs_upgrade(db): 
    39         """FIXME""" 
     38        """Called when Trac checks whether the environment needs to be upgraded. 
     39         
     40        Should return `True` if this participant needs an upgrade to be 
     41        performed, `False` otherwise. 
     42        """ 
    4043 
    4144    def upgrade_environment(db): 
    42         """FIXME""" 
     45        """Actually perform an environment upgrade. 
     46         
     47        Implementations of this method should not commit any database 
     48        transactions. This is done implicitly after all participants have 
     49        performed the upgrades they need without an error being raised. 
     50        """ 
    4351 
    4452 
     
    99107        about to be activated. If this method returns false, the component does 
    100108        not get activated.""" 
    101         component_name = (cls.__module__ + '.' + cls.__name__).lower() 
    102         for name,value in self.config.options('disabled_components'): 
    103             if value in util.TRUE and component_name.startswith(name): 
    104                 return False 
    105         return True 
     109        if not isinstance(cls, (str, unicode)): 
     110            component_name = (cls.__module__ + '.' + cls.__name__).lower() 
     111        else: 
     112            component_name = cls 
     113 
     114        rules = [(name.lower(), value.lower() in ('enabled', 'on')) 
     115                 for name, value in self.config.options('components')] 
     116        rules.sort(lambda a, b: -cmp(len(a[0]), len(b[0]))) 
     117 
     118        for pattern, enabled in rules: 
     119            if component_name == pattern or pattern.endswith('*') \ 
     120                    and component_name.startswith(pattern[:-1]): 
     121                return enabled 
     122 
     123        # By default, all components in the trac package are enabled 
     124        return component_name.startswith('trac.') 
    106125 
    107126    def verify(self): 
     
    170189        _create_file(os.path.join(self.path, 'conf', 'trac.ini')) 
    171190        self.load_config() 
    172         for section,name,value in db_default.default_config: 
     191        for section, name, value in db_default.default_config: 
    173192            self.config.set(section, name, value) 
    174193        self.config.set('trac', 'database', db_str) 
     
    190209        """Load the configuration file.""" 
    191210        self.config = Configuration(os.path.join(self.path, 'conf', 'trac.ini')) 
    192         for section,name,value in db_default.default_config: 
     211        for section, name, value in db_default.default_config: 
    193212            self.config.setdefault(section, name, value) 
    194213