Sat, 08 Jun 2019 11:17:17 +0300
cleanup
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 |
65 | 2 | import flask |
3 | import testsuite | |
4 | import config | |
5 | import parse | |
6 | import colours | |
29 | 7 | |
65 | 8 | app = flask.Flask('LDCheck') |
29 | 9 | |
10 | @app.route('/', methods = ['GET', 'POST']) | |
11 | def web_front(): | |
65 | 12 | test_suite = testsuite.load_tests() |
13 | request = flask.request | |
29 | 14 | if request.method == 'POST': |
15 | # check if the post request has the file part | |
16 | if 'file' not in request.files or not request.files['file'].filename: | |
65 | 17 | return flask.redirect(request.url) |
29 | 18 | 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
|
19 | filename = file.filename |
65 | 20 | config_object = config.load_config('ldcheck.cfg') |
21 | for ldconfig_ldr_path in config.find_ldconfig_ldr_paths(config_object): | |
29 | 22 | with ldconfig_ldr_path.open() as ldconfig_ldr: |
65 | 23 | colours.load_colours(ldconfig_ldr) |
24 | model = parse.read_ldraw( | |
29 | 25 | file.stream, |
61
15c95d3fcfd8
show the filename of the processed file in the report
Teemu Piippo <teemu@hecknology.net>
parents:
57
diff
changeset
|
26 | name = filename, |
65 | 27 | ldraw_directories = config_object['libraries'], |
29 | 28 | ) |
65 | 29 | report = testsuite.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
|
30 | |
75f44d3063da
Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents:
29
diff
changeset
|
31 | # 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
|
32 | 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
|
33 | object = model.body[problem.body_index] |
65 | 34 | problem.message_str = str(problem) |
62
f0a6bf48b05e
Problem reporting revamp, program is now aware of its problem types
Teemu Piippo <teemu@hecknology.net>
parents:
61
diff
changeset
|
35 | problem.ldraw_code = object.textual_representation() |
65 | 36 | return flask.render_template('webfront.html', |
63
8949af6a4279
added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
37 | report = report, |
8949af6a4279
added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
38 | name = filename, |
65 | 39 | problem_types = testsuite.all_problem_types(test_suite) |
63
8949af6a4279
added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
40 | ) |
32
75f44d3063da
Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents:
29
diff
changeset
|
41 | else: |
65 | 42 | return flask.render_template('webfront.html', |
63
8949af6a4279
added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
43 | report = None, |
8949af6a4279
added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
44 | name = None, |
65 | 45 | problem_types = testsuite.all_problem_types(test_suite) |
63
8949af6a4279
added the list of issues onto the web frontend
Teemu Piippo <teemu@hecknology.net>
parents:
62
diff
changeset
|
46 | ) |
29 | 47 | |
32
75f44d3063da
Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents:
29
diff
changeset
|
48 | @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
|
49 | 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
|
50 | 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
|
51 | 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
|
52 | 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
|
53 | |
75f44d3063da
Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents:
29
diff
changeset
|
54 | if __name__ == '__main__': |
75f44d3063da
Reworked web front, problems are now sorted by category as well as line number
Santeri Piippo
parents:
29
diff
changeset
|
55 | 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
|
56 | parser = ArgumentParser() |
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('-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
|
58 | 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
|
59 | 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
|
60 | app.run(port = args.port, debug = args.debug) |