1 #!/usr/bin/env python3 |
1 #!/usr/bin/env python3 |
2 from flask import Flask, render_template, redirect, request |
2 from flask import Flask, render_template, redirect, request |
3 from ldcheck import appname, version, version_string |
3 from ldcheck import appname, version, version_string |
4 from ldcheck import load_config, find_ldconfig_ldr_paths |
|
5 from parse import read_ldraw |
4 from parse import read_ldraw |
6 from testsuite import load_tests, check_model, problem_text, all_problem_types |
5 from testsuite import load_tests, check_model, problem_text, all_problem_types |
7 |
6 |
8 app = Flask(appname) |
7 app = Flask(appname) |
|
8 |
|
9 from ldcheck import LDrawContext |
|
10 try: |
|
11 context = LDrawContext() |
|
12 except RuntimeError as error: |
|
13 from sys import stderr, exit |
|
14 print('error:', str(error), file = stderr) |
|
15 exit(1) |
9 |
16 |
10 def format_report_html(report, model, test_suite): |
17 def format_report_html(report, model, test_suite): |
11 messages = [] |
18 messages = [] |
12 for problem in report['problems']: |
19 for problem in report['problems']: |
13 ldraw_code = model.body[problem.body_index].textual_representation() |
20 ldraw_code = model.body[problem.body_index].textual_representation() |
35 # check if the post request has the file part |
42 # check if the post request has the file part |
36 if 'file' not in request.files or not request.files['file'].filename: |
43 if 'file' not in request.files or not request.files['file'].filename: |
37 return redirect(request.url) |
44 return redirect(request.url) |
38 file = request.files['file'] |
45 file = request.files['file'] |
39 filename = file.filename |
46 filename = file.filename |
40 config = load_config() |
47 model = read_ldraw(file.stream, name = filename, context = context) |
41 model = read_ldraw( |
|
42 file.stream, |
|
43 name = filename, |
|
44 ldraw_directories = config['libraries'], |
|
45 ) |
|
46 report = check_model(model, test_suite) |
48 report = check_model(model, test_suite) |
47 |
49 |
48 # Amend human-readable messages into the report |
50 # Amend human-readable messages into the report |
49 for problem in report['problems']: |
51 for problem in report['problems']: |
50 object = model.body[problem.body_index] |
52 object = model.body[problem.body_index] |