5 MODULES_PACKAGE = 'forum_modules'
11 def init_modules_engine(site_src_root, disabled_modules):
12 MODULES_FOLDER = os.path.join(site_src_root, MODULES_PACKAGE)
14 MODULE_LIST.extend(filter(lambda m: getattr(m, 'CAN_USE', True), [
15 __import__('forum_modules.%s' % f, globals(), locals(), ['forum_modules'])
16 for f in os.listdir(MODULES_FOLDER)
17 if os.path.isdir(os.path.join(MODULES_FOLDER, f)) and
18 os.path.exists(os.path.join(MODULES_FOLDER, "%s/__init__.py" % f)) and
19 not f in disabled_modules
22 def get_modules_script(script_name):
26 if hasattr(m, script_name):
27 all.append(getattr(m, script_name))
31 all.append(__import__('%s.%s' % (m.__name__, script_name), globals(), locals(), [m.__name__]))
32 except ImportError, e:
33 #print repr(type(e)) + m.__name__ + ":" + str(e)
37 msg = "Error importing %s from module %s: \n %s" % (
38 script_name, m, traceback.format_exc()
44 def get_modules_script_implementations(script_name, impl_class):
45 scripts = get_modules_script(script_name)
48 for script in scripts:
49 all_impls.update(dict([
50 (n, i) for (n, i) in [(n, getattr(script, n)) for n in dir(script)]
51 if isinstance(i, impl_class)
56 def get_modules_script_classes(script_name, base_class):
57 scripts = get_modules_script(script_name)
60 for script in scripts:
61 all_classes.update(dict([
62 (n, c) for (n, c) in [(n, getattr(script, n)) for n in dir(script)]
63 if isinstance(c, (type, types.ClassType)) and issubclass(c, base_class)
68 def get_all_handlers(name):
69 handler_files = get_modules_script('handlers')
73 getattr(f, name) for f in handler_files
80 def call_all_handlers(name, *args, **kwargs):
81 all = get_all_handlers(name)
86 ret.append(handler(*args, **kwargs))
90 def get_handler(name, default):
91 all = get_all_handlers(name)
92 return len(all) and all[0] or default
94 from decorators import decorate, ReturnImediatelyException