Proposal: write plugins as classes

Steven Armstrong <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
This is just an idea. I'ld like to here what you guys think of it.


Motivation
----------

There may be plugins that do similar things or use similar code.
There's currently no way to extend existing plugins (apart from hacking
them).
There's currently no defined procedure to store temporary variables or
rember state among callbacks. Doing that in module level variables can
be problematic for environments other than CGI. Storing that in the data
dict (as I currently do in some plugins) can also be problematic. What
if some other plugin uses the same name to store something there?


Proposal
--------

Write a PluginBase class which offers common functionality all/most
plugins would benefit from.

A plugin could than look something like:

funky.py ------------------------------

from Pyblosxom.plugins import PluginBase

class FunkyPlugin(PluginBase):

  def __init__(self):
    super(FunkyPlugin, self).__init__()
    self.beFunky = False

  def cb_start(self, args):
    """Do some funky initialization"""

  def cb_pathinfo(self, args):
    path_info = args['request'].getHttp()['PATH_INFO']
    if path_info.endswith("funky"):
       self.beFunky = True

  def cb_story(self, args)
    entry = args['entry']
    if self.beFunky:
       entry['funky_message'] = "funky :-)"
    else:
       entry['funky_message'] = "Not funky today :-("

  def cb_end(self, args):
    """Do some funky cleanup"""


class Plugin(FunkyPlugin):
  pass

---------------------------------------

The plugin loading mechanism would then load the plugin, create an
instance of the Plugin class and call its cb_* methods as it called
module functions before.

We could write a wrapper class that handles older plugins that are not
written like this to be backwards compatible or just check if the Plugin
class exists or not or something like that.


What say you?

cheers
Steven



-------------------------------------------------------
This SF.net email is sponsored by Demarc:
A global provider of Threat Management Solutions.
Download our HomeAdmin security software for free today!
http://www.demarc.com/Info/Sentarus/hamr30
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.