~unity-2d-team/unity-2d/Shell-MultiMonitor

« back to all changes in this revision

Viewing changes to grackle/server/wsgi.py

  • Committer: William Grant
  • Date: 2012-01-20 08:26:17 UTC
  • Revision ID: william.grant@canonical.com-20120120082617-4t3zdb532je063j4
A little bit of server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import web
20
20
 
 
21
from grackle.server.model import CassandraConnection
 
22
 
 
23
conn = None
 
24
 
21
25
 
22
26
class root:
23
27
 
33
37
 
34
38
    def GET(self, name):
35
39
        web.header('Content-Type', 'text/plain')
 
40
        args = web.input()
 
41
        if not getattr(args, 'op', None):
 
42
            return self.index(name)
 
43
 
 
44
        if args.op == 'get_messages':
 
45
            return self.get_messages(name)
 
46
 
 
47
    def POST(self, name):
 
48
        data = web.data()
 
49
        conn.add_message(name, data)
 
50
        web.ctx.status = '201 Created'
 
51
 
 
52
    def index(self, name):
36
53
        return ('Service for archive %s.' % name)
37
54
 
 
55
    def get_messages(self, name):
 
56
        return repr(conn.get_messages(name))
 
57
 
38
58
 
39
59
urls = (
40
60
    '/', 'root',
44
64
app = web.application(urls, globals(), autoreload=False)
45
65
 
46
66
if __name__ == "__main__":
 
67
    conn = CassandraConnection('grackle', 'localhost/9160')
47
68
    app.run()