修改部分代码格式

This commit is contained in:
virusdefender 2015-09-13 11:47:12 +08:00
parent 34246f7345
commit e6c9916a12
5 changed files with 23 additions and 18 deletions

1
.gitignore vendored
View File

@ -62,3 +62,4 @@ static/src/upload_image/*
build.txt
tmp/
test_case/
release/

View File

@ -34,7 +34,7 @@ REDIS_CACHE = {
DEBUG = True
# 同理 这是 web 服务器的上传路径
TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/')
TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/')
ALLOWED_HOSTS = []

View File

@ -5,7 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>青岛大学在线评测平台 - 首页</title>
<link rel="stylesheet" type="text/css" href="/static/css/fullpage/jquery.fullPage.css">
<link href="/static/css/fullpage/jquery.fullPage.css" rel="stylesheet">
<link rel="shortcut icon" href="/static/img/favicon.ico">
<style>
html, textarea, input, option, select, button {

View File

@ -86,10 +86,6 @@
<script src="/static/js/require.js"></script>
<script>
require(["bootstrap"]);
</script>
{% block js_block %}{% endblock %}
<!-- footer begin -->

View File

@ -20,32 +20,40 @@ shutil.rmtree(static_release_path)
# 复制一份静态文件文件夹到 release
shutil.copytree(static_src_path, static_release_path)
r = re.compile(r'<script src="(.+)"></script>')
js_re = re.compile(r'<script src="(.+)"></script>')
css_re = re.compile(r'<link href="(.+)" rel="stylesheet">')
name_map = {}
def do(match):
js_path = match.group(1).lstrip("/static/")
def process(match):
file_path = match.group(1).replace("/static/", "")
# print file_path, match.group(), match.group(1)
if not os.path.exists(static_release_path + js_path):
if not os.path.exists(static_release_path + file_path):
return match.group(0)
if js_path in name_map:
md5 = name_map[js_path]
if file_path in name_map:
md5 = name_map[file_path]
else:
# rename
md5 = hashlib.md5(open(static_release_path + js_path, "r").read()).hexdigest()
os.rename(static_release_path + js_path, static_release_path + js_path + "?v=" + md5)
return '<script src="%s"></script>' % (js_path + "?v=" + md5,)
md5 = hashlib.md5(open(static_release_path + file_path, "r").read()).hexdigest()
# os.rename(static_release_path + js_path, static_release_path + js_path + "?v=" + md5)
if ".js" in file_path:
return '<script src="/static/%s"></script>' % (file_path + "?v=" + md5[:6], )
elif ".css" in file_path:
return '<link rel="stylesheet" type="text/css" href="/static/%s">' % (file_path + "?v=" + md5[:6], )
else:
return match.group(0)
for root, dirs, files in os.walk(template_release_path):
for name in files:
html_path = os.path.join(root, name)
html_content = open(html_path, "r").read()
replaced_html_content = re.sub(r, do, html_content)
js_replaced_html_content = re.sub(js_re, process, html_content)
css_replaced_html_content = re.sub(css_re, process, js_replaced_html_content)
f = open(html_path, "w")
f.write(replaced_html_content)
f.write(css_replaced_html_content)
f.close()