Edgewall Software

Ticket #3833: env_reset.diff

File env_reset.diff, 6.7 KB (added by cmlenz, 16 months ago)

Somewhat different approach, works a lot better for me

  • trac/core.py

     
    11# -*- coding: utf-8 -*- 
    22# 
    3 # Copyright (C) 2003-2005 Edgewall Software 
     3# Copyright (C) 2003-2007 Edgewall Software 
    44# Copyright (C) 2003-2004 Jonas Borgström <jonas@edgewall.com> 
    5 # Copyright (C) 2004-2005 Christopher Lenz <cmlenz@gmx.de> 
     5# Copyright (C) 2004-2007 Christopher Lenz <cmlenz@gmx.de> 
    66# All rights reserved. 
    77# 
    88# This software is licensed as described in the file COPYING, which 
     
    2424    """Exception base class for errors in Trac.""" 
    2525 
    2626    title = 'Trac Error' 
    27      
     27 
    2828    def __init__(self, message, title=None, show_traceback=False): 
    2929        """If message is a genshi.builder.tag object, everything up to the 
    3030        first <p> will be displayed in the red box, and everything after will 
     
    218218        not be available. 
    219219        """ 
    220220        return True 
     221 
     222    def reset(self): 
     223        self.components = {} 
     224        self.enabled = {} 
  • trac/env.py

     
    2323import sys 
    2424from urlparse import urlsplit 
    2525 
    26 from trac import db_default 
     26from trac import db_default, loader 
    2727from trac.config import * 
    2828from trac.core import Component, ComponentManager, implements, Interface, \ 
    2929                      ExtensionPoint, TracError 
     
    167167            ] 
    168168        self._href = self._abs_href = None 
    169169 
    170         from trac.loader import load_components 
    171         plugins_dir = self.config.get('inherit', 'plugins_dir') 
    172         load_components(self, plugins_dir and (plugins_dir,)) 
    173  
    174170        if create: 
    175171            self.create(options) 
    176172        else: 
    177173            self.verify() 
    178174 
     175        self._load_components() 
     176 
    179177        if create: 
    180178            for setup_participant in self.setup_participants: 
    181179                setup_participant.environment_created() 
     
    225223        # By default, all components in the trac package are enabled 
    226224        return component_name.startswith('trac.') 
    227225 
     226    def reset(self): 
     227        ComponentManager.reset(self) 
     228        self._load_components() 
     229 
    228230    def verify(self): 
    229231        """Verify that the provided path points to a valid Trac environment 
    230232        directory.""" 
     
    429431        return self._abs_href 
    430432    abs_href = property(_get_abs_href, 'The application URL') 
    431433 
     434    def _load_components(self): 
     435        plugins_dir = self.shared_plugins_dir 
     436        loader.load_components(self, plugins_dir and (plugins_dir,)) 
    432437 
     438 
    433439class EnvironmentSetup(Component): 
    434440    implements(IEnvironmentSetupParticipant) 
    435441 
     
    521527            else: 
    522528                # Re-parse the configuration file if it changed since the last 
    523529                # the time it was parsed 
    524                 env.config.parse_if_needed() 
     530                if env.config.parse_if_needed(): 
     531                    env.reset() 
    525532        finally: 
    526533            env_cache_lock.release() 
    527534    else: 
  • trac/admin/web_ui.py

     
    381381                self._do_update(req) 
    382382            anchor = '' 
    383383            if req.args.has_key('plugin'): 
    384                 anchor = '#no' + req.args.get('plugin') 
     384                anchor = '#no%d' % (int(req.args.get('plugin')) + 1) 
    385385            req.redirect(req.href.admin(cat, page) + anchor) 
    386386 
    387387        return self._render_view(req) 
     
    426426 
    427427        # TODO: Validate that the uploaded file is actually a valid Trac plugin 
    428428 
     429        # Make the environment reset itself on the next request 
     430        self.env.config.touch() 
     431 
    429432    def _do_uninstall(self, req): 
    430433        """Uninstall a plugin.""" 
    431434        plugin_filename = req.args.get('plugin_filename') 
     
    437440        self.log.info('Uninstalling plugin %s', plugin_filename) 
    438441        os.remove(plugin_path) 
    439442 
     443        # Make the environment reset itself on the next request 
     444        self.env.config.touch() 
     445 
    440446    def _do_update(self, req): 
    441447        """Update component enablement.""" 
    442448        components = req.args.getlist('component') 
  • trac/config.py

     
    173173        finally: 
    174174            fileobj.close() 
    175175 
    176     def parse_if_needed(self): 
    177         # Load global configuration 
     176    def parse_if_needed(self, check_only=False): 
    178177        if not self.filename or not os.path.isfile(self.filename): 
    179             return 
     178            return False 
     179 
     180        changed = False 
    180181        modtime = os.path.getmtime(self.filename) 
    181182        if modtime > self._lastmtime: 
    182183            self.parser.read(self.filename) 
    183184            self._lastmtime = modtime 
     185            changed = True 
    184186 
    185187        if self.parser.has_option('inherit', 'file'): 
    186188            filename = self.parser.get('inherit', 'file') 
     
    189191                                        filename) 
    190192            if not self.parent or self.parent.filename != filename: 
    191193                self.parent = Configuration(filename) 
     194                changed = True 
    192195            else: 
    193                 self.parent.parse_if_needed() 
     196                changed |= self.parent.parse_if_needed(check_only=check_only) 
    194197        elif self.parent: 
     198            changed = True 
    195199            self.parent = None 
    196200 
     201        return changed 
    197202 
     203    def touch(self): 
     204        os.utime(self.filename, None) 
     205 
     206 
    198207class Section(object): 
    199208    """Proxy for a specific configuration section. 
    200209     
  • trac/log.py

     
    4444            format = '%(asctime)s ' + format 
    4545    datefmt = '' 
    4646    if logtype == 'stderr': 
    47         datefmt = '%X'         
     47        datefmt = '%X' 
    4848    level = level.upper() 
    4949    if level in ('DEBUG', 'ALL'): 
    5050        logger.setLevel(logging.DEBUG) 
  • trac/util/__init__.py

     
    228228        pkginfo = email.message_from_string(dist.get_metadata('PKG-INFO')) 
    229229        for attr in [key for key in attrs if key in pkginfo]: 
    230230            info[normalize(attr)] = pkginfo[attr] 
     231    except IOError, e: 
     232        err = 'Failed to read PKG-INFO file for %s: %s' % (dist, e) 
     233        for attr in attrs: 
     234            info[normalize(attr)] = err 
    231235    except email.Errors.MessageError, e: 
    232236        err = 'Failed to parse PKG-INFO file for %s: %s' % (dist, e) 
    233237        for attr in attrs: