1 # Copyright (C) 2005-2010 Aaron Bentley <abentley@panoramicfeedback.com>
2 # Gianluca Montecchi <gian@grys.it>
3 # Marien Zwart <marien.zwart@gmail.com>
4 # W. Trevor King <wking@drexel.edu>
6 # This file is part of Bugs Everywhere.
8 # Bugs Everywhere is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by the
10 # Free Software Foundation, either version 2 of the License, or (at your
11 # option) any later version.
13 # Bugs Everywhere is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Bugs Everywhere. If not, see <http://www.gnu.org/licenses/>.
22 Allow simple listing and loading of the various becommands and libbe
23 submodules (i.e. "plugins").
31 _PLUGIN_PATH = os.path.realpath(
34 os.path.dirname(__file__))))
35 if _PLUGIN_PATH not in sys.path:
36 sys.path.append(_PLUGIN_PATH)
38 def import_by_name(modname):
40 >>> mod = import_by_name('libbe.bugdir')
41 >>> 'BugDir' in dir(mod)
43 >>> import_by_name('libbe.highly_unlikely')
44 Traceback (most recent call last):
46 ImportError: No module named highly_unlikely
48 module = __import__(modname)
49 components = modname.split('.')
50 for comp in components[1:]:
51 module = getattr(module, comp)
56 >>> 'list' in [n for n in modnames('libbe.command')]
58 >>> 'plugin' in [n for n in modnames('libbe.util')]
61 components = prefix.split('.')
62 modfiles = os.listdir(os.path.join(_PLUGIN_PATH, *components))
64 for modfile in modfiles:
65 if modfile.startswith('.'):
66 continue # the occasional emacs temporary file
67 if modfile.endswith('.py') and modfile != '__init__.py':