diff options
author | yvesf <yvesf-git@xapek.org> | 2011-07-24 11:05:42 +0200 |
---|---|---|
committer | yvesf <yvesf-git@xapek.org> | 2011-07-24 11:05:42 +0200 |
commit | 75017423563a18986aa096566d8a2969c32c3588 (patch) | |
tree | bd86ab746dd06f71ebd1b723e3bec754805e8736 /ebus/webapp/soup_plugin.py | |
parent | a0382ecfbef32b47b7438170feaa7b81d7bc22db (diff) | |
download | ebus-alt-75017423563a18986aa096566d8a2969c32c3588.tar.gz ebus-alt-75017423563a18986aa096566d8a2969c32c3588.zip |
clean up file structure, use bottle soup plugin
Diffstat (limited to 'ebus/webapp/soup_plugin.py')
-rw-r--r-- | ebus/webapp/soup_plugin.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/ebus/webapp/soup_plugin.py b/ebus/webapp/soup_plugin.py new file mode 100644 index 0000000..68120af --- /dev/null +++ b/ebus/webapp/soup_plugin.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python + +import inspect + +from sqlalchemy import create_engine, text +from sqlalchemy.ext.sqlsoup import SqlSoup + + +class SoupPlugin(object): + name = 'soup' + def __init__(self, url, keyword='soup'): + self.url = url + self.keyword = keyword + + def setup(self, app): + for other in app.plugins: + if not isinstance(other, SoupPlugin): continue + if other.keyword == self.keyword: + raise PluginError("Found another soup plugin with "\ + "conflicting settings (non-unique keyword).") + + self.engine = create_engine(self.url) + self.soup = SqlSoup(self.engine) + + + def apply(self, callback, context): + print "apply" + conf = context['config'].get('soup') or {} + keyword = conf.get('keyword', self.keyword) + + args = inspect.getargspec(context['callback'])[0] + if keyword not in args: + return callback + + def wrapper(*args, **kwargs): + kwargs[keyword] = self.soup + return callback(*args, **kwargs) + + return wrapper |