forked from twang817/aws-alfred-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquicklook_server.py
45 lines (35 loc) · 1.27 KB
/
quicklook_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
import os
import sys
from jinja2 import Environment, FileSystemLoader
import tornado.autoreload
import tornado.ioloop
import tornado.web
class Ec2QuicklookHandler(tornado.web.RequestHandler):
def enrich(self, context):
pass
def get(self):
template = templates.get_template('ec2.html.j2')
context = json.loads(self.get_argument('context', '{}'))
self.enrich(context)
self.write(template.render(**context))
class S3QuicklookHandler(tornado.web.RequestHandler):
def enrich(self, context):
pass
def get(self):
template = templates.get_template('s3.html.j2')
context = json.loads(self.get_argument('context', '{}'))
self.enrich(context)
self.write(template.render(**context))
def make_app():
return tornado.web.Application([
(r'/static/(.*)', tornado.web.StaticFileHandler, {'path': os.path.join(os.getcwd(), 'static')}),
(r'/quicklook/ec2', Ec2QuicklookHandler),
(r'/quicklook/s3', S3QuicklookHandler),
])
if __name__ == '__main__':
templates = Environment(loader=FileSystemLoader(os.path.join(os.getcwd(), 'templates')))
app = make_app()
app.listen(int(sys.argv[1]))
tornado.autoreload.start()
tornado.ioloop.IOLoop.current().start()