# HG changeset patch # User Jeff Hammel # Date 1274798933 25200 # Node ID 57ca873ed9bf59bd527a98f00a44326b74d7db8d # Parent 3bf478cb31664b764813f2669db90543f24ce3c1 make this a pluggable system and start reorging infrastructure for that diff -r 3bf478cb3166 -r 57ca873ed9bf setup.py --- 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 """, ) diff -r 3bf478cb3166 -r 57ca873ed9bf taginthemiddle.ini --- 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 diff -r 3bf478cb3166 -r 57ca873ed9bf taginthemiddle/middleware.py --- 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 diff -r 3bf478cb3166 -r 57ca873ed9bf taginthemiddle/model.py --- 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')