提交 6bc40f6e 编写于 作者: P Peter Pan

fix: clean static files when exit

上级 3c13916a
......@@ -104,8 +104,7 @@ setup(
long_description_content_type='text/markdown',
install_requires=REQUIRED_PACKAGES,
package_data={
'visualdl.server': [('dist' + ('/*' * n)) for n in range(1, 20)] + [('static' + ('/*' * n)) for n in
range(1, 20)],
'visualdl.server': [('dist' + ('/*' * n)) for n in range(1, 20)],
'visualdl.python': ['dog.jpg', 'testing.wav']
},
packages=find_packages(),
......
......@@ -19,6 +19,7 @@ import json
import os
import time
import sys
import signal
import multiprocessing
import threading
import re
......@@ -387,19 +388,27 @@ def run(logdir,
return p.pid
def main():
args = parse_args()
def render_template(args):
template.render(
template_file_path,
static_file_path,
PUBLIC_PATH=args.public_path.strip('/'))
logger.info(" port=" + str(args.port))
app = create_app(args=args)
app.run(debug=False, host=args.host, port=args.port, threaded=False)
if __name__ == "__main__":
def clean_template(signalnum, frame):
template.clean(static_file_path)
sys.exit(0)
def main():
args = parse_args()
render_template(args)
for sig in [signal.SIGINT, signal.SIGHUP, signal.SIGTERM]:
signal.signal(sig, clean_template)
logger.info(" port=" + str(args.port))
app = create_app(args=args)
app.run(debug=False, host=args.host, port=args.port, threaded=False)
if __name__ == "__main__":
main()
......@@ -18,8 +18,7 @@ from shutil import (copytree, rmtree)
def render(path, dest, **context):
if os.path.exists(dest):
rmtree(dest)
clean(dest)
copytree(path, dest)
for root, dirs, files in os.walk(dest):
for file in files:
......@@ -32,3 +31,8 @@ def render(path, dest, **context):
content = content.replace("{{" + key + "}}", value)
with open(file_path, "w") as f:
f.write(content)
def clean(path):
if os.path.exists(path):
rmtree(path)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册