Changeset 2335
- Timestamp:
- 10/08/2005 11:13:05 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 4 modified
-
scripts/trac-postinstall.py (modified) (3 diffs)
-
setup.py (modified) (3 diffs)
-
trac/config.py (modified) (6 diffs)
-
trac/env.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/trac-postinstall.py
r1745 r2335 14 14 prefix = sysconfig.get_config_var('prefix') 15 15 16 conf_dir = os.path.join(prefix, 'share', 'trac', 'conf') 16 17 templates_dir = os.path.join(prefix, 'share', 'trac', 'templates') 17 18 htdocs_dir = os.path.join(prefix, 'share', 'trac', 'htdocs') … … 25 26 # This file was autogenerated when installing Trac %(version)s. 26 27 # 28 __default_conf_dir__ = %(conf)r 27 29 __default_templates_dir__ = %(templates)r 28 30 __default_htdocs_dir__ = %(htdocs)r … … 30 32 __default_macros_dir__ = %(macros)r 31 33 32 """ % {'version': trac.__version__, 'templates': templates_dir, 33 'htdocs': htdocs_dir, 'wiki': wiki_dir, 'macros': macros_dir}) 34 """ % {'version': trac.__version__, 'conf': conf_dir, 35 'templates': templates_dir, 'htdocs': htdocs_dir, 36 'wiki': wiki_dir, 'macros': macros_dir}) 34 37 fd.close() 35 38 -
trunk/setup.py
r2244 r2335 32 32 33 33 def siteconfig(self): 34 conf_dir = os.path.join(self.prefix, 'share', 'trac', 'conf') 34 35 templates_dir = os.path.join(self.prefix, 'share', 'trac', 'templates') 35 36 htdocs_dir = os.path.join(self.prefix, 'share', 'trac', 'htdocs') 36 37 wiki_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-default') 37 38 macros_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-macros') 38 f = open(_p('trac/siteconfig.py'), 'w')39 f = open(_p('trac/siteconfig.py'), 'w') 39 40 f.write(""" 40 41 # PLEASE DO NOT EDIT THIS FILE! 41 42 # This file was autogenerated when installing %(trac)s %(ver)s. 42 43 # 44 __default_conf_dir__ = %(conf)r 43 45 __default_templates_dir__ = %(templates)r 44 46 __default_htdocs_dir__ = %(htdocs)r … … 46 48 __default_macros_dir__ = %(macros)r 47 49 48 """ % {'trac':PACKAGE, 'ver':VERSION, 'templates':_p(templates_dir), 49 'htdocs':_p(htdocs_dir), 'wiki':_p(wiki_dir), 'macros':_p(macros_dir)}) 50 """ % {'trac': PACKAGE, 'ver': VERSION, 'conf': _p(conf_dir), 51 'templates': _p(templates_dir), 'htdocs': _p(htdocs_dir), 52 'wiki': _p(wiki_dir), 'macros': _p(macros_dir)}) 50 53 f.close() 51 54 … … 132 135 mode |= 044 133 136 os.chmod(path, mode) 134 135 137 136 138 # Our custom bdist_wininst -
trunk/trac/config.py
r2127 r2335 18 18 19 19 from ConfigParser import ConfigParser 20 import os.path 20 import os 21 import sys 21 22 22 23 23 24 class Configuration: 24 """ 25 Thin layer over ConfigParser from the Python standard library. 25 """Thin layer over `ConfigParser` from the Python standard library. 26 26 27 In addition to providing some convenience methods, the class remembers 27 28 the last modification time of the configuration file, and reparses it … … 30 31 31 32 def __init__(self, filename): 33 self._defaults = {} 32 34 self.filename = filename 33 35 self.parser = ConfigParser() 34 self.__defaults = {} 35 self.__lastmtime = 0 36 self._lastmtime = 0 37 self.site_filename = os.path.join(default_dir('conf'), 'trac.ini') 38 self.site_parser = ConfigParser() 39 self._lastsitemtime = 0 36 40 self.parse_if_needed() 37 41 … … 39 43 if not self.parser.has_option(section, name): 40 44 if default is None: 41 return self._ _defaults.get((section, name), '')45 return self._defaults.get((section, name), '') 42 46 return default 43 47 return self.parser.get(section, name) 44 48 45 49 def setdefault(self, section, name, value): 46 self.__defaults[(section, name)] = value 50 if (section, name) not in self._defaults: 51 self._defaults[(section, name)] = value 47 52 48 53 def set(self, section, name, value): 49 """ 50 Changes a config value, these changes are _not_ persistent unless saved51 with `save()`.54 """Change a configuration value. 55 56 These changes are not persistent unless saved with `save()`. 52 57 """ 53 58 if not self.parser.has_section(section): … … 56 61 57 62 def options(self, section): 58 if not self.parser.has_section(section): 59 return [] 60 try: 61 return self.parser.items(section) 62 except AttributeError: 63 options = [] 63 options = [] 64 if self.parser.has_section(section): 64 65 for option in self.parser.options(section): 65 66 options.append((option, self.parser.get(section, option))) 66 return options 67 for option, value in self._defaults.iteritems(): 68 if option[0] == section: 69 if not [exists for exists in options if exists[0] == option[1]]: 70 options.append((option[1], value)) 71 return options 67 72 68 73 def __contains__(self, name): … … 79 84 if not self.filename: 80 85 return 81 self.parser.write(open(self.filename, 'w')) 86 fileobj = file(self.filename, 'w') 87 try: 88 self.parser.write(fileobj) 89 finally: 90 fileobj.close() 82 91 83 92 def parse_if_needed(self): 93 # Merge global configuration option into _defaults 94 if os.path.isfile(self.site_filename): 95 modtime = os.path.getmtime(self.site_filename) 96 if modtime > self._lastsitemtime: 97 self.site_parser.read(self.site_filename) 98 for section in self.site_parser.sections(): 99 for option in self.site_parser.options(section): 100 value = self.site_parser.get(section, option) 101 self._defaults[(section, option)] = value 102 self._lastsitemtime = modtime 103 84 104 if not self.filename: 85 105 return 86 106 modtime = os.path.getmtime(self.filename) 87 if modtime > self._ _lastmtime:88 self.parser.read fp(open(self.filename))89 self._ _lastmtime = modtime107 if modtime > self._lastmtime: 108 self.parser.read(self.filename) 109 self._lastmtime = modtime 90 110 91 111 … … 97 117 # This is not a regular install with a generated siteconfig.py file, 98 118 # so try to figure out the directory based on common setups 99 import os.path, sys100 119 special_dirs = {'wiki': 'wiki-default', 'macros': 'wiki-macros'} 101 120 dirname = special_dirs.get(name, name) -
trunk/trac/env.py
r2260 r2335 17 17 from __future__ import generators 18 18 19 import os 20 19 21 from trac import db, db_default, util 20 22 from trac.config import Configuration … … 22 24 ExtensionPoint, TracError 23 25 24 import os25 import os.path26 27 26 __all__ = ['Environment', 'IEnvironmentSetupParticipant', 'open_environment'] 28 27 … … 37 36 38 37 def environment_needs_upgrade(db): 39 """FIXME""" 38 """Called when Trac checks whether the environment needs to be upgraded. 39 40 Should return `True` if this participant needs an upgrade to be 41 performed, `False` otherwise. 42 """ 40 43 41 44 def upgrade_environment(db): 42 """FIXME""" 45 """Actually perform an environment upgrade. 46 47 Implementations of this method should not commit any database 48 transactions. This is done implicitly after all participants have 49 performed the upgrades they need without an error being raised. 50 """ 43 51 44 52 … … 99 107 about to be activated. If this method returns false, the component does 100 108 not get activated.""" 101 component_name = (cls.__module__ + '.' + cls.__name__).lower() 102 for name,value in self.config.options('disabled_components'): 103 if value in util.TRUE and component_name.startswith(name): 104 return False 105 return True 109 if not isinstance(cls, (str, unicode)): 110 component_name = (cls.__module__ + '.' + cls.__name__).lower() 111 else: 112 component_name = cls 113 114 rules = [(name.lower(), value.lower() in ('enabled', 'on')) 115 for name, value in self.config.options('components')] 116 rules.sort(lambda a, b: -cmp(len(a[0]), len(b[0]))) 117 118 for pattern, enabled in rules: 119 if component_name == pattern or pattern.endswith('*') \ 120 and component_name.startswith(pattern[:-1]): 121 return enabled 122 123 # By default, all components in the trac package are enabled 124 return component_name.startswith('trac.') 106 125 107 126 def verify(self): … … 170 189 _create_file(os.path.join(self.path, 'conf', 'trac.ini')) 171 190 self.load_config() 172 for section, name,value in db_default.default_config:191 for section, name, value in db_default.default_config: 173 192 self.config.set(section, name, value) 174 193 self.config.set('trac', 'database', db_str) … … 190 209 """Load the configuration file.""" 191 210 self.config = Configuration(os.path.join(self.path, 'conf', 'trac.ini')) 192 for section, name,value in db_default.default_config:211 for section, name, value in db_default.default_config: 193 212 self.config.setdefault(section, name, value) 194 213
