Edgewall Software

Ticket #3833: env_reset.3.diff

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

Updated patch

  • trac/env.py

     
    516516        env_cache_lock.acquire() 
    517517        try: 
    518518            env = env_cache.get(env_path) 
     519            if env and env.config.parse_if_needed(): 
     520                # The environment configuration has changed, so shut it down 
     521                # and remove it from the cache so that it gets reinitialized 
     522                env.shutdown() 
     523                if hasattr(env.log, '_trac_handler'): 
     524                    env.log.removeHandler(env.log._trac_handler) 
     525                del env_cache[env_path] 
     526                env = None 
    519527            if env is None: 
    520528                env = env_cache.setdefault(env_path, open_environment(env_path)) 
    521             else: 
    522                 # Re-parse the configuration file if it changed since the last 
    523                 # the time it was parsed 
    524                 env.config.parse_if_needed() 
    525529        finally: 
    526530            env_cache_lock.release() 
    527531    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/admin/templates/admin_logging.html

     
    5252        <div class="buttons"> 
    5353          <input type="submit" value="Apply changes"/> 
    5454        </div> 
    55         <p class="help"> 
    56           You may need to restart the server for these changes to take effect. 
    57         </p> 
    5855      </fieldset> 
    5956    </form> 
    6057  </body> 
  • trac/config.py

     
    174174            fileobj.close() 
    175175 
    176176    def parse_if_needed(self): 
    177         # Load global configuration 
    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: 
     183            self.parser._sections = {} 
    182184            self.parser.read(self.filename) 
    183185            self._lastmtime = modtime 
     186            changed = True 
    184187 
    185188        if self.parser.has_option('inherit', 'file'): 
    186189            filename = self.parser.get('inherit', 'file') 
     
    189192                                        filename) 
    190193            if not self.parent or self.parent.filename != filename: 
    191194                self.parent = Configuration(filename) 
     195                changed = True 
    192196            else: 
    193                 self.parent.parse_if_needed() 
     197                changed |= self.parent.parse_if_needed() 
    194198        elif self.parent: 
     199            changed = True 
    195200            self.parent = None 
    196201 
     202        return changed 
    197203 
     204    def touch(self): 
     205        os.utime(self.filename, None) 
     206 
     207 
    198208class Section(object): 
    199209    """Proxy for a specific configuration section. 
    200210     
     
    292302        """ 
    293303        if self.config.parser.has_option(self.name, name): 
    294304            path = self.config.parser.get(self.name, name) 
    295             if path and not os.path.isabs(path): 
     305            if not path: 
     306                return default 
     307            if not os.path.isabs(path): 
    296308                path = os.path.join(os.path.dirname(self.config.filename), 
    297309                                    path) 
    298310            return os.path.normcase(os.path.realpath(path)) 
  • trac/tests/env.py

     
    11from trac import db_default 
     2from trac.db import sqlite_backend 
    23from trac.env import Environment 
    34 
    45import os.path 
  • 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) 
     
    5858        logger.setLevel(logging.WARNING) 
    5959    formatter = logging.Formatter(format, datefmt) 
    6060    hdlr.setFormatter(formatter) 
    61     logger.addHandler(hdlr)  
     61    logger.addHandler(hdlr) 
    6262 
     63    # Remember our handler so that we can remove it later 
     64    logger._trac_handler = hdlr  
     65 
    6366    return logger 
  • 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: