Edgewall Software

Ticket #9416: 9416-environment-creation-r9848.patch

File 9416-environment-creation-r9848.patch, 5.3 KB (added by rblank, 2 years ago)

Refactored environment creation.

  • trac/admin/tests/console.py

    diff --git a/trac/admin/tests/console.py b/trac/admin/tests/console.py
    a b  
    7070            self._db = InMemoryDatabase() 
    7171        return self._db 
    7272 
    73     def create(self, db_str=None): 
    74         pass 
     73    def create(self, options=[]): 
     74        self.setup_config() 
    7575 
    7676    def verify(self): 
    7777        return True 
     
    8484        return cls.__module__.startswith('trac.') and \ 
    8585               cls.__module__.find('.tests.') == -1 
    8686 
    87     def setup_config(self, load_defaults=None): 
     87    def setup_config(self): 
    8888        self.config = InMemoryConfiguration(None) 
     89        self.setup_log() 
    8990 
    9091 
    9192class TracadminTestCase(unittest.TestCase): 
  • trac/config.py

    diff --git a/trac/config.py b/trac/config.py
    a b  
    286286           and os.access(self.filename, os.W_OK): 
    287287            os.utime(self.filename, None) 
    288288 
     289    def set_defaults(self, compmgr=None): 
     290        """Retrieve all default values and store them explicitly in the 
     291        configuration, so that they can be saved to file. 
     292         
     293        Values already set in the configuration are not overridden. 
     294        """ 
     295        for section, default_options in self.defaults(compmgr).items(): 
     296            for name, value in default_options.items(): 
     297                if not self.parser.has_option(_to_utf8(section), 
     298                                              _to_utf8(name)): 
     299                    if any(parent[section].contains(name, defaults=False) 
     300                           for parent in self.parents): 
     301                        value = None 
     302                    self.set(section, name, value) 
     303 
    289304 
    290305class Section(object): 
    291306    """Proxy for a specific configuration section. 
  • trac/env.py

    diff --git a/trac/env.py b/trac/env.py
    a b  
    204204        ComponentManager.__init__(self) 
    205205 
    206206        self.path = path 
    207         self.setup_config(load_defaults=create) 
    208         self.setup_log() 
    209  
    210207        self.systeminfo = [] 
    211         from trac import core, __version__ as VERSION 
    212         self.log.info('-' * 32 + ' environment startup [Trac %s] ' + '-' * 32, 
    213                       get_pkginfo(core).get('version', VERSION)) 
    214208        self._href = self._abs_href = None 
    215209 
    216         from trac.loader import load_components 
    217         plugins_dir = self.shared_plugins_dir 
    218         load_components(self, plugins_dir and (plugins_dir,)) 
    219  
    220210        if create: 
    221211            self.create(options) 
    222212        else: 
    223213            self.verify() 
     214            self.setup_config() 
    224215 
    225216        if create: 
    226217            for setup_participant in self.setup_participants: 
     
    393384 
    394385        # Setup the default configuration 
    395386        os.mkdir(os.path.join(self.path, 'conf')) 
    396         create_file(os.path.join(self.path, 'conf', 'trac.ini')) 
    397387        create_file(os.path.join(self.path, 'conf', 'trac.ini.sample')) 
    398         skip_defaults = any((section, option) == ('inherit', 'file') 
    399                             for section, option, value in options) 
    400         self.setup_config(load_defaults=not skip_defaults) 
     388        config = Configuration(os.path.join(self.path, 'conf', 'trac.ini')) 
    401389        for section, name, value in options: 
    402             self.config.set(section, name, value) 
    403         self.config.save() 
    404         # Full reload to get 'inherit' working 
    405         self.config.parse_if_needed(force=True) 
    406         del self._rules 
     390            config.set(section, name, value) 
     391        config.save() 
     392        self.setup_config() 
     393        if not any((section, option) == ('inherit', 'file') 
     394                   for section, option, value in options): 
     395            self.config.set_defaults(self) 
     396            self.config.save() 
    407397 
    408398        # Create the database 
    409399        DatabaseManager(self).init_db() 
     
    427417        row = cursor.fetchone() 
    428418        return row and int(row[0]) 
    429419 
    430     def setup_config(self, load_defaults=False): 
     420    def setup_config(self): 
    431421        """Load the configuration file.""" 
    432422        self.config = Configuration(os.path.join(self.path, 'conf', 
    433423                                                 'trac.ini')) 
    434         if load_defaults: 
    435             for section, default_options in self.config.defaults(self).items(): 
    436                 for name, value in default_options.items(): 
    437                     if any(parent[section].contains(name, defaults=False) 
    438                            for parent in self.config.parents): 
    439                         value = None 
    440                     self.config.set(section, name, value) 
     424        self.setup_log() 
     425        from trac.loader import load_components 
     426        plugins_dir = self.shared_plugins_dir 
     427        load_components(self, plugins_dir and (plugins_dir,)) 
    441428 
    442429    def get_templates_dir(self): 
    443430        """Return absolute path to the templates directory.""" 
     
    466453                     .replace('%(project)s', self.project_name) 
    467454        self.log, self._log_handler = logger_handler_factory( 
    468455            logtype, logfile, self.log_level, self.path, format=format) 
     456        from trac import core, __version__ as VERSION 
     457        self.log.info('-' * 32 + ' environment startup [Trac %s] ' + '-' * 32, 
     458                      get_pkginfo(core).get('version', VERSION)) 
    469459 
    470460    def get_known_users(self, cnx=None): 
    471461        """Generator that yields information about all known users, i.e. users