summaryrefslogtreecommitdiffstats
path: root/web/about.py
blob: 8170f0dc6919200966389b68d35c0f7b602df0d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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()