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__]))
19 except ImportError, e:
20 #print repr(type(e)) + m.__name__ + ":" + str(e)
24 msg = "Error importing %s from module %s: \n %s" % (
25 script_name, m, traceback.format_exc()
31 def get_modules_script_implementations(script_name, impl_class):
32 scripts = get_modules_script(script_name)
35 for script in scripts:
36 all_impls.update(dict([
37 (n, i) for (n, i) in [(n, getattr(script, n)) for n in dir(script)]
38 if isinstance(i, impl_class)
43 def get_modules_script_classes(script_name, base_class):
44 scripts = get_modules_script(script_name)
47 for script in scripts:
48 all_classes.update(dict([
49 (n, c) for (n, c) in [(n, getattr(script, n)) for n in dir(script)]
50 if isinstance(c, (type, types.ClassType)) and issubclass(c, base_class)
55 def get_all_handlers(name):
56 handler_files = get_modules_script('handlers')
60 getattr(f, name) for f in handler_files
67 def call_all_handlers(name, *args, **kwargs):
68 all = get_all_handlers(name)
73 ret.append(handler(*args, **kwargs))
77 def get_handler(name, default):
78 all = get_all_handlers(name)
79 return len(all) and all[0] or default
81 from decorators import decorate, ReturnImediatelyException