-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue.py
executable file
·119 lines (85 loc) · 3.57 KB
/
value.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/python
# Store the filepath for file manipulation
import os
filepath = os.path.abspath(os.path.dirname(__file__))
# Add the file path to the system path to import framework file.
import sys
if filepath not in sys.path:
sys.path.append(filepath)
# Debug Module.
import cgitb
cgitb.enable()
# Framework module
from framework import *
def errorModal(activeRow,activeCol,msg):
output = '''
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Error loading value row: %s, col: %s</h4>
</div>
<div class="modal-body">
<div class="te">%s</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>''' % (activeRow, activeCol, msg)
# Encode it.
utf8_output = output.encode('utf-8')
return utf8_output
def makeBody(activeFile,activeNode,activeRow,activeCol):
# Open database file.
database = open_file(filepath + databaseDirectory + '/' + activeFile, mode = 'r')
# Get the node with path
table = database.get_node(activeNode)
# If an exception occurs we try again
# If an exception occurs we try again
if type(table) is not Table:
return errorModal(activeRow, activeCol, "Error while loading node %s in file %s" % (activeFile,activeNode))
# Get the value
value = table[int(activeRow)][activeCol]
# Close database file
database.close()
output = '''
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">%s%s row:%s col:%s</h4>
</div>
<div class="modal-body">
<div class="te">%s</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>''' % (activeFile, activeNode, activeRow, activeCol, value)
# Encode it.
utf8_output = output.encode('utf-8')
return utf8_output
def application(environ, start_response):
# Process the parameters if any.
parameters = parse_qs(environ.get('QUERY_STRING', ''))
# Test if we've got an active filename.
if 'file' not in parameters.keys():
return errorPage('Missing argument. Value page needs a filename argument.<br>Example: value?file=test.h5&path=/foo/bar&row=0&col=chips', start_response)
# Test if we've got an active filename.
if 'path' not in parameters.keys():
return errorPage('Missing argument. Value page needs a path argument that contains the path of the node.<br>Example: value?file=test.h5&path=/foo/bar&row=0&col=chips', start_response)
# Test if we've got an active filename.
if 'row' not in parameters.keys():
return errorPage('Missing argument. Value page needs a row argument that contains the row number in table.<br>Example: value?file=test.h5&path=/foo/bar&row=0&col=chips', start_response)
# Test if we've got an active filename.
if 'col' not in parameters.keys():
return errorPage('Missing argument. Value page needs a "col" argument that contains the row number in table.<br>Example: value?file=test.h5&path=/foo/bar&row=0&col=chips', start_response)
# Get the filename
activeFile = parameters['file'][0]
# Get the table path
activeNode = parameters['path'][0]
# Get the row number
activeRow = parameters['row'][0]
# Get the column name
activeCol = parameters['col'][0]
# Make answer header.
status = '200 OK'
response_headers = [('Content-Type', 'text/html; charset=utf-8')]
start_response(status, response_headers)
# Return it.
return [makeBody(activeFile,activeNode,activeRow,activeCol)]
#print makeBody('test.h5','/Economics/GDPEUESTQUOGLD','0','QuoteDate')