Newer
Older
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
from flask import Flask, render_template, send_from_directory
from multiprocessing import Process
from collect_html import collect_html
from generate_html import generate_html
from gevent import pywsgi
from utils import IP2NAME, CACHE_DIR, SERVER_PORT
import os
if not os.path.exists(CACHE_DIR):
os.makedirs(CACHE_DIR)
app = Flask(__name__, static_url_path="")
@app.route("/")
@app.route("/gpus.html")
def root():
sections = []
for machine_ip in IP2NAME:
machine_name = IP2NAME[machine_ip] + '(' + machine_ip + ')'
target_file = os.path.join(CACHE_DIR, f"{machine_ip}.html")
if os.path.exists(target_file):
with open(target_file, "r", encoding="utf-8") as f:
html = f.read()
else:
html = ""
if html:
sections.append(html)
else:
sections.append(render_template("section-error.html", machine_name=machine_name))
return render_template("index.html", sections=sections)
@app.route('/static/<path:path>')
def sendui(path):
return send_from_directory('static', path)
if __name__ == "__main__":
p = Process(target=collect_html)
p.start()
server = pywsgi.WSGIServer(('0.0.0.0', SERVER_PORT), app)
server.serve_forever()