webfront.py

changeset 32
75f44d3063da
parent 29
db6ca177c6c4
child 41
4d87bc126368
child 57
c147116768f4
--- a/webfront.py	Wed Jan 24 23:14:01 2018 +0200
+++ b/webfront.py	Wed Jan 31 14:34:23 2018 +0200
@@ -1,7 +1,8 @@
+#!/usr/bin/env python3
 from flask import Flask, render_template, redirect, request
 from ldcheck import load_config, load_colours, find_ldconfig_ldr_paths
 from ldcheck import read_ldraw
-from testsuite import load_tests, check_model, format_report_html
+from testsuite import load_tests, check_model, problem_text
 
 app = Flask('LDCheck')
 
@@ -12,7 +13,6 @@
         if 'file' not in request.files or not request.files['file'].filename:
             return redirect(request.url)
         file = request.files['file']
-        print(type(file))
         config = load_config('ldcheck.cfg')
         for ldconfig_ldr_path in find_ldconfig_ldr_paths(config):
             with ldconfig_ldr_path.open() as ldconfig_ldr:
@@ -24,18 +24,28 @@
         )
         test_suite = load_tests()
         report = check_model(model, test_suite)
-        return str.format(
-            '<!doctype html><html><body><ul>{report}</ul></body></html>',
-            report = format_report_html(report, model, test_suite)
-        )
-    return '''
-    <!doctype html>
-    <title>Upload new File</title>
-    <h1>Upload new File</h1>
-    <form method=post enctype=multipart/form-data>
-      <p><input type=file name=file>
-         <input type=submit value=Upload>
-    </form>
-    '''
+
+        # Amend human-readable messages into the report
+        for problem in report['problems']:
+            object = model.body[problem['body-index']]
+            problem['message'] = problem_text(problem, test_suite)
+            problem['ldraw-code'] = object.textual_representation()
+    else:
+        report = None
+    return render_template('webfront.html',
+        report = report,
+    )
 
-app.run()
+@app.route('/static/<path:path>')
+def static_file(path):
+    from flask import send_from_directory
+    from os import path
+    return send_from_directory(path.join('static', path))
+
+if __name__ == '__main__':
+    from argparse import ArgumentParser
+    parser = ArgumentParser()
+    parser.add_argument('-p', '--port', type = int, default = 5000)
+    parser.add_argument('-d', '--debug', action = 'store_true')
+    args = parser.parse_args()
+    app.run(port = args.port, debug = args.debug)

mercurial