summaryrefslogtreecommitdiff
path: root/heap/ebus/webapp/soup_plugin.py
diff options
context:
space:
mode:
authorEbus-at-dockstar <ebus@dockstar>2013-03-25 10:24:28 +0100
committerEbus-at-dockstar <ebus@dockstar>2013-03-25 10:24:43 +0100
commit862282ce99760832d3e9e5b4b1171b861105e004 (patch)
tree0e229418e391917b79d42a8bdee46fb7a8612895 /heap/ebus/webapp/soup_plugin.py
parent9522cdffa94f278eb5e1894600535986e22c2890 (diff)
downloadebus-alt-862282ce99760832d3e9e5b4b1171b861105e004.tar.gz
ebus-alt-862282ce99760832d3e9e5b4b1171b861105e004.zip
move old stuff away
Diffstat (limited to 'heap/ebus/webapp/soup_plugin.py')
-rw-r--r--heap/ebus/webapp/soup_plugin.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/heap/ebus/webapp/soup_plugin.py b/heap/ebus/webapp/soup_plugin.py
new file mode 100644
index 0000000..e85d0b0
--- /dev/null
+++ b/heap/ebus/webapp/soup_plugin.py
@@ -0,0 +1,42 @@
+# -*- 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
+from sqlsoup import SQLSoup as SqlSoup
+
+
+class SoupPlugin(object):
+ name = 'soup'
+ def __init__(self, url, echo=False, keyword='soup'):
+ self.url = url
+ self.keyword = keyword
+ self.echo = echo
+
+ 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, echo=self.echo)
+ 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