Ticket #2638: sitewide-plugins.diff
| File sitewide-plugins.diff, 4.6 KB (added by athomas, 3 years ago) |
|---|
-
setup.py
36 36 htdocs_dir = os.path.join(self.prefix, 'share', 'trac', 'htdocs') 37 37 wiki_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-default') 38 38 macros_dir = os.path.join(self.prefix, 'share', 'trac', 'wiki-macros') 39 plugins_dir = os.path.join(self.prefix, 'share', 'trac', 'plugins') 39 40 f = open(_p('trac/siteconfig.py'), 'w') 40 41 f.write(""" 41 42 # PLEASE DO NOT EDIT THIS FILE! … … 46 47 __default_htdocs_dir__ = %(htdocs)r 47 48 __default_wiki_dir__ = %(wiki)r 48 49 __default_macros_dir__ = %(macros)r 50 __default_plugins_dir__ = %(plugins)r 49 51 50 52 """ % {'trac': PACKAGE, 'ver': VERSION, 'conf': _p(conf_dir), 51 53 'templates': _p(templates_dir), 'htdocs': _p(htdocs_dir), 52 'wiki': _p(wiki_dir), 'macros': _p(macros_dir)}) 54 'wiki': _p(wiki_dir), 'macros': _p(macros_dir), 55 'plugins': _p(plugins_dir)}) 53 56 f.close() 54 57 55 58 # Run actual install -
trac/loader.py
18 18 import imp 19 19 import os 20 20 import sys 21 from trac.config import default_dir 21 22 try: 22 23 set 23 24 except NameError: … … 32 33 33 34 def load_components(env): 34 35 loaded_components = [] 35 plugins_dir = os.path.normcase(os.path.realpath(os.path.join(env.path, 36 'plugins'))) 36 plugins_dirs = [os.path.normcase(os.path.realpath(os.path.join(env.path, 37 'plugins'))), 38 default_dir('plugins')] 37 39 38 40 # First look for Python source files in the plugins directory, which simply 39 41 # get imported, thereby registering them with the component manager if they 40 42 # define any components 41 plugin_files = glob(os.path.join(plugins_dir, '*.py')) 42 for plugin_file in plugin_files: 43 try: 44 plugin_name = os.path.basename(plugin_file[:-3]) 45 if plugin_name not in loaded_components: 46 env.log.debug('Loading plugin %s from %s' % (plugin_name, 47 plugin_file)) 48 module = imp.load_source(plugin_name, plugin_file) 49 loaded_components.append(plugin_name) 50 env.config.setdefault('components', plugin_name + '.*', 51 'enabled') 52 except Exception, e: 53 env.log.error('Failed to load plugin from %s', plugin_file, 54 exc_info=True) 43 for plugins_dir in plugins_dirs: 44 plugin_files = glob(os.path.join(plugins_dir, '*.py')) 45 for plugin_file in plugin_files: 46 try: 47 plugin_name = os.path.basename(plugin_file[:-3]) 48 if plugin_name not in loaded_components: 49 env.log.debug('Loading plugin %s from %s' % (plugin_name, 50 plugin_file)) 51 module = imp.load_source(plugin_name, plugin_file) 52 loaded_components.append(plugin_name) 53 env.config.setdefault('components', plugin_name + '.*', 54 'enabled') 55 except Exception, e: 56 env.log.error('Failed to load plugin from %s', plugin_file, 57 exc_info=True) 55 58 56 59 # If setuptools is installed try to load any eggs from the plugins 57 60 # directory, and also plugins available on sys.path 58 61 if pkg_resources is not None: 59 62 ws = pkg_resources.working_set 60 ws.add_entry(plugins_dir) 61 pkg_env = pkg_resources.Environment([plugins_dir] + sys.path) 63 for plugins_dir in plugins_dirs: 64 ws.add_entry(plugins_dir) 65 pkg_env = pkg_resources.Environment(plugins_dirs + sys.path) 62 66 63 67 memo = set() 64 68 def flatten(dists): … … 113 117 114 118 if modules: 115 119 # Automatically enable any components provided by plugins 116 # loaded from the environment plugins directory.117 if os.path.dirname(egg.location) == plugins_dir:120 # loaded from the environment and site-wide plugins directory. 121 if os.path.dirname(egg.location) in plugins_dirs: 118 122 for module in modules: 119 123 env.config.setdefault('components', module + '.*', 120 124 'enabled')
