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

« back to all changes in this revision

Viewing changes to grackle/wsgi.py

  • Committer: William Grant
  • Date: 2012-01-22 11:59:29 UTC
  • Revision ID: william.grant@canonical.com-20120122115929-vfqznemirdu539ij
Expose a backward memo too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
__metaclass__ = type
18
18
 
 
19
import json
 
20
import uuid
 
21
 
19
22
import web
20
23
 
21
 
from grackle.server.model import CassandraConnection
 
24
from grackle.model import CassandraConnection
22
25
 
23
26
conn = None
24
27
 
42
45
            return self.index(name)
43
46
 
44
47
        if args.op == 'get_messages':
45
 
            return self.get_messages(name)
 
48
            return self.get_messages(name, args)
46
49
 
47
50
    def POST(self, name):
48
51
        data = web.data()
52
55
    def index(self, name):
53
56
        return ('Service for archive %s.' % name)
54
57
 
55
 
    def get_messages(self, name):
56
 
        return repr(conn.get_messages(name))
 
58
    def get_messages(self, name, args):
 
59
        try:
 
60
            count = int(args.count)
 
61
        except (AttributeError, ValueError):
 
62
            count = 10
 
63
        order = getattr(args, 'order', '-date')
 
64
        start = getattr(args, 'start', '')
 
65
        messages, next_memo = conn.get_messages(name, order, count, start)
 
66
        return json.dumps({
 
67
            'messages': messages,
 
68
            'next_memo': next_memo,
 
69
            })
57
70
 
58
71
 
59
72
urls = (
64
77
app = web.application(urls, globals(), autoreload=False)
65
78
 
66
79
if __name__ == "__main__":
67
 
    conn = CassandraConnection('grackle', 'localhost/9160')
 
80
    import logging
 
81
    logging.basicConfig(
 
82
        format='%(asctime)s:%(levelname)s:%(name)s:%(message)s',
 
83
        level=logging.DEBUG)
 
84
    conn = CassandraConnection('grackle', ['localhost:9160'])
68
85
    app.run()