Edgewall Software

Ticket #3833: env_reset.3.osimons.diff

File env_reset.3.osimons.diff, 6.0 KB (added by osimons <simon-code@…>, 16 months ago)

Another attempt at solving environment reload - a combination of earlier patches that also solves logging.

  • trac/env.py

     
    329329                     .replace('%(path)s', self.path) \ 
    330330                     .replace('%(basename)s', os.path.basename(self.path)) \ 
    331331                     .replace('%(project)s', self.project_name) 
    332         self.log = logger_factory(logtype, logfile, self.log_level, self.path, 
    333                                   format=format) 
     332        self.log, self._log_hdlr = logger_factory(logtype, logfile, 
     333                            self.log_level, self.path, format=format) 
    334334 
    335335    def get_known_users(self, cnx=None): 
    336336        """Generator that yields information about all known users, i.e. users 
     
    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 is dirty - shut it down and remove from cache 
     521                env.shutdown() 
     522                env.log.removeHandler(env._log_hdlr) 
     523                env_cache.pop(env_path) 
     524                env = None 
    519525            if env is None: 
    520526                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() 
    525527        finally: 
    526528            env_cache_lock.release() 
    527529    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

     
    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) 
     
    6060    hdlr.setFormatter(formatter) 
    6161    logger.addHandler(hdlr)  
    6262 
    63     return logger 
     63    return logger, hdlr 
  • 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: