-
Notifications
You must be signed in to change notification settings - Fork 16
/
flask_app.py
53 lines (39 loc) · 1.22 KB
/
flask_app.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
#!/usr/bin/env python3
import os
import sys
import logging
from flask import Flask, jsonify, send_file, request
here = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(here, '..'))
from fliplot.core import parseFile
here = os.path.dirname(os.path.realpath(__file__))
logging.basicConfig(format='%(asctime)s,%(msecs)d %(levelname)-8s %(filename)s:%(lineno)d %(message)s',
datefmt='%Y-%m-%d:%H:%M:%S',
level=logging.DEBUG)
app = Flask('fliplot')
@app.route('/')
def static_file():
return send_file('index.html')
@app.route('/parse-vcd', methods = ['POST'])
def parse_vcd():
content = None
fname = None
try:
content = request.json['content']
except KeyError:
logging.info(f'No content, try to open the file locally.')
try:
fname = request.json['fname']
except KeyError:
logging.info(f'No filename! So mysterious.')
logging.info(f'open file to parse: {fname}')
try:
data = parseFile(os.path.join(here, fname), content)
return jsonify(data)
except Exception as e:
logging.info(f'Error: {e}')
@app.route('/<path:path>')
def send_f(path):
return send_file(path)
if __name__ == "__main__":
app.run()