webfront.py

changeset 65
f2dc17b830e0
parent 63
8949af6a4279
--- a/webfront.py	Sat Jun 08 01:51:50 2019 +0300
+++ b/webfront.py	Sat Jun 08 11:17:17 2019 +0300
@@ -1,47 +1,48 @@
 #!/usr/bin/env python3
-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, all_problem_types
+import flask
+import testsuite
+import config
+import parse
+import colours
 
-app = Flask('LDCheck')
+app = flask.Flask('LDCheck')
 
 @app.route('/', methods = ['GET', 'POST'])
 def web_front():
-    test_suite = load_tests()
+    test_suite = testsuite.load_tests()
+    request = flask.request
     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:
-            return redirect(request.url)
+            return flask.redirect(request.url)
         file = request.files['file']
         filename = file.filename
-        config = load_config('ldcheck.cfg')
-        for ldconfig_ldr_path in find_ldconfig_ldr_paths(config):
+        config_object = config.load_config('ldcheck.cfg')
+        for ldconfig_ldr_path in config.find_ldconfig_ldr_paths(config_object):
             with ldconfig_ldr_path.open() as ldconfig_ldr:
-                load_colours(ldconfig_ldr)
-        model = read_ldraw(
+                colours.load_colours(ldconfig_ldr)
+        model = parse.read_ldraw(
             file.stream,
             name = filename,
-            ldraw_directories = config['libraries'],
+            ldraw_directories = config_object['libraries'],
         )
-        report = check_model(model, test_suite)
+        report = testsuite.check_model(model, test_suite)
 
         # Amend human-readable messages into the report
         for problem in report['problems']:
             object = model.body[problem.body_index]
-            problem.message_str = problem_text(problem, test_suite)
+            problem.message_str = str(problem)
             problem.ldraw_code = object.textual_representation()
-        return render_template('webfront.html',
+        return flask.render_template('webfront.html',
             report = report,
             name = filename,
-            problem_types = all_problem_types(test_suite)
+            problem_types = testsuite.all_problem_types(test_suite)
         )
     else:
-        test_suite = load_tests()
-        return render_template('webfront.html',
+        return flask.render_template('webfront.html',
             report = None,
             name = None,
-            problem_types = all_problem_types(test_suite)
+            problem_types = testsuite.all_problem_types(test_suite)
         )
 
 @app.route('/static/<path:path>')

mercurial