-
Notifications
You must be signed in to change notification settings - Fork 0
/
tamandua_web.py
executable file
·85 lines (63 loc) · 2.42 KB
/
tamandua_web.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
#!/usr/bin/env python3
"""
Tamandua. Aggregate information from logfiles.
This is the main (entry point) of the web-app backend.
"""
import os
import sys
BASEDIR = os.path.abspath(os.path.dirname(__file__))
sys.path.append(BASEDIR)
from flask import Flask
from flask_restful import Api
from src.web.data_finder import DataFinder
from src.config import Config
from src.constants import CONFIGFILE
from src.exceptions import print_exception
from src.web.exceptions import errors as api_errors
import src.web.rest_api as rest_api
app = Flask(
__name__,
template_folder='web/templates',
static_folder='web/static')
api = Api(app, errors=api_errors)
Config().setup(os.path.join(BASEDIR, CONFIGFILE), BASEDIR)
try:
dataFinder = DataFinder()
except Exception as e:
print_exception(e, "Trying to create an instance of DataFinder", "Exiting application", fatal=True)
sys.exit(1)
api.add_resource(rest_api.Columns,
'/columns',
resource_class_args=[dataFinder])
api.add_resource(rest_api.Tags,
'/tags',
resource_class_args=[dataFinder])
api.add_resource(rest_api.Search,
'/search/<int:page>/<int:size>',
resource_class_args=[dataFinder])
api.add_resource(rest_api.Count,
'/count',
resource_class_args=[dataFinder])
api.add_resource(rest_api.AdvancedCount,
'/advcount/<field>/<int:length>',
resource_class_args=[dataFinder])
api.add_resource(rest_api.AdvancedCount,
'/advcount/<field>/<int:length>/<separator>',
resource_class_args=[dataFinder],
endpoint='advcount_with_separator')
api.add_resource(rest_api.FieldChoices,
'/fieldchoices/<field>/<int:maxChoices>',
resource_class_args=[dataFinder],
endpoint='advcount')
api.add_resource(rest_api.SupportedFieldChoices,
'/supported_fieldchoices',
resource_class_args=[dataFinder])
api.add_resource(rest_api.Trend,
'/trend/<field>/<int:dataCount>',
resource_class_args=[dataFinder])
api.add_resource(rest_api.Trend,
'/trend/<field>/<int:dataCount>/<separator>',
resource_class_args=[dataFinder],
endpoint='trend_with_separator')
if __name__ == "__main__":
app.run(host='localhost', port=8080, debug=True)