forked from OpenShiftDemos/os-sample-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
46 lines (36 loc) · 1.32 KB
/
Copy pathapp.py
File metadata and controls
46 lines (36 loc) · 1.32 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
import traceback
# import unittest.mock as mock
# from mock import patch, MagicMock
import cx_Oracle
from flask import Flask, redirect, url_for, request
application = Flask(__name__, static_url_path='')
with open('static/sqltest.html', 'r') as content_file:
content = content_file.read()
@application.route('/')
def root():
return content
# http://flask.pocoo.org/snippets/76/
# important that path: because the "/" chars
@application.route('/success/<path:name>')
def success(name):
out = 'welcome %s' % name
try:
connection = cx_Oracle.connect(name)
cursor = connection.cursor()
cursor.execute("select * from user_tables")
out = ' '.join(str(s) for s in cursor.fetchall()) + '\n'
except Exception:
out = traceback.format_exc()
return out
@application.route('/sqltestres', methods=['POST', 'GET'])
def login():
if request.method == 'POST':
user = request.form['nm']
return redirect(url_for('success', name=user))
else:
user = request.args.get('nm')
return redirect(url_for('success', name=user))
if __name__ == '__main__':
# see https://lists.openshift.redhat.com/openshift-archives/dev/2015-July/msg00043.html
# with mock.patch.object(getpass, "getuser", return_value='default'):
application.run(debug=True, host='0.0.0.0')