changeset 19:57ca873ed9bf default tip

make this a pluggable system and start reorging infrastructure for that
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 25 May 2010 07:48:53 -0700
parents 3bf478cb3166
children
files setup.py taginthemiddle.ini taginthemiddle/middleware.py taginthemiddle/model.py
diffstat 4 files changed, 36 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Mon May 24 07:48:48 2010 -0700
+++ b/setup.py	Tue May 25 07:48:53 2010 -0700
@@ -31,6 +31,10 @@
       # -*- Entry points: -*-
       [paste.app_factory]
       TagInTheMiddle = TagInTheMiddle.factory:factory
+
+      [tag.engines]
+      sqlite = TagInTheMiddle.model:SQLiteTags
+      file = TagInTheMiddle.model:FileTags
       """,
       )
       
--- a/taginthemiddle.ini	Mon May 24 07:48:48 2010 -0700
+++ b/taginthemiddle.ini	Tue May 25 07:48:53 2010 -0700
@@ -1,4 +1,4 @@
-#!/usr/bin/env paster
+#!/usr/bin/env paster serve
 
 [DEFAULT]
 debug = true
@@ -19,5 +19,5 @@
 
 [app:TagInTheMiddle]
 paste.app_factory = taginthemiddle.example:factory
-directory = %(here)s
-TagInTheMiddle.tags_file = %(here)s/tags
\ No newline at end of file
+directory = %(here)s # for example
+tags.engine = file://%(here)s/tags
--- a/taginthemiddle/middleware.py	Mon May 24 07:48:48 2010 -0700
+++ b/taginthemiddle/middleware.py	Tue May 25 07:48:53 2010 -0700
@@ -1,12 +1,11 @@
 """
-request dispatcher:
-data persisting across requests should go here
+apply and display tags via WSGI middleware;
+request dispatcher component
 """
 
 import os
 
 from handlers import TagCloud, ViewTags, PostTags
-from model import Tags
 
 from genshi.template import TemplateLoader
 from lxmlmiddleware import LXMLMiddleware
@@ -20,10 +19,10 @@
     defaults = { 'auto_reload': 'False',
                  'template_dirs': '',
                  'patterns': '*', # glob pattern: all URLs by default
-                 'tags_file': None, 
                  'tags_url': 'tags', # base URL for viewing tags
                  'post_url': '.tags', # sub-URL for posting tags
                  'author': None, # for RSS
+                 'engine': None
                  }
 
     def __init__(self, app, **kw):
@@ -33,8 +32,6 @@
         for key in self.defaults:
             setattr(self, key, kw.get(key, self.defaults[key]))
         self.auto_reload = self.auto_reload.lower() == 'true'
-        assert self.tags_file is not None
-        self.tags = Tags(self.tags_file)
         self.patterns = self.patterns.strip().split()
 
         # request handlers
@@ -46,6 +43,9 @@
         self.loader = TemplateLoader(self.template_dirs,
                                      auto_reload=self.auto_reload)
 
+        # tag engine
+        assert self.engine is not None, 'Must specify a tag.engine'
+
     def __call__(self, environ, start_response):
 
         # get a request object
--- a/taginthemiddle/model.py	Mon May 24 07:48:48 2010 -0700
+++ b/taginthemiddle/model.py	Tue May 25 07:48:53 2010 -0700
@@ -7,6 +7,9 @@
 
 import os
 import time
+from pkg_resources import iter_entry_points
+
+### interface
 
 class Tags(object):
   """
@@ -31,6 +34,21 @@
     get the URLs for a set of tags
     """
 
+def make_tags(string):
+  """
+  Instantiate and return a tag engine from a setuptools entry point
+  - string: "URL" of tagger (e.g. 'file:///path/to/file?author=whoami')
+  """
+
+  # have to split out the schema ourselves or urlparse is too smart for
+  # its own good
+  assert '://' in string # XXX could also not have this for no parameters
+  name, value = string.split('://', 1)
+
+  import pdb; pdb.set_trace()
+
+### implementation
+
 class FileTags(Tags):
   """
   file (e.g. .ini) based tagging scheme
@@ -128,3 +146,8 @@
     """
     select * from tags where tag=''
     """
+
+### command line
+
+if __name__ == '__main__':
+  foo = make_tags('file:///tmp/foo.tags?author=bar')