author | Fabien Ninoles <fabien@tzone.org> |
Tue, 30 Dec 2008 22:32:10 -0500 | |
changeset 65 | b975a3d7606a |
parent 60 | dad9733c99f0 |
child 73 | c078d8a04d76 |
permissions | -rw-r--r-- |
57 | 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') |
|
58
004a32370ba5
Correct some bugs and make keywords edition with the new action
fabien@tzone.org
parents:
57
diff
changeset
|
32 |
actions['keywords'] = ('editkw', 'do_it') |
60
dad9733c99f0
Convert the prefs editor to the action library.
fabien@tzone.org
parents:
58
diff
changeset
|
33 |
actions['prefs'] = ('edit_prefs', 'do_it') |