lib/actions.py
author fabien@tzone.org
Wed, 31 Dec 2008 01:00:21 -0500
changeset 70 1798859f7f6c
parent 60 dad9733c99f0
child 73 c078d8a04d76
permissions -rw-r--r--
Add my_db.MyDBConnexion.map_keywords
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     1
import imp
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     2
import sys
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     3
import os
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     4
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     5
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     6
class ActionsLoader:
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     7
	def __init__(self):
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     8
		self._actions = {}
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
     9
	def keys(self):
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    10
		return self._actions.keys()
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    11
	def _getmodule(self, name):
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    12
		modpath = os.path.join(os.path.dirname(__file__), 'actions')
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    13
		fp, pathname, description = imp.find_module(name, [modpath])
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    14
		try:
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    15
			return imp.load_module(name, fp, pathname, description)
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    16
		finally:
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    17
			if fp:
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    18
				fp.close()
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    19
	def __getitem__(self, item):
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    20
		mname, fname = self._actions[item]
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    21
		return self._getmodule(mname).__dict__[fname]
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    22
	def __setitem__(self, key, value):
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    23
		self._actions[key] = value
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    24
		
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    25
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    26
actions = ActionsLoader()
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    27
actions['default'] = ('index', 'do_it')
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    28
actions['index'] = ('index', 'do_it')
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    29
actions['edit'] = ('edit', 'do_it')
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    30
actions['import'] = ('imp_xbel', 'do_it')
31271426f879 First change to use a common entry point.
fabien@tzone.org
parents:
diff changeset
    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')