Edgewall Software

Ticket #3620: comment_out_globally_set_options-r3717.diff

File comment_out_globally_set_options-r3717.diff, 2.5 KB (added by cboos, 6 years ago)

Possible fix for the issue: special case the None value to be an indicator of a globally set configuration option.

  • trac/env.py

     
    242242        if load_defaults: 
    243243            for section, default_options in self.config.defaults().iteritems(): 
    244244                for name, value in default_options.iteritems(): 
     245                    if self.config.has_site_option(section, name): 
     246                        value = None 
    245247                    self.config.set(section, name, value) 
    246248 
    247249    def get_templates_dir(self): 
  • trac/config.py

     
    162162            for section, options in sections: 
    163163                print>>fileobj, '[%s]' % section 
    164164                for key, val in options: 
    165                     print>>fileobj, '%s = %s' % \ 
    166                                     (key, to_unicode(val).encode('utf-8')) 
     165                    if key in self[section].overriden: 
     166                        print>>fileobj, '# %s = <set in global trac.ini>' % key 
     167                    else: 
     168                        print>>fileobj, '%s = %s' % \ 
     169                                        (key, to_unicode(val).encode('utf-8')) 
    167170                print>>fileobj 
    168171        finally: 
    169172            fileobj.close() 
     
    183186            self.parser.read(self.filename) 
    184187            self._lastmtime = modtime 
    185188 
     189    def has_site_option(self, section, name): 
     190        return self.site_parser.has_option(section, name) 
    186191 
     192 
    187193class Section(object): 
    188194    """Proxy for a specific configuration section. 
    189195     
    190196    Objects of this class should not be instantiated directly. 
    191197    """ 
    192     __slots__ = ['config', 'name'] 
     198    __slots__ = ['config', 'name', 'overriden'] 
    193199 
    194200    def __init__(self, config, name): 
    195201        self.config = config 
    196202        self.name = name 
     203        self.overriden = {} 
    197204 
    198205    def __contains__(self, name): 
    199206        return self.config.parser.has_option(self.name, name) or \ 
     
    283290        """ 
    284291        if not self.config.parser.has_section(self.name): 
    285292            self.config.parser.add_section(self.name) 
    286         return self.config.parser.set(self.name, name, 
    287                                       to_unicode(value).encode('utf-8')) 
     293        if value is None: 
     294            self.overriden[name] = True 
     295            value = '' 
     296        else: 
     297            value = to_unicode(value).encode('utf-8') 
     298        return self.config.parser.set(self.name, name, value) 
    288299 
    289300 
    290301class Option(object):