11 def load(modules_path
):
12 """Load all commands modules from modules_path direcotory.
14 Returns a dictionary :
16 "class_name" : class_instance,
21 # adding plugins path to sys.path
22 if modules_path
not in sys
.path
:
23 sys
.path
.append(modules_path
)
24 # importing all modules from modules_path
25 for module_name
in os
.listdir(modules_path
):
26 module_path
= os
.path
.abspath(
27 string
.join(modules_path
, module_name
))
28 (module_name
, module_extension
) = os
.path
.splitext(module_name
)
29 # if it shouldn't be load
30 if os
.path
.islink(module_path
) or \
31 module_path
== __file__
or \
32 module_extension
!= ".py":
34 for key
in sys
.modules
.keys():
35 if key
== module_name
:
37 module
= __import__(module_name
)
38 command_modules
.append({"obj": module_name
, "name": module
,})
39 # search for class in each module
41 for module
in command_modules
:
42 for obj
in dir(module
["name"]):
44 # better class serch 2008-01-27 16:56:42
45 if not obj
.startswith("_") and \
46 type(getattr(module
['name'], obj
)) == types
.TypeType
:
47 # create instance for each class
49 getattr(module
['name'], obj
)()