4 from django.conf import settings
6 def get_modules_folder():
7 return get_modules_folder.value
9 def get_modules_script(script_name):
12 for m in settings.MODULE_LIST:
13 if hasattr(m, script_name):
14 all.append(getattr(m, script_name))
18 all.append(__import__('%s.%s' % (m.__name__, script_name), globals(), locals(), [m.__name__]))
20 if isinstance(e, ImportError) and str(e).endswith(script_name):
22 logging.exception("Error importing %s from module %s", script_name, m)
26 def get_modules_script_implementations(script_name, impl_class):
27 scripts = get_modules_script(script_name)
30 for script in scripts:
31 all_impls.update(dict([
32 (n, i) for (n, i) in [(n, getattr(script, n)) for n in dir(script)]
33 if isinstance(i, impl_class)
38 def get_modules_script_classes(script_name, base_class):
39 scripts = get_modules_script(script_name)
42 for script in scripts:
43 all_classes.update(dict([
44 (n, c) for (n, c) in [(n, getattr(script, n)) for n in dir(script)]
45 if isinstance(c, (type, types.ClassType)) and issubclass(c, base_class)
50 def get_all_handlers(name):
51 handler_files = get_modules_script('handlers')
55 getattr(f, name) for f in handler_files
62 def call_all_handlers(name, *args, **kwargs):
63 all = get_all_handlers(name)
68 ret.append(handler(*args, **kwargs))
72 def get_handler(name, default):
73 all = get_all_handlers(name)
74 return len(all) and all[0] or default
76 from decorators import decorate, ReturnImediatelyException