author | fabien@tzone.org |
Mon, 05 Jan 2009 18:11:38 -0500 | |
changeset 76 | 147eddb3826c |
parent 74 | 6784c4350b41 |
permissions | -rw-r--r-- |
57 | 1 |
import imp |
2 |
import sys |
|
3 |
import os |
|
4 |
||
5 |
||
76
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
6 |
class Action: |
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
7 |
def __init__(self, mname, fname): |
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
8 |
self.mname = mname |
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
9 |
self.fname = fname |
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
10 |
def _getmodule(self): |
57 | 11 |
modpath = os.path.join(os.path.dirname(__file__), 'actions') |
76
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
12 |
fp, pathname, description = imp.find_module(self.mname, [modpath]) |
57 | 13 |
try: |
76
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
14 |
return imp.load_module(self.mname, fp, pathname, description) |
57 | 15 |
finally: |
16 |
if fp: |
|
17 |
fp.close() |
|
76
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
18 |
def __call__(self, *args): |
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
19 |
apply(self._getmodule().__dict__[self.fname],args) |
57 | 20 |
|
76
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
21 |
actions = {} |
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
22 |
actions['index'] = Action('index', 'do_it') |
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
23 |
actions['import'] = Action('imp_xbel', 'do_it') |
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
24 |
actions['bookmark'] = Action('bookmark', 'do_it') |
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
25 |
actions['keywords'] = Action('editkw', 'do_it') |
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
26 |
actions['prefs'] = Action('edit_prefs', 'do_it') |
147eddb3826c
Remove ActionLoader and replace it with a standard
fabien@tzone.org
parents:
74
diff
changeset
|
27 |
actions['folder'] = Action('folder', 'do_it') |
74
6784c4350b41
Cleanup of old code, fixes some errors with folders view and make it a
fabien@tzone.org
parents:
73
diff
changeset
|
28 |
actions['default'] = actions['index'] |