changeset 1132:f9d8b80f5afb

implement list of known actions similar to list of known macros
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 06 Aug 2006 23:42:36 +0200
parents 67044a2a0224
children db56bd53fc32
files MoinMoin/action/__init__.py MoinMoin/macro/SystemInfo.py MoinMoin/request/__init__.py
diffstat 3 files changed, 23 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/__init__.py	Sun Aug 06 18:02:58 2006 +0200
+++ b/MoinMoin/action/__init__.py	Sun Aug 06 23:42:36 2006 +0200
@@ -29,10 +29,13 @@
 from MoinMoin import wikiutil
 from MoinMoin.Page import Page
 
-# create a list of extension actions from the subpackage directory
+# create a list of extension actions from the package directory
 extension_actions = pysupport.getPackageModules(__file__)
 modules = extension_actions
 
+# builtin-stuff (see do_<name> below):
+names = ['show', 'recall', 'raw', 'format', 'content', 'print', 'refresh', 'goto', 'userform', ]
+
 class ActionBase:
     """ action base class with some generic stuff to inherit
 
@@ -284,15 +287,14 @@
     Page(request, pagename).send_page(request, msg=savemsg)
 
 # Dispatching ----------------------------------------------------------------
-import os
-
-def getPlugins(request):
-    """ return the path to the action plugin directory and a list of plugins there """
-    dir = os.path.join(request.cfg.plugin_dir, 'action')
-    plugins = []
-    if os.path.isdir(dir):
-        plugins = pysupport.getPackageModules(os.path.join(dir, 'dummy'))
-    return dir, plugins
+def getNames(cfg):
+    if hasattr(cfg, 'action_names'):
+        return cfg.action_names
+    else:
+        lnames = names[:]
+        lnames.extend(wikiutil.getPlugins('action', cfg))
+        cfg.action_names = lnames # remember it
+        return lnames
 
 def getHandler(request, action, identifier="execute"):
     """ return a handler function for a given action or None """
--- a/MoinMoin/macro/SystemInfo.py	Sun Aug 06 18:02:58 2006 +0200
+++ b/MoinMoin/macro/SystemInfo.py	Sun Aug 06 23:42:36 2006 +0200
@@ -101,11 +101,12 @@
     row(_('Local extension macros'),
         ', '.join(wikiutil.wikiPlugins('macro', Macro.cfg)) or nonestr)
 
-    ext_actions = [x for x in action.extension_actions
+    glob_actions = [x for x in action.extension_actions
+                    if not x in request.cfg.actions_excluded]
+    row(_('Global extension actions'), ', '.join(glob_actions) or nonestr)
+    loc_actions = [x for x in wikiutil.wikiPlugins('action', Macro.cfg)
                    if not x in request.cfg.actions_excluded]
-    row(_('Global extension actions'), ', '.join(ext_actions) or nonestr)
-    row(_('Local extension actions'),
-        ', '.join(action.getPlugins(request)[1]) or nonestr)
+    row(_('Local extension actions'), ', '.join(loc_actions) or nonestr)
 
     row(_('Global parsers'), ', '.join(parser.modules) or nonestr)
     row(_('Local extension parsers'),
--- a/MoinMoin/request/__init__.py	Sun Aug 06 18:02:58 2006 +0200
+++ b/MoinMoin/request/__init__.py	Sun Aug 06 23:42:36 2006 +0200
@@ -663,21 +663,9 @@
             self.cfg._known_actions # check
         except AttributeError:
             from MoinMoin import action
-            # Add built in actions
-            actions = [name[3:] for name in action.__dict__ if name.startswith('do_')]
-
-            # Add plugins           
-            dummy, plugins = action.getPlugins(self)
-            actions.extend(plugins)
+            self.cfg._known_actions = set(action.getNames(self.cfg))
 
-            # Add extensions
-            actions.extend(action.extension_actions)
-
-            # TODO: Use set when we require Python 2.3
-            actions = dict(zip(actions, [''] * len(actions)))
-            self.cfg._known_actions = actions
-
-        # Return a copy, so clients will not change the dict.
+        # Return a copy, so clients will not change the set.
         return self.cfg._known_actions.copy()
 
     def getAvailableActions(self, page):
@@ -698,14 +686,10 @@
 
             # Filter non ui actions (starts with lower case letter)
             actions = self.getKnownActions()
-            for key in actions.keys():
-                if key[0].islower():
-                    del actions[key]
+            actions = [action for action in actions if not action[0].islower()]
 
             # Filter wiki excluded actions
-            for key in self.cfg.actions_excluded:
-                if key in actions:
-                    del actions[key]
+            actions = [action for action in actions if not action in self.cfg.actions_excluded]
 
             # Filter actions by page type, acl and user state
             excluded = []
@@ -715,11 +699,9 @@
                 # Prevent modification of underlay only pages, or pages
                 # the user can't write and can't delete
                 excluded = [u'RenamePage', u'DeletePage', ] # AttachFile must NOT be here!
-            for key in excluded:
-                if key in actions:
-                    del actions[key]
+            actions = [action for action in actions if not action in excluded]
 
-            self._available_actions = actions
+            self._available_actions = set(actions)
 
         # Return a copy, so clients will not change the dict.
         return self._available_actions.copy()