Add capabilities to get and render manpage output in the Web UI (#881)

- class method to get arbitrary file contents
- new web UI endpoint to fetch the contents of rascsi man pages (rendered txt files)
- Link to manpage in page footer
- Link to new wiki page for image type docs
- Other UI tweaks
This commit is contained in:
Daniel Markstedt 2022-10-03 12:46:18 -07:00 committed by GitHub
parent fd47411322
commit dcb4b33f2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 12 deletions

View File

@ -181,3 +181,15 @@ class SysCmds:
return process.returncode, process.stdout.decode("utf-8")
return process.returncode, process.stderr.decode("utf-8")
@staticmethod
def get_filecontents(file_path):
"""
Takes (str) file_path, with the path to the file to fetch the contents of.
Returns either the file contents, or the exception error.
"""
try:
with open(file_path) as file:
return 0, file.read()
except Exception as error:
return 1, error

View File

@ -89,7 +89,7 @@
{% block content %}{% endblock content %}
</div>
<div class="footer">
<center><tt>{{ _("RaSCSI Reloaded version: ") }}<strong>{{ version }} <a href="https://github.com/akuker/RASCSI/commit/{{ env["running_env"]["git"] }}" target="_blank">{{ env["running_env"]["git"][:7] }}</a></strong></tt></center>
<center><tt><a href="/sys/manpage?app=rascsi">{{ _("RaSCSI Reloaded version: ") }}</a><strong>{{ version }} <a href="https://github.com/akuker/RASCSI/commit/{{ env["running_env"]["git"] }}" target="_blank">{{ env["running_env"]["git"][:7] }}</a></strong></tt></center>
<center><tt>{{ _("Pi environment: ") }}{{ env["running_env"]["env"] }}</tt></center>
</div>
</div>

View File

@ -171,7 +171,7 @@
</summary>
<ul>
<li>{{ _("Manage image files in the active RaSCSI image directory: <tt>%(directory)s</tt> with a scan depth of %(scan_depth)s.", directory=base_dir, scan_depth=scan_depth) }}</li>
<li>{{ _("Select a valid SCSI ID and <a href=\"%(url)s\">LUN</a> to attach to. Unless you know what you're doing, always use LUN 0.", url="https://en.wikipedia.org/wiki/Logical_unit_number") }}
<li>{{ _("Select a valid SCSI ID and <a href=\"%(url)s\" target=\"_blank\">LUN</a> to attach to. Unless you know what you're doing, always use LUN 0.", url="https://en.wikipedia.org/wiki/Logical_unit_number") }}
</li>
<li>{{ _("If RaSCSI was unable to detect the media type associated with the image, you get to choose the type from the dropdown.") }}</li>
<li>
@ -348,17 +348,17 @@
<li>{{ _("Please configure the <tt>rascsi_bridge</tt> network bridge before attaching an emulated network adapter!") }}</li>
{% endif %}
<li>{{ _("If you have a DHCP setup, choose only the interface you have configured the bridge with. You can ignore the inet field when attaching.") }}</li>
<li>{{ _("To browse the modern web, install a vintage web proxy such as <a href=\"%(url)s\">Macproxy</a>.", url="https://github.com/akuker/RASCSI/wiki/Vintage-Web-Proxy#macproxy") }}</li>
<li>{{ _("To browse the modern web, install a vintage web proxy such as <a href=\"%(url)s\" target=\"_blank\">Macproxy</a>.", url="https://github.com/akuker/RASCSI/wiki/Vintage-Web-Proxy#macproxy") }}</li>
</li>
</ul>
<li>{{ _("Read more about <a href=\"%(url)s\">supported device types</a> on the wiki.", url="https://github.com/akuker/RASCSI/wiki/Supported-Device-Types") }}
<li>{{ _("Read more about <a href=\"%(url)s\" target=\"_blank\">supported device types</a> on the wiki.", url="https://github.com/akuker/RASCSI/wiki/Supported-Device-Types") }}
</li>
</ul>
</details>
<table border="black" cellpadding="3">
<tr style="font-weight: bold;">
<td>{{ _("Device") }}</td>
<td>{{ _("Code") }}</td>
<td>{{ _("Key") }}</td>
<td>{{ _("Parameters and Actions") }}</td>
</tr>
{% for type in REMOVABLE_DEVICE_TYPES + PERIPHERAL_DEVICE_TYPES %}
@ -442,7 +442,7 @@
<ul>
<li>{{ _("The largest file size accepted in this form is %(max_file_size)s MiB. Use other file transfer means for larger files.", max_file_size=max_file_size) }}</li>
<li>{{ _("File uploads will progress only if you stay on this page. If you navigate away before the transfer is completed, you will end up with an incomplete file.") }}</li>
<li>{{ _("Install <a href=\"%(url)s\">Netatalk</a> to use the AFP File Server.", url="https://github.com/akuker/RASCSI/wiki/AFP-File-Sharing") }}</li>
<li>{{ _("Install <a href=\"%(url)s\" target=\"_blank\">Netatalk</a> to use the AFP File Server.", url="https://github.com/akuker/RASCSI/wiki/AFP-File-Sharing") }}</li>
</ul>
</details>
@ -498,7 +498,7 @@
</summary>
<ul>
<li>{{ _("Choose the desination directory and download a file from the Web to your Raspberry Pi.") }}</li>
<li>{{ _("Install <a href=\"%(url)s\">Netatalk</a> to use the AFP File Server.", url="https://github.com/akuker/RASCSI/wiki/AFP-File-Sharing") }}</li>
<li>{{ _("Install <a href=\"%(url)s\" target=\"_blank\">Netatalk</a> to use the AFP File Server.", url="https://github.com/akuker/RASCSI/wiki/AFP-File-Sharing") }}</li>
</ul>
</details>
@ -579,11 +579,7 @@
{{ _("Create Empty Disk Image File") }}
</summary>
<ul>
<li>{{ _("The Generic Hard Disk image type is recommended for most computer platforms.") }}</li>
<li>{{ _("The Apple image type improves compatibility with Apple Macintosh computers.") }}</li>
<li>{{ _("The NEC image type improves compatibility with NEC PC-98 computers.") }}</li>
<li>{{ _("The SCSI-1 image type makes RaSCSI behave like a legacy SCSI-1 device, which may improve compatibility with very old SCSI controllers.") }}</li>
<li>{{ _("The Removable Disk image type can be used with SCSI floppy drives, SyQuest drives, Zip drives, etc.") }}</li>
<li>{{ _("Please refer to <a href=\"%(url)s\" target=\"_blank\">wiki documentation</a> to learn more about the supported image file types.", url="https://github.com/akuker/RASCSI/wiki/Supported-Device-Types#image-types") }}</li>
</ul>
</details>
<table style="border: none">

View File

@ -0,0 +1,8 @@
{% extends "base.html" %}
{% block content %}
<h3>{{ _("Manual for %(app)s:", app=app) }}</h3>
<p><pre>{{ manpage }}</pre></p>
<p><a href="/">{{ _("Go to Home") }}</a></p>
{% endblock content %}

View File

@ -57,6 +57,7 @@ from web_utils import (
upload_with_dropzonejs,
)
from settings import (
WEB_DIR,
AFP_DIR,
MAX_FILE_SIZE,
DEFAULT_CONFIG,
@ -487,6 +488,45 @@ def show_diskinfo():
)
@APP.route("/sys/manpage", methods=["GET"])
def show_manpage():
"""
Displays manpage
"""
app_allowlist = ["rascsi", "rasctl", "rasdump", "scsimon"]
app = request.args.get("app", type = str)
if app not in app_allowlist:
return response(
error=True,
message=_("%(app)s is not a recognized RaSCSI app", app=app)
)
server_info = ractl_cmd.get_server_info()
file_path = f"{WEB_DIR}/../../../doc/{app}_man_page.txt"
returncode, manpage = sys_cmd.get_filecontents(file_path)
if returncode == 0:
formatted_manpage = ""
for line in manpage.splitlines(True):
# Strip out irrelevant header
if not line.startswith("!!"):
formatted_manpage += line
return response(
template="manpage.html",
app=app,
manpage=formatted_manpage,
version=server_info["version"],
)
return response(
error=True,
message=_("An error occurred when accessing man page: %(error)s", error=manpage)
)
@APP.route("/logs/show", methods=["POST"])
def show_logs():
"""

View File

@ -95,3 +95,11 @@ def test_create_image_with_properties_file(http_client, delete_file):
# Cleanup
delete_file(file_name)
# route("/sys/manpage", methods=["POST"])
def test_show_manpage(http_client):
response = http_client.get("/sys/manpage?app=rascsi")
response_data = response.json()
assert response.status_code == 200
assert "rascsi" in response_data["data"]["manpage"]