# HG changeset patch # User Teemu Piippo # Date 1559947368 -10800 # Node ID 8949af6a42797bf2d9da86ca453709970a192c4b # Parent f0a6bf48b05e91860d998f2f5d7caf8302168c45 added the list of issues onto the web frontend diff -r f0a6bf48b05e -r 8949af6a4279 ldcheck.py --- a/ldcheck.py Sat Jun 08 01:32:25 2019 +0300 +++ b/ldcheck.py Sat Jun 08 01:42:48 2019 +0300 @@ -64,31 +64,19 @@ import argparse -def default_problem_message(message): - if callable(message): - import inspect - spec = inspect.getfullargspec(message) - args = {} - assert not spec.varargs and not spec.varkw - for argname in spec.args + spec.kwonlyargs: - args[argname] = '<' + argname.replace('_', ' ') + '>' - return message(**args) - else: - return message - class ListTestSuiteAction(argparse.Action): def __init__(self, option_strings, dest, nargs = None, **kwargs): super().__init__(option_strings, dest, nargs = 0, **kwargs) def __call__(self, *args, **kwargs): - from testsuite import load_tests, all_warning_types + import testsuite from sys import exit from re import sub - test_suite = load_tests() - for warning_type in sorted(all_warning_types(test_suite), key = lambda k: k.name): + test_suite = testsuite.load_tests() + for warning_type in testsuite.all_problem_types(test_suite): print(str.format('{name}: {severity}: "{message}"', name = warning_type.name, severity = warning_type.severity, - message = default_problem_message(warning_type.message), + message = warning_type.placeholder_message(), )) exit(0) diff -r f0a6bf48b05e -r 8949af6a4279 templates/webfront.html --- a/templates/webfront.html Sat Jun 08 01:32:25 2019 +0300 +++ b/templates/webfront.html Sat Jun 08 01:42:48 2019 +0300 @@ -35,7 +35,28 @@ {% else %} No problems whatsoever. {% endif %} +
{% endif %} +

List of reported issue types

+ + + + + + + + + + +{% for problem_type in problem_types %} + + + + + +{% endfor %} + +
Name of issueSeverityExample message
{{ problem_type.name }}{{ problem_type.severity }}{{ problem_type.placeholder_message() }}
diff -r f0a6bf48b05e -r 8949af6a4279 testsuite.py --- a/testsuite.py Sat Jun 08 01:32:25 2019 +0300 +++ b/testsuite.py Sat Jun 08 01:42:48 2019 +0300 @@ -17,6 +17,17 @@ bad_object = bad_object, **args, ) + def placeholder_message(self): + if callable(self.message): + import inspect + spec = inspect.getfullargspec(self.message) + args = {} + assert not spec.varargs and not spec.varkw + for argname in spec.args + spec.kwonlyargs: + args[argname] = '<' + argname.replace('_', ' ') + '>' + return self.message(**args) + else: + return self.message class Problem: def __init__(self, problem_class, bad_object, **args): @@ -160,9 +171,16 @@ messages.append(message) return '\n'.join(messages) -def all_warning_types(test_suite): +def iterate_problems(test_suite): for test_function in test_suite['tests']: yield from test_function.ldcheck_problem_types.values() + +def all_problem_types(test_suite): + return sorted( + iterate_problems(test_suite), + key = lambda problem_type: problem_type.name + ) + if __name__ == '__main__': from pprint import pprint diff -r f0a6bf48b05e -r 8949af6a4279 webfront.py --- a/webfront.py Sat Jun 08 01:32:25 2019 +0300 +++ b/webfront.py Sat Jun 08 01:42:48 2019 +0300 @@ -2,12 +2,13 @@ from flask import Flask, render_template, redirect, request from ldcheck import load_config, load_colours, find_ldconfig_ldr_paths from parse import read_ldraw -from testsuite import load_tests, check_model, problem_text +from testsuite import load_tests, check_model, problem_text, all_problem_types app = Flask('LDCheck') @app.route('/', methods = ['GET', 'POST']) def web_front(): + test_suite = load_tests() if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files or not request.files['file'].filename: @@ -23,7 +24,6 @@ name = filename, ldraw_directories = config['libraries'], ) - test_suite = load_tests() report = check_model(model, test_suite) # Amend human-readable messages into the report @@ -31,13 +31,18 @@ object = model.body[problem.body_index] problem.message_str = problem_text(problem, test_suite) problem.ldraw_code = object.textual_representation() + return render_template('webfront.html', + report = report, + name = filename, + problem_types = all_problem_types(test_suite) + ) else: - report = None - filename = None - return render_template('webfront.html', - report = report, - name = filename - ) + test_suite = load_tests() + return render_template('webfront.html', + report = None, + name = None, + problem_types = all_problem_types(test_suite) + ) @app.route('/static/') def static_file(path):