Show version number in configuration page

This commit is contained in:
C5H12O5
2023-08-28 21:35:02 +08:00
parent 8f71ec66c2
commit 9e1d4db3af
3 changed files with 16 additions and 4 deletions

View File

@ -6,9 +6,9 @@ import sys
from http.server import HTTPServer
from pathlib import Path
_basedir = Path(__file__).resolve().parent
_host = "0.0.0.0"
_port = 5125
_basedir = Path(__file__).resolve().parent
# initialize the templates
with open(_basedir / "templates/config.html", "r", encoding="utf-8") as html:
@ -40,10 +40,11 @@ def render_index(saved=None):
source["priority"] = saved_conf["priority"]
source_html += _source_tmpl.substitute(source)
return _index_tmpl.substitute(sources=source_html)
return _index_tmpl.substitute(sources=source_html, version=plugin_version())
def render_config(site, site_conf, saved_conf):
"""Render the configuration for a site."""
config_html = ""
config = site_conf.get("config")
if config is not None:
@ -82,6 +83,16 @@ def load_sites():
return dict(sorted(sites.items(), key=lambda x: x[0]))
def plugin_version():
"""Get the plugin version from the directory name."""
dir_name = _basedir.parent.name
if "-" in dir_name:
version = dir_name.split("-")[-1]
if version != "plugin":
return f"v{version}"
return ""
# initialize the index page
_index_html = render_index()

View File

@ -44,6 +44,7 @@
<ul class="collapsible">
${sources}
</ul>
<h5 class="right-align">${version}</h5>
</div>
</div>

4
run.sh
View File

@ -2,6 +2,7 @@
BASEDIR=$(dirname $0)
ARGV=""
PORT=5125
escape()
{
@ -16,8 +17,7 @@ while [ $i -le $# ]; do
i=`expr $i + 1`
done
port=5125
if ! netstat -tuln | grep ":$port" >/dev/null; then
if ! netstat -tuln | grep ":$PORT" >/dev/null; then
nohup /usr/bin/env python3 "$BASEDIR"/configserver/serve.py > /dev/null 2>&1 &
fi