Use local server instead of temporary file
This commit is contained in:
parent
84d05ac06e
commit
950c052e3f
|
@ -1,17 +1,20 @@
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import tempfile
|
import threading
|
||||||
import time
|
|
||||||
import os
|
|
||||||
import markdown
|
import markdown
|
||||||
|
import tornado.ioloop
|
||||||
|
import tornado.web
|
||||||
import navpoint.fix_path
|
import navpoint.fix_path
|
||||||
|
|
||||||
|
|
||||||
def about():
|
class AboutHandler(tornado.web.RequestHandler):
|
||||||
|
def get(self):
|
||||||
with open(navpoint.fix_path.fix_path("README.md")) as f:
|
with open(navpoint.fix_path.fix_path("README.md")) as f:
|
||||||
readme = markdown.markdown(
|
readme = markdown.markdown(
|
||||||
f.read()
|
f.read()
|
||||||
.replace("https://www.gnu.org/licenses/gpl-3.0.en.html", "#gpl")
|
.replace("https://www.gnu.org/licenses/gpl-3.0.en.html", "#gpl")
|
||||||
.replace("https://creativecommons.org/licenses/by-sa/4.0/", "#cc")
|
.replace(
|
||||||
|
"https://creativecommons.org/licenses/by-sa/4.0/", "#cc"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(navpoint.fix_path.fix_path("GPL-3.0.txt")) as f:
|
with open(navpoint.fix_path.fix_path("GPL-3.0.txt")) as f:
|
||||||
|
@ -20,11 +23,7 @@ def about():
|
||||||
with open(navpoint.fix_path.fix_path("CC-BY-SA-4.0.txt")) as f:
|
with open(navpoint.fix_path.fix_path("CC-BY-SA-4.0.txt")) as f:
|
||||||
cc = f.read()
|
cc = f.read()
|
||||||
|
|
||||||
fd, name = tempfile.mkstemp(suffix=".html")
|
self.write(
|
||||||
os.close(fd)
|
|
||||||
|
|
||||||
with open(name, "w") as f:
|
|
||||||
f.write(
|
|
||||||
f"""\
|
f"""\
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
@ -45,7 +44,19 @@ def about():
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
tornado.ioloop.IOLoop.instance().stop()
|
||||||
|
|
||||||
webbrowser.open(name)
|
|
||||||
time.sleep(5) # Give the browser time to open the file
|
def _run():
|
||||||
os.remove(name)
|
app = tornado.web.Application(
|
||||||
|
[
|
||||||
|
("/", AboutHandler),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
app.listen(9999, address="127.0.0.1")
|
||||||
|
tornado.ioloop.IOLoop.instance().start()
|
||||||
|
|
||||||
|
|
||||||
|
def about():
|
||||||
|
threading.Thread(target=_run).start()
|
||||||
|
webbrowser.open("http://127.0.0.1:9999/")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user