Edgewall Software

Ticket #2498: patch-2498.diff

File patch-2498.diff, 4.0 KB (added by Manuzhai, 6 years ago)

Attempt at a fix.

  • trac/env.py

     
    3636 
    3737    def environment_needs_upgrade(db): 
    3838        """Called when Trac checks whether the environment needs to be upgraded. 
    39          
     39 
    4040        Should return `True` if this participant needs an upgrade to be 
    4141        performed, `False` otherwise. 
    4242        """ 
    4343 
    4444    def upgrade_environment(db): 
    4545        """Actually perform an environment upgrade. 
    46          
     46 
    4747        Implementations of this method should not commit any database 
    4848        transactions. This is done implicitly after all participants have 
    4949        performed the upgrades they need without an error being raised. 
     
    5959     * an SQLite database (stores tickets, wiki pages...) 
    6060     * Project specific templates and wiki macros. 
    6161     * wiki and ticket attachments. 
    62     """    
     62    """ 
    6363    setup_participants = ExtensionPoint(IEnvironmentSetupParticipant) 
    6464 
    6565    def __init__(self, path, create=False, options=[]): 
    6666        """Initialize the Trac environment. 
    67          
     67 
    6868        @param path:   the absolute path to the Trac environment 
    6969        @param create: if `True`, the environment is created and populated with 
    7070                       default data; otherwise, the environment is expected to 
     
    7676 
    7777        self.path = path 
    7878        self.load_config() 
    79         self.setup_log()  
    8079 
    81         from trac.loader import load_components 
    82         load_components(self) 
    83  
    8480        if create: 
     81            self.setup_log(True) 
    8582            self.create(options) 
    8683        else: 
     84            self.setup_log() 
    8785            self.verify() 
    8886 
     87        from trac.loader import load_components 
     88        load_components(self) 
     89 
    8990        if create: 
    9091            for setup_participant in self.setup_participants: 
    9192                setup_participant.environment_created() 
    9293 
    9394    def component_activated(self, component): 
    9495        """Initialize additional member variables for components. 
    95          
     96 
    9697        Every component activated through the `Environment` object gets three 
    9798        member variables: `env` (the environment object), `config` (the 
    9899        environment configuration) and `log` (a logger object).""" 
     
    103104    def is_component_enabled(self, cls): 
    104105        """Implemented to only allow activation of components that are not 
    105106        disabled in the configuration. 
    106          
     107 
    107108        This is called by the `ComponentManager` base class when a component is 
    108109        about to be activated. If this method returns false, the component does 
    109110        not get activated.""" 
     
    146147    def get_repository(self, authname=None): 
    147148        """Return the version control repository configured for this 
    148149        environment. 
    149          
     150 
    150151        @param authname: user name for authorization 
    151152        """ 
    152153        repos_type = self.config.get('trac', 'repository_type') 
     
    218219        """Return absolute path to the log directory.""" 
    219220        return os.path.join(self.path, 'log') 
    220221 
    221     def setup_log(self): 
     222    def setup_log(self, create=False): 
    222223        """Initialize the logging sub-system.""" 
    223224        from trac.log import logger_factory 
    224225        logtype = self.config.get('logging', 'log_type') 
     
    227228        if not os.path.isabs(logfile): 
    228229            logfile = os.path.join(self.get_log_dir(), logfile) 
    229230        logid = self.path # Env-path provides process-unique ID 
    230         self.log = logger_factory(logtype, logfile, loglevel, logid) 
     231        if create: 
     232            self.log = logger_factory('syslog', logfile, loglevel, logid) 
     233        else: 
     234            self.log = logger_factory(logtype, logfile, loglevel, logid) 
    231235 
    232236    def get_known_users(self, cnx=None): 
    233237        """Generator that yields information about all known users, i.e. users 
     
    281285 
    282286    def upgrade(self, backup=False, backup_dest=None): 
    283287        """Upgrade database. 
    284          
     288 
    285289        Each db version should have its own upgrade module, names 
    286290        upgrades/dbN.py, where 'N' is the version number (int). 
    287291