From f73f2356820468344757dbb9d7f3ec73ece7bf66 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 13 Feb 2023 20:43:51 +0100 Subject: Updating. Signed-off-by: Daniel Baumann --- web/about.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 web/about.py (limited to 'web/about.py') diff --git a/web/about.py b/web/about.py new file mode 100755 index 0000000..8170f0d --- /dev/null +++ b/web/about.py @@ -0,0 +1,69 @@ +#!/usr/bin/python3.10 + +from datetime import timedelta +from time import clock_gettime,CLOCK_BOOTTIME + +import platform + +def print_html(htmlfile, os_string, host_architecture, host_name, host_uptime, kernel_name, kernel_version, cnt_version): + with open(htmlfile, 'r') as f: + html = f.read() + + print(html.format(**locals())) + +def get_host_architecture(): + host_architecture = platform.machine() + + return host_architecture + +def get_host_name(): + host_name = platform.node() + + return host_name + +def get_host_uptime(): + host_uptime = str(timedelta(seconds=int(clock_gettime(CLOCK_BOOTTIME)))) + + return host_uptime + +def get_kernel_name(): + kernel_name = platform.system() + + return kernel_name + +def get_kernel_version(): + kernel_version = platform.release() + + return kernel_version + +def get_cnt_version(): + with open('/usr/share/compute-tools/VERSION.txt', 'r') as f: + cnt_version = f.readline().strip() + + return cnt_version + +def main(): + _os_release = platform.freedesktop_os_release() + os_name = _os_release["NAME"] + os_version = _os_release["VERSION_ID"] + os_codename = _os_release["VERSION_CODENAME"] + os_url = _os_release["HOME_URL"] + + os_string = '' + os_name + ' ' + os_version + ' (' + os_codename + ')' + + host_architecture = get_host_architecture() + host_name = get_host_name() + host_uptime = get_host_uptime() + kernel_name = get_kernel_name() + kernel_version = get_kernel_version() + cnt_version = get_cnt_version() + + print('Content-Type: text/html\n') + print_html('html/header.html.in', os_string, host_architecture, host_name, host_uptime, kernel_name, kernel_version, cnt_version) + print_html('html/about.html.in', os_string, host_architecture, host_name, host_uptime, kernel_name, kernel_version, cnt_version) + print_html('html/footer.html', os_string, host_architecture, host_name, host_uptime, kernel_name, kernel_version, cnt_version) + + exit(0) + +if __name__ == '__main__': + main() -- cgit v1.2.3