Use man2html to generate man pages in the Web UI (#887)

* Use man2html to generate man pages in the web UI

* Fix tests
This commit is contained in:
Daniel Markstedt 2022-10-04 06:38:15 -07:00 committed by GitHub
parent 402a1ba380
commit 0e4d42f04c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 47 additions and 20 deletions

View File

@ -6,7 +6,7 @@ FROM "${OS_ARCH}/${OS_DISTRO}:${OS_VERSION}"
EXPOSE 80 443
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends sudo systemd rsyslog procps
RUN apt-get update && apt-get install -y --no-install-recommends sudo systemd rsyslog procps man-db man2html
RUN groupadd pi
RUN useradd --create-home --shell /bin/bash -g pi pi

View File

@ -104,7 +104,8 @@ function installPackages() {
unzip \
unar \
disktype \
libgmock-dev
libgmock-dev \
man2html
}
# install Debian packges for RaSCSI standalone
@ -116,7 +117,8 @@ function installPackagesStandalone() {
libprotobuf-dev \
protobuf-compiler \
disktype \
libgmock-dev
libgmock-dev \
man2html
}
# cache the pip packages

View File

@ -183,13 +183,16 @@ class SysCmds:
return process.returncode, process.stderr.decode("utf-8")
@staticmethod
def get_filecontents(file_path):
def get_manpage(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.
Takes (str) file_path path to image file to generate manpage for.
Returns either the man2html output, or the stderr output.
"""
try:
with open(file_path) as file:
return 0, file.read()
except Exception as error:
return 1, error
process = run(
["man2html", file_path, "-M", "/"],
capture_output=True,
)
if process.returncode == 0:
return process.returncode, process.stdout.decode("utf-8")
return process.returncode, process.stderr.decode("utf-8")

View File

@ -89,7 +89,7 @@
{% block content %}{% endblock content %}
</div>
<div class="footer">
<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>{{ _("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>{{ _("Pi environment: ") }}{{ env["running_env"]["env"] }}</tt></center>
</div>
</div>

View File

@ -751,6 +751,10 @@
</tr>
</table>
<hr/>
<a href="/sys/manpage?app=rascsi"><p>{{ _("Read the RaSCSI Manual") }}</p></a>
<center><tt>
{% if netatalk_configured == 1 %}
{{ _("The AppleShare server is running. No active connections.") }}

View File

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

View File

@ -504,14 +504,27 @@ def show_manpage():
)
server_info = ractl_cmd.get_server_info()
file_path = f"{WEB_DIR}/../../../doc/{app}_man_page.txt"
file_path = f"{WEB_DIR}/../../../doc/{app}.1"
html_to_strip = [
"Content-type",
"!DOCTYPE",
"<HTML>",
"<HEAD>",
"<BODY>",
"<H1>",
]
returncode, manpage = sys_cmd.get_filecontents(file_path)
returncode, manpage = sys_cmd.get_manpage(file_path)
if returncode == 0:
formatted_manpage = ""
for line in manpage.splitlines(True):
# Strip out irrelevant header
if not line.startswith("!!"):
# Make URIs compatible with the Flask webapp
if "/?1+" in line:
line = line.replace("/?1+", "manpage?app=")
# Strip out useless hyperlink
elif "man2html" in line:
line = line.replace("<A HREF=\"/\">man2html</A>", "man2html")
if not any(ele in line for ele in html_to_strip):
formatted_manpage += line
return response(
@ -945,7 +958,11 @@ def create_file():
if not process["status"]:
return response(error=True, message=process["msg"])
return response(message=_("Image file created: %(file_name)s", file_name=full_file_name))
return response(
status_code=201,
message=_("Image file created: %(file_name)s", file_name=full_file_name),
image=full_file_name,
)
@APP.route("/files/download", methods=["POST"])

View File

@ -74,7 +74,7 @@ def test_attach_image(http_client, create_test_image, detach_devices):
},
),
("Host Bridge", {"type": "SCBR", "interface": "eth0", "inet": "10.10.20.1/24"}),
("DaynaPORT SCSI/Link", {"type": "SCDP", "interface": "eth0", "inet": "10.10.20.1/24"}),
("Ethernet Adapter", {"type": "SCDP", "interface": "eth0", "inet": "10.10.20.1/24"}),
("Host Services", {"type": "SCHS"}),
("Printer", {"type": "SCLP", "timeout": 30, "cmd": "lp -oraw %f"}),
],

View File

@ -21,6 +21,7 @@ def test_create_file(http_client, list_files, delete_file):
"file_name": file_prefix,
"type": "hds",
"size": 1,
"drive_name": "DEC RZ22",
},
)