summaryrefslogtreecommitdiffstats
path: root/web/about.py
diff options
context:
space:
mode:
Diffstat (limited to 'web/about.py')
-rwxr-xr-xweb/about.py69
1 files changed, 69 insertions, 0 deletions
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 = '<a href="' + os_url + '">' + os_name + '</a> ' + 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()