|
1 | | -# |
2 | | -# Copyright (C) 2019 UAVCAN Development Team <[email protected]>. |
| 1 | +# Copyright (C) OpenCyphal <[email protected]>. |
3 | 2 | # Author: Pavel Kirienko <[email protected]> |
4 | | -# |
5 | 3 |
|
6 | | -import os |
7 | | -import re |
8 | | -import glob |
| 4 | +from flask import redirect |
9 | 5 | from .. import app |
10 | | -from flask import send_file, redirect, abort |
11 | 6 |
|
| 7 | +_SPECIFICATION_URI = "https://opencyphal.github.io/specification/Cyphal_Specification.pdf" |
12 | 8 |
|
13 | | -_SPECIFICATION_DIRECTORY_PATH = os.path.join(app.root_path, '..', 'specification') |
14 | 9 |
|
15 | | -_CYPHAL_SPECIFICATION_GLOB = 'Cyphal_Specification*.pdf' |
16 | | - |
17 | | -@app.route('/specification/') |
18 | | -def _latest_specification(): |
19 | | - entries = list(glob.glob(os.path.join(_SPECIFICATION_DIRECTORY_PATH, _CYPHAL_SPECIFICATION_GLOB))) |
20 | | - entries.sort(key=lambda t: [int(c) if c.isdigit() else c for c in re.split(r'(\d+)', t)]) # Natural sorting |
21 | | - newest_file = os.path.basename(entries[-1]) |
22 | | - app.logger.info('Sorted specifications: %r, newest: %r', entries, newest_file) |
23 | | - return redirect('/specification/' + newest_file) |
24 | | - |
25 | | - |
26 | | -@app.route('/specification/<path:file_name>') |
27 | | -def _particular_specification(file_name): |
28 | | - try: |
29 | | - return send_file(os.path.join(_SPECIFICATION_DIRECTORY_PATH, file_name), |
30 | | - mimetype='application/pdf') |
31 | | - except FileNotFoundError: |
32 | | - return abort(404) |
| 10 | +@app.route("/specification/", defaults={"subpath": ""}) |
| 11 | +@app.route("/specification/<path:subpath>") |
| 12 | +def _latest_specification(subpath: str): |
| 13 | + _ = subpath |
| 14 | + return redirect(_SPECIFICATION_URI, code=301) |
0 commit comments