5 MODULES_PACKAGE = 'forum_modules'
10 def init_modules_engine(site_src_root, disabled_modules):
11 modules_folder = os.path.join(site_src_root, MODULES_PACKAGE)
13 MODULE_LIST.extend(filter(lambda m: getattr(m, 'CAN_USE', True), [
14 __import__('forum_modules.%s' % f, globals(), locals(), ['forum_modules'])
15 for f in os.listdir(modules_folder)
16 if os.path.isdir(os.path.join(modules_folder, f)) and
17 os.path.exists(os.path.join(modules_folder, "%s/__init__.py" % f)) and
18 not f in disabled_modules
21 get_modules_folder.value = modules_folder
23 def get_modules_folder():
24 return get_modules_folder.value
26 def get_modules_script(script_name):
30 if hasattr(m, script_name):
31 all.append(getattr(m, script_name))
35 all.append(__import__('%s.%s' % (m.__name__, script_name), globals(), locals(), [m.__name__]))
36 except ImportError, e:
37 #print repr(type(e)) + m.__name__ + ":" + str(e)
41 msg = "Error importing %s from module %s: \n %s" % (
42 script_name, m, traceback.format_exc()
48 def get_modules_script_implementations(script_name, impl_class):
49 scripts = get_modules_script(script_name)
52 for script in scripts:
53 all_impls.update(dict([
54 (n, i) for (n, i) in [(n, getattr(script, n)) for n in dir(script)]
55 if isinstance(i, impl_class)
60 def get_modules_script_classes(script_name, base_class):
61 scripts = get_modules_script(script_name)
64 for script in scripts:
65 all_classes.update(dict([
66 (n, c) for (n, c) in [(n, getattr(script, n)) for n in dir(script)]
67 if isinstance(c, (type, types.ClassType)) and issubclass(c, base_class)
72 def get_all_handlers(name):
73 handler_files = get_modules_script('handlers')
77 getattr(f, name) for f in handler_files
84 def call_all_handlers(name, *args, **kwargs):
85 all = get_all_handlers(name)
90 ret.append(handler(*args, **kwargs))
94 def get_handler(name, default):
95 all = get_all_handlers(name)
96 return len(all) and all[0] or default
98 from decorators import decorate, ReturnImediatelyException