This repository was archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsgauge.py
More file actions
72 lines (59 loc) · 2.35 KB
/
Copy pathlsgauge.py
File metadata and controls
72 lines (59 loc) · 2.35 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
""" filename: lsgauge.py
this is a wrapper for main program, its primary purpose is to
manage error messages and output your HTML, XML or JSON as required
The flask framework is used to interface this code to the web server.
For more info on flash look at http://flask.pocoo.org/
"""
from flask import Flask, request, make_response
application = Flask(__name__)
import traceback
import os
import sys
CURRENTDIR = os.path.dirname(os.path.abspath(__file__))
if CURRENTDIR not in sys.path:
sys.path.append(CURRENTDIR)
def wsErrorTextHTML(txt):
## displays the python error on the web page - useful for debugging
## but on a live system would have it save the error to a database
## and give the user an error number
err = "<p>ERROR!</p>"
err += "<pre>"+ txt + "</pre>"
return err
@application.errorhandler(500)
def internalServerError(error):
err = "<p>ERROR! 500</p>"
err += "<pre>"+ str(error) + "</pre>"
err += "<pre>"+ str(traceback.format_exc()) + "</pre>"
return err
# This next line is the main entry point for the lsgauge web application
# Flask takes care of linking this together. As it is below, the URL to
# access the web page will be http://servername/lsgauge
@application.route('/lsgauge', methods=['POST', 'GET'])
def indexApp():
application.debug = 0
try:
##
## The core code is in lsgaugeCore.py
##
from lsgaugeCore import LSGaugeCore
lsgaugeCore = LSGaugeCore()
htmlData = lsgaugeCore.index(request)
application.logger.debug(htmlData)
## output your html code
response = make_response(htmlData)
response.headers['Content-Type'] = 'text/html'
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response.headers['Pragma'] = 'no-cache'
response.headers['Expires'] = '0'
return response
except:
## for when you get an error message
response = make_response(wsErrorTextHTML(traceback.format_exc()))
response.headers['Content-Type'] = 'text/html'
return response
response = make_response("unkown!")
response.headers['Content-Type'] = 'text/html'
return response
if __name__ == "__main__":
application.debug = True
application.run()