Ticket #2498: patch-2498.diff
| File patch-2498.diff, 4.0 KB (added by Manuzhai, 6 years ago) |
|---|
-
trac/env.py
36 36 37 37 def environment_needs_upgrade(db): 38 38 """Called when Trac checks whether the environment needs to be upgraded. 39 39 40 40 Should return `True` if this participant needs an upgrade to be 41 41 performed, `False` otherwise. 42 42 """ 43 43 44 44 def upgrade_environment(db): 45 45 """Actually perform an environment upgrade. 46 46 47 47 Implementations of this method should not commit any database 48 48 transactions. This is done implicitly after all participants have 49 49 performed the upgrades they need without an error being raised. … … 59 59 * an SQLite database (stores tickets, wiki pages...) 60 60 * Project specific templates and wiki macros. 61 61 * wiki and ticket attachments. 62 """ 62 """ 63 63 setup_participants = ExtensionPoint(IEnvironmentSetupParticipant) 64 64 65 65 def __init__(self, path, create=False, options=[]): 66 66 """Initialize the Trac environment. 67 67 68 68 @param path: the absolute path to the Trac environment 69 69 @param create: if `True`, the environment is created and populated with 70 70 default data; otherwise, the environment is expected to … … 76 76 77 77 self.path = path 78 78 self.load_config() 79 self.setup_log()80 79 81 from trac.loader import load_components82 load_components(self)83 84 80 if create: 81 self.setup_log(True) 85 82 self.create(options) 86 83 else: 84 self.setup_log() 87 85 self.verify() 88 86 87 from trac.loader import load_components 88 load_components(self) 89 89 90 if create: 90 91 for setup_participant in self.setup_participants: 91 92 setup_participant.environment_created() 92 93 93 94 def component_activated(self, component): 94 95 """Initialize additional member variables for components. 95 96 96 97 Every component activated through the `Environment` object gets three 97 98 member variables: `env` (the environment object), `config` (the 98 99 environment configuration) and `log` (a logger object).""" … … 103 104 def is_component_enabled(self, cls): 104 105 """Implemented to only allow activation of components that are not 105 106 disabled in the configuration. 106 107 107 108 This is called by the `ComponentManager` base class when a component is 108 109 about to be activated. If this method returns false, the component does 109 110 not get activated.""" … … 146 147 def get_repository(self, authname=None): 147 148 """Return the version control repository configured for this 148 149 environment. 149 150 150 151 @param authname: user name for authorization 151 152 """ 152 153 repos_type = self.config.get('trac', 'repository_type') … … 218 219 """Return absolute path to the log directory.""" 219 220 return os.path.join(self.path, 'log') 220 221 221 def setup_log(self ):222 def setup_log(self, create=False): 222 223 """Initialize the logging sub-system.""" 223 224 from trac.log import logger_factory 224 225 logtype = self.config.get('logging', 'log_type') … … 227 228 if not os.path.isabs(logfile): 228 229 logfile = os.path.join(self.get_log_dir(), logfile) 229 230 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) 231 235 232 236 def get_known_users(self, cnx=None): 233 237 """Generator that yields information about all known users, i.e. users … … 281 285 282 286 def upgrade(self, backup=False, backup_dest=None): 283 287 """Upgrade database. 284 288 285 289 Each db version should have its own upgrade module, names 286 290 upgrades/dbN.py, where 'N' is the version number (int). 287 291
