5 from forum.utils.mixed import Proxy
7 MODULES_PACKAGE = 'forum_modules'
12 def init_modules_engine(site_src_root, disabled_modules):
13 modules_folder = os.path.join(site_src_root, MODULES_PACKAGE)
15 MODULE_LIST.extend(filter(lambda m: getattr(m, 'CAN_USE', True), [
16 __import__('forum_modules.%s' % f, globals(), locals(), ['forum_modules'])
17 for f in os.listdir(modules_folder)
18 if os.path.isdir(os.path.join(modules_folder, f)) and
19 os.path.exists(os.path.join(modules_folder, "%s/__init__.py" % f)) and
20 not f in disabled_modules
23 get_modules_folder.value = modules_folder
25 def get_modules_folder():
26 return get_modules_folder.value
28 def get_modules_script(script_name):
32 if hasattr(m, script_name):
33 all.append(getattr(m, script_name))
37 all.append(__import__('%s.%s' % (m.__name__, script_name), globals(), locals(), [m.__name__]))
38 except ImportError, e:
39 #print repr(type(e)) + m.__name__ + ":" + str(e)
43 msg = "Error importing %s from module %s: \n %s" % (
44 script_name, m, traceback.format_exc()
50 def get_modules_script_implementations(script_name, impl_class):
51 scripts = get_modules_script(script_name)
54 for script in scripts:
55 all_impls.update(dict([
56 (n, i) for (n, i) in [(n, getattr(script, n)) for n in dir(script)]
57 if isinstance(i, impl_class)
62 def get_modules_script_classes(script_name, base_class):
63 scripts = get_modules_script(script_name)
66 for script in scripts:
67 all_classes.update(dict([
68 (n, c) for (n, c) in [(n, getattr(script, n)) for n in dir(script)]
69 if isinstance(c, (type, types.ClassType)) and issubclass(c, base_class)
74 def get_all_handlers(name):
75 handler_files = get_modules_script('handlers')
79 getattr(f, name) for f in handler_files
86 def call_all_handlers(name, *args, **kwargs):
87 all = get_all_handlers(name)
92 ret.append(handler(*args, **kwargs))
96 def get_handler(name, default):
97 all = get_all_handlers(name)
98 return len(all) and all[0] or default
100 from decorators import decorate, ReturnImediatelyException