equal
deleted
inserted
replaced
|
1 import imp |
|
2 import sys |
|
3 import os |
|
4 |
|
5 |
|
6 class ActionsLoader: |
|
7 def __init__(self): |
|
8 self._actions = {} |
|
9 def keys(self): |
|
10 return self._actions.keys() |
|
11 def _getmodule(self, name): |
|
12 modpath = os.path.join(os.path.dirname(__file__), 'actions') |
|
13 fp, pathname, description = imp.find_module(name, [modpath]) |
|
14 try: |
|
15 return imp.load_module(name, fp, pathname, description) |
|
16 finally: |
|
17 if fp: |
|
18 fp.close() |
|
19 def __getitem__(self, item): |
|
20 mname, fname = self._actions[item] |
|
21 return self._getmodule(mname).__dict__[fname] |
|
22 def __setitem__(self, key, value): |
|
23 self._actions[key] = value |
|
24 |
|
25 |
|
26 actions = ActionsLoader() |
|
27 actions['default'] = ('index', 'do_it') |
|
28 actions['index'] = ('index', 'do_it') |
|
29 actions['edit'] = ('edit', 'do_it') |
|
30 actions['import'] = ('imp_xbel', 'do_it') |
|
31 actions['add'] = ('add', 'do_it') |
|
32 actions['confirm'] = ('add', 'do_it') |