LEFT | RIGHT |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 # | 2 # |
3 # Copyright (C) 2005-2009 Edgewall Software | 3 # Copyright (C) 2005-2009 Edgewall Software |
4 # Copyright (C) 2005-2006 Christopher Lenz <cmlenz@gmx.de> | 4 # Copyright (C) 2005-2006 Christopher Lenz <cmlenz@gmx.de> |
5 # All rights reserved. | 5 # All rights reserved. |
6 # | 6 # |
7 # This software is licensed as described in the file COPYING, which | 7 # This software is licensed as described in the file COPYING, which |
8 # you should have received as part of this distribution. The terms | 8 # you should have received as part of this distribution. The terms |
9 # are also available at http://trac.edgewall.org/wiki/TracLicense. | 9 # are also available at http://trac.edgewall.org/wiki/TracLicense. |
10 # | 10 # |
11 # This software consists of voluntary contributions made by many | 11 # This software consists of voluntary contributions made by many |
12 # individuals. For the exact contribution history, see the revision | 12 # individuals. For the exact contribution history, see the revision |
13 # history and logs, available at http://trac.edgewall.org/log/. | 13 # history and logs, available at http://trac.edgewall.org/log/. |
14 # | 14 # |
15 # Author: Christopher Lenz <cmlenz@gmx.de> | 15 # Author: Christopher Lenz <cmlenz@gmx.de> |
16 | 16 |
17 from glob import glob | 17 from glob import glob |
18 import imp | 18 import imp |
19 import pkg_resources | 19 import pkg_resources |
20 from pkg_resources import working_set, DistributionNotFound, VersionConflict, \ | 20 from pkg_resources import working_set, DistributionNotFound, VersionConflict, \ |
21 UnknownExtra | 21 UnknownExtra |
22 import os | 22 import os |
23 import sys | 23 import sys |
24 | 24 |
25 import trac.util.autoreload | 25 from trac.util.autoreload import _AUTORELOAD_EXTRA_FILES |
26 from trac.util.compat import set | 26 from trac.util.compat import set |
27 from trac.util.text import exception_to_unicode | 27 from trac.util.text import exception_to_unicode |
28 | 28 |
29 __all__ = ['load_components'] | 29 __all__ = ['load_components'] |
30 | 30 |
31 def _enable_plugin(env, module): | 31 def _enable_plugin(env, module): |
32 """Enable the given plugin module by adding an entry to the configuration. | 32 """Enable the given plugin module by adding an entry to the configuration. |
33 """ | 33 """ |
34 if module + '.*' not in env.config['components']: | 34 if module + '.*' not in env.config['components']: |
35 env.config['components'].set(module + '.*', 'enabled') | 35 env.config['components'].set(module + '.*', 'enabled') |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 if plugin_name not in sys.modules: | 91 if plugin_name not in sys.modules: |
92 module = imp.load_source(plugin_name, plugin_file) | 92 module = imp.load_source(plugin_name, plugin_file) |
93 if path == auto_enable: | 93 if path == auto_enable: |
94 _enable_plugin(env, plugin_name) | 94 _enable_plugin(env, plugin_name) |
95 except Exception, e: | 95 except Exception, e: |
96 env.log.error('Failed to load plugin from %s: %s', | 96 env.log.error('Failed to load plugin from %s: %s', |
97 plugin_file, | 97 plugin_file, |
98 exception_to_unicode(e, traceback=True)) | 98 exception_to_unicode(e, traceback=True)) |
99 # add failed plugin to the list of monitored files | 99 # add failed plugin to the list of monitored files |
100 # in autoreload mode for development | 100 # in autoreload mode for development |
101 trac.util.autoreload._AUTORELOAD_EXTRA_FILES\ | 101 if plugin_file not in _AUTORELOAD_EXTRA_FILES: |
102 .append(plugin_file) | 102 _AUTORELOAD_EXTRA_FILES.append(plugin_file) |
103 | 103 |
104 return _load_py_files | 104 return _load_py_files |
105 | 105 |
106 def load_components(env, extra_path=None, loaders=(load_eggs('trac.plugins'), | 106 def load_components(env, extra_path=None, loaders=(load_eggs('trac.plugins'), |
107 load_py_files())): | 107 load_py_files())): |
108 """Load all plugin components found on the given search path.""" | 108 """Load all plugin components found on the given search path.""" |
109 plugins_dir = os.path.normcase(os.path.realpath( | 109 plugins_dir = os.path.normcase(os.path.realpath( |
110 os.path.join(env.path, 'plugins') | 110 os.path.join(env.path, 'plugins') |
111 )) | 111 )) |
112 search_path = [plugins_dir] | 112 search_path = [plugins_dir] |
113 if extra_path: | 113 if extra_path: |
114 search_path += list(extra_path) | 114 search_path += list(extra_path) |
115 | 115 |
116 for loadfunc in loaders: | 116 for loadfunc in loaders: |
117 loadfunc(env, search_path, auto_enable=plugins_dir) | 117 loadfunc(env, search_path, auto_enable=plugins_dir) |
LEFT | RIGHT |