lib/actions.py
author fabien@tzone.org
Mon, 05 Jan 2009 18:11:38 -0500
changeset 76 147eddb3826c
parent 74 6784c4350b41
permissions -rw-r--r--
Remove ActionLoader and replace it with a standard dict of new Action objects. Fixes a bad behavior with default action.

import imp
import sys
import os


class Action:
	def __init__(self, mname, fname):
		self.mname = mname
		self.fname = fname
	def _getmodule(self):
		modpath = os.path.join(os.path.dirname(__file__), 'actions')
		fp, pathname, description = imp.find_module(self.mname, [modpath])
		try:
			return imp.load_module(self.mname, fp, pathname, description)
		finally:
			if fp:
				fp.close()
	def __call__(self, *args):
		apply(self._getmodule().__dict__[self.fname],args)
		
actions = {}
actions['index'] = Action('index', 'do_it')
actions['import'] = Action('imp_xbel', 'do_it')
actions['bookmark'] = Action('bookmark', 'do_it')
actions['keywords'] = Action('editkw', 'do_it')
actions['prefs'] = Action('edit_prefs', 'do_it')
actions['folder'] = Action('folder', 'do_it')
actions['default'] = actions['index']