add some basic versioning

Tue, 25 Aug 2020 22:20:15 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 25 Aug 2020 22:20:15 +0300
changeset 100
62759e5c4554
parent 99
01941a811b5a
child 101
745f2c3aec0a

add some basic versioning

ldcheck.py file | annotate | diff | comparison | revisions
templates/webfront.html file | annotate | diff | comparison | revisions
webfront.py file | annotate | diff | comparison | revisions
--- a/ldcheck.py	Tue Aug 25 22:10:04 2020 +0300
+++ b/ldcheck.py	Tue Aug 25 22:20:15 2020 +0300
@@ -3,6 +3,10 @@
 if version_info < (3, 4):
     raise RuntimeError('Python 3.4 or newer required')
 
+appname = 'ldcheck'
+version = (0, 0, 9999)
+version_string = str.join('.', map(str, version))
+
 from colours import load_colours
 from geometry import *
 from pathlib import Path
@@ -130,6 +134,13 @@
         action = 'store_true',
         help = 'use colors'
     )
+    parser.add_argument('-v', '--version',
+        action = 'version',
+        version = str.format('{appname} {version}',
+            appname = appname,
+            version = version_string,
+        ),
+    )
     args = parser.parse_args()
     config = load_config('ldcheck.cfg')
     for ldconfig_ldr_path in find_ldconfig_ldr_paths(config):
--- a/templates/webfront.html	Tue Aug 25 22:10:04 2020 +0300
+++ b/templates/webfront.html	Tue Aug 25 22:20:15 2020 +0300
@@ -7,7 +7,7 @@
 </head>
 <body>
 <div class="top-form">
-    <h1>Check your part here</h1>
+    <h1>{{appname}} {{version}} - Check your part here</h1>
     <form method="post" enctype="multipart/form-data">
         <input type="file" name="file"/>
         <input type="submit" />
@@ -15,6 +15,10 @@
 </div>
 <div class="report-container">
 
+{% if is_debug %}
+<p>Note: this is an unreleased version, everything may not work as intended.</p>
+{% endif %}
+
 {% if report %}
     <h1>{{name}}</h1>
     {% if report['problems'] %}
--- a/webfront.py	Tue Aug 25 22:10:04 2020 +0300
+++ b/webfront.py	Tue Aug 25 22:20:15 2020 +0300
@@ -1,10 +1,11 @@
 #!/usr/bin/env python3
 from flask import Flask, render_template, redirect, request
+from ldcheck import appname, version, version_string
 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
 
-app = Flask('LDCheck')
+app = Flask(appname)
 
 def format_report_html(report, model, test_suite):
     messages = []
@@ -25,6 +26,11 @@
 @app.route('/', methods = ['GET', 'POST'])
 def web_front():
     test_suite = load_tests()
+    common_args = {
+        'appname': appname,
+        'version': version_string,
+        'is_debug': max(version) == 9999,
+    }
     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:
@@ -39,6 +45,7 @@
             file.stream,
             name = filename,
             ldraw_directories = config['libraries'],
+            **common_args,
         )
         report = check_model(model, test_suite)
 
@@ -50,14 +57,16 @@
         return render_template('webfront.html',
             report = report,
             name = filename,
-            problem_types = all_problem_types(test_suite)
+            problem_types = all_problem_types(test_suite),
+            **common_args,
         )
     else:
         test_suite = load_tests()
         return render_template('webfront.html',
             report = None,
             name = None,
-            problem_types = all_problem_types(test_suite)
+            problem_types = all_problem_types(test_suite),
+            **common_args,
         )
 
 @app.route('/static/<path:path>')

mercurial