svn-gvsig-desktop / branches / v2_0_0_prep / build / buildman / bin / bmplugins / __init__.py @ 27363
History | View | Annotate | Download (1.07 KB)
1 |
"""
|
---|---|
2 |
Path where plugins reside
|
3 |
Each plugin should implement IPlugIn interface
|
4 |
from bmbase.
|
5 |
"""
|
6 |
|
7 |
|
8 |
|
9 |
import os |
10 |
import sys |
11 |
from bmcore.BMUtil import BMUtil |
12 |
import imp |
13 |
|
14 |
def bmimport(name, paths): |
15 |
# Fast path: see if the module has already been imported.
|
16 |
try:
|
17 |
return sys.modules[name]
|
18 |
except KeyError: |
19 |
pass
|
20 |
|
21 |
# If any of the following calls raises an exception,
|
22 |
# there's a problem we can't handle -- let the caller handle it.
|
23 |
|
24 |
fp, pathname, description = imp.find_module(name,paths) |
25 |
|
26 |
try:
|
27 |
return imp.load_module(name, fp, pathname, description)
|
28 |
finally:
|
29 |
# Since we may exit via an exception, close fp explicitly.
|
30 |
if fp:
|
31 |
fp.close() |
32 |
|
33 |
util = BMUtil() |
34 |
searchPaths=[os.path.join(sys.path[0],'bmplugins'),util.buildmanPlugInPath(),os.path.join(sys.path[0],'../bmplugins')] |
35 |
|
36 |
plugList = [] |
37 |
for dir in searchPaths: |
38 |
if not os.path.exists(dir): |
39 |
continue
|
40 |
for f in os.listdir(dir): |
41 |
if f.endswith('.py') and not f.startswith('__init__'): |
42 |
plugList.append(f[0:-3]) |
43 |
|
44 |
print plugList
|
45 |
for m in plugList: |
46 |
bmimport(m,searchPaths) |
47 |
|