From f6c6bfb61b930e2c83409260269ad05a1b8807b0 Mon Sep 17 00:00:00 2001 From: 2ndacc Date: Fri, 21 Feb 2020 16:28:39 +0800 Subject: [PATCH] pack js and css --- TC1/http_server/test.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/TC1/http_server/test.py b/TC1/http_server/test.py index 0a11be3..ba89c78 100644 --- a/TC1/http_server/test.py +++ b/TC1/http_server/test.py @@ -11,8 +11,7 @@ try: except: io = __import__("StringIO").StringIO -def gen(fn): - s = open(fn, 'rb').read() +def gen(s, fn): dat = io() with gzip.GzipFile(fileobj=dat, mode="w") as f: f.write(s) @@ -27,11 +26,15 @@ def gen(fn): fn = re.sub(r"[^\w]", "_", fn) print("const unsigned char %s[0x%x] = {\n%s};" % (fn, len(dat), s)) +def pack(path, name): + s = b'' + for fn in glob.glob(path): + s += ("/*%s*/\n" % fn).encode('utf-8') + s += open(fn, 'rb').read() + gen(s, name) + +pack('web/*.js', 'js_pack') +pack('web/*.css', 'css_pack') + for fn in glob.glob('web/*.html'): - gen(fn) - -for fn in glob.glob('web/*.js'): - gen(fn) - -for fn in glob.glob('web/*.css'): - gen(fn) + gen(open(fn, 'rb').read(), fn)