# HG changeset patch # User Jeff Hammel # Date 1278536301 25200 # Node ID bcc3a59713c3932b159c3ea0de00c5f3e991a66e # Parent 3550159184cfc957b6a7f72ce9a37a8c55c5c265 1st steps to have blog post entry handler plugins diff -r 3550159184cf -r bcc3a59713c3 bitsyblog/blog.py --- a/bitsyblog/blog.py Mon Jun 28 08:07:09 2010 -0700 +++ b/bitsyblog/blog.py Wed Jul 07 13:58:21 2010 -0700 @@ -5,6 +5,7 @@ from cStringIO import StringIO from glob import glob +from pkg_resources import iter_entry_points class BlogEntry(object): """interface class for a blog entry""" @@ -46,6 +47,14 @@ class Blog(object): """abstract class for a users' blog""" + def __init__(self): + self.handlers = [] # handlers for blog post event + for entry_point in iter_entry_points('bitsyblog.listeners'): + try: + handler = entry_point.load() + self.handlers.append(handler) + except: + continue def __call__(self, user, permissions=('public',), number=None): return self.blog(user, permissions, number=number) @@ -78,7 +87,9 @@ def post(self, user, date, text, privacy): """post a new blog entry""" - + entry = BlogEntry(date, body, privacy, user): + for handler in self.handlers: + handler(entry) def delete(self, user, datestamp): """remove a blog entry""" @@ -87,6 +98,7 @@ """a blog that lives on the filesystem""" def __init__(self, directory): + Blog.__init__(self) self.directory = directory def location(self, user, permission, *path):