comparison web/templog.py @ 182:e731c0d30b09

set nearly working
author Matt Johnston <matt@ucc.asn.au>
date Tue, 04 Feb 2014 22:49:16 +0800
parents 3b4277aaed3c
children adbf70d1449f
comparison
equal deleted inserted replaced
180:15ebb9de5049 182:e731c0d30b09
6 import zlib 6 import zlib
7 from datetime import datetime, timedelta 7 from datetime import datetime, timedelta
8 import time 8 import time
9 import urllib 9 import urllib
10 import sys 10 import sys
11 import os
11 12
12 import bottle 13 import bottle
13 from bottle import route, request, response 14 from bottle import route, request, response
14 15
15 import config 16 import config
41 start = end - timedelta(minutes=length_minutes) 42 start = end - timedelta(minutes=length_minutes)
42 43
43 response.set_header('Content-Type', 'image/png') 44 response.set_header('Content-Type', 'image/png')
44 start_epoch = time.mktime(start.timetuple()) 45 start_epoch = time.mktime(start.timetuple())
45 return log.graph_png(start_epoch, length_minutes * 60) 46 return log.graph_png(start_epoch, length_minutes * 60)
47
48 @route('/set')
49 def set():
50 return bottle.template('set', inline_data = log.get_params())
51
52 @route('/set_current.json')
53 def set_fresh():
54 response.set_header('Content-Type', 'application/javascript')
55 return log.get_current()
46 56
47 @route('/') 57 @route('/')
48 def top(): 58 def top():
49 59
50 minutes = int(request.query.get('length', 26*60)) 60 minutes = int(request.query.get('length', 26*60))
85 @route('/debug') 95 @route('/debug')
86 def debuglog(): 96 def debuglog():
87 response.set_header('Content-Type', 'text/plain') 97 response.set_header('Content-Type', 'text/plain')
88 return log.tail_debug_log() 98 return log.tail_debug_log()
89 99
100 @route('/env')
101 def env():
102 response.set_header('Content-Type', 'text/plain')
103 return '\n'.join(("%s %s" % k) for k in request.environ.items())
104 #return str(request.environ)
105 #yield "\n"
106 #var_lookup = environ['mod_ssl.var_lookup']
107 #return var_lookup("SSL_SERVER_I_DN_O")
108
109 @bottle.get('/<filename:re:.*\.js>')
110 def javascripts(filename):
111 return bottle.static_file(filename, root='static')
112
113
90 def main(): 114 def main():
91 #bottle.debug(True) 115 #bottle.debug(True)
92 #bottle.run(reloader=True) 116 #bottle.run(reloader=True)
93 bottle.run(server='cgi', reloader=True) 117 bottle.run(server='cgi', reloader=True)
94 #bottle.run(port=9999, reloader=True) 118 #bottle.run(port=9999, reloader=True)