added the list of issues onto the web frontend

Sat, 08 Jun 2019 01:42:48 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 08 Jun 2019 01:42:48 +0300
changeset 63
8949af6a4279
parent 62
f0a6bf48b05e
child 64
1c0884f5506e

added the list of issues onto the web frontend

ldcheck.py file | annotate | diff | comparison | revisions
templates/webfront.html file | annotate | diff | comparison | revisions
testsuite.py file | annotate | diff | comparison | revisions
webfront.py file | annotate | diff | comparison | revisions
--- 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)
 
--- 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 %}
+    <hr />
 {% endif %}
+<h1>List of reported issue types</h1>
+<table>
+<thead>
+<tr>
+<th>Name of issue</th>
+<th>Severity</th>
+<th>Example message</th>
+</tr>
+</thead>
+<tbody>
+
+{% for problem_type in problem_types %}
+    <tr>
+    <td>{{ problem_type.name }}</td>
+    <td>{{ problem_type.severity }}</td>
+    <td>{{ problem_type.placeholder_message() }}</td>
+    </tr>
+{% endfor %}
+</tbody>
+</table>
 </div>
 </body>
 </html>
--- 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
--- 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/<path:path>')
 def static_file(path):

mercurial