webfront.py

Sun, 23 Jun 2019 00:50:22 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 23 Jun 2019 00:50:22 +0300
changeset 75
3ec747dfbfb9
parent 63
8949af6a4279
child 65
f2dc17b830e0
child 99
01941a811b5a
permissions
-rwxr-xr-x

added a test for BFC INVERTNEXT not followed by a type-1 line

32
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
1 #!/usr/bin/env python3
29
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
2 from flask import Flask, render_template, redirect, request
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
3 from ldcheck import load_config, load_colours, find_ldconfig_ldr_paths
57
c147116768f4 fixed the web front
Teemu Piippo <teemu@hecknology.net>
parents: 32
diff changeset
4 from parse import read_ldraw
63
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
5 from testsuite import load_tests, check_model, problem_text, all_problem_types
29
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
6
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
7 app = Flask('LDCheck')
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
8
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
9 @app.route('/', methods = ['GET', 'POST'])
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
10 def web_front():
63
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
11 test_suite = load_tests()
29
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
12 if request.method == 'POST':
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
13 # check if the post request has the file part
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
14 if 'file' not in request.files or not request.files['file'].filename:
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
15 return redirect(request.url)
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
16 file = request.files['file']
61
15c95d3fcfd8 show the filename of the processed file in the report
Teemu Piippo <teemu@hecknology.net>
parents: 57
diff changeset
17 filename = file.filename
29
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
18 config = load_config('ldcheck.cfg')
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
19 for ldconfig_ldr_path in find_ldconfig_ldr_paths(config):
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
20 with ldconfig_ldr_path.open() as ldconfig_ldr:
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
21 load_colours(ldconfig_ldr)
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
22 model = read_ldraw(
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
23 file.stream,
61
15c95d3fcfd8 show the filename of the processed file in the report
Teemu Piippo <teemu@hecknology.net>
parents: 57
diff changeset
24 name = filename,
57
c147116768f4 fixed the web front
Teemu Piippo <teemu@hecknology.net>
parents: 32
diff changeset
25 ldraw_directories = config['libraries'],
29
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
26 )
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
27 report = check_model(model, test_suite)
32
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
28
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
29 # Amend human-readable messages into the report
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
30 for problem in report['problems']:
62
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 61
diff changeset
31 object = model.body[problem.body_index]
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 61
diff changeset
32 problem.message_str = problem_text(problem, test_suite)
f0a6bf48b05e Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents: 61
diff changeset
33 problem.ldraw_code = object.textual_representation()
63
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
34 return render_template('webfront.html',
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
35 report = report,
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
36 name = filename,
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
37 problem_types = all_problem_types(test_suite)
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
38 )
32
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
39 else:
63
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
40 test_suite = load_tests()
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
41 return render_template('webfront.html',
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
42 report = None,
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
43 name = None,
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
44 problem_types = all_problem_types(test_suite)
8949af6a4279 added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents: 62
diff changeset
45 )
29
db6ca177c6c4 added a simple web frontend
Santeri Piippo
parents:
diff changeset
46
32
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
47 @app.route('/static/<path:path>')
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
48 def static_file(path):
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
49 from flask import send_from_directory
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
50 from os import path
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
51 return send_from_directory(path.join('static', path))
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
52
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
53 if __name__ == '__main__':
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
54 from argparse import ArgumentParser
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
55 parser = ArgumentParser()
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
56 parser.add_argument('-p', '--port', type = int, default = 5000)
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
57 parser.add_argument('-d', '--debug', action = 'store_true')
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
58 args = parser.parse_args()
75f44d3063da Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents: 29
diff changeset
59 app.run(port = args.port, debug = args.debug)

mercurial