From 75017423563a18986aa096566d8a2969c32c3588 Mon Sep 17 00:00:00 2001 From: yvesf Date: Sun, 24 Jul 2011 11:05:42 +0200 Subject: clean up file structure, use bottle soup plugin --- ebus/web/controller.py | 79 -------------------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 ebus/web/controller.py (limited to 'ebus/web/controller.py') diff --git a/ebus/web/controller.py b/ebus/web/controller.py deleted file mode 100644 index 99d7053..0000000 --- a/ebus/web/controller.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -import os, time -import itty -from werkzeug.contrib.cache import SimpleCache -from simplejson import dumps as dump_json -from sqlalchemy.orm import sessionmaker - -from ebus.web import model - -Session = sessionmaker() - -class CacheDecorator(object): - def __init__(self,key,timeout=20): - self.cache = SimpleCache(default_timeout=timeout) - self.func = None - self.key = key - - def cachedFunc(self, *args, **kwargs): - key = self.key(args, kwargs) - ret = self.cache.get(key) - if ret is None: - ret = self.func(*args, **kwargs) - self.cache.set(key, ret) - return ret - - def __call__(self, func): - self.func = func - return self.cachedFunc - - -## Web Requests -@itty.get("/") -def index(req): - filename=os.path.join(os.path.dirname(__file__), "static", "index.html") - return open(filename,"r").read() - -#@itty.get('/json/(?P[^/]+)') -#@itty.get('/json/(?P[^/]+)/from_date/(?P[^/]+)') -#@itty.get('/json/(?P[^/]+)/from_date/(?P[^/]+)/till_date/(?P[^/]+)') -@CacheDecorator(key=lambda args,kwargs: tuple(kwargs.keys()) + tuple(kwargs.values()), - timeout=20) -def json(req,sensor=None,from_date=None,till_date=None): - print "sensor=%s from_date=%s till_date=%s" % (sensor,from_date,till_date) - """ - values = Session().query(model.Value).join(model.Sensor) - - if sensor: - values = values.filter(model.Sensor.name == sensor)\ - - if from_date: - values = values.filter(model.Value.timestamp >= from_date) - - if till_date: - values = values.filter(model.Value.timestamp <= till_date) - - response = {"sensor":sensor, "from_date":from_date, "till_date":till_date, "values":values.all()} - return itty.Response(dump_json(response), - content_type="application/json") - """ - return itty.Response("") - -@itty.get('/json/list') -def list(req): - sensors = Session().query(model.Sensor) - return str(sensors.all()) - -@itty.get("/static/(?P.+)") -def static(request,filename): - return "" - file = itty.static_file(filename, root=os.path.join(os.path.dirname(__file__), 'static')) - return itty.Response(file, content_type=itty.content_type(file)) - - - -## Start method -def run(db_engine,host="0.0.0.0",port=5000): - Session.configure(bind=db_engine) - return itty.run_itty(host=host,port=port) -- cgit v1.2.1