mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
scripts: waifulib: zip: add support for passing compression level on Python 3.7. Exclude PNG files from compression
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# encoding: utf-8
|
||||
|
||||
from waflib import TaskGen, Task, Logs, Utils
|
||||
import zipfile
|
||||
import zipfile, sys
|
||||
|
||||
class ziparchive(Task.Task):
|
||||
color = 'YELLOW'
|
||||
@@ -17,15 +17,25 @@ class ziparchive(Task.Task):
|
||||
|
||||
def run(self):
|
||||
outfile = self.outputs[0].abspath()
|
||||
comp = zipfile.ZIP_STORED if self.compresslevel == 0 else zipfile.ZIP_DEFLATED
|
||||
kwargs = {}
|
||||
kwargs['mode'] = 'w'
|
||||
kwargs['compression'] = zipfile.ZIP_STORED if self.compresslevel == 0 else zipfile.ZIP_DEFLATED
|
||||
|
||||
with zipfile.ZipFile(outfile, mode='w', compression=comp) as zf:
|
||||
if sys.hexversion >= 0x3070000:
|
||||
kwargs['compresslevel'] = self.compresslevel
|
||||
|
||||
with zipfile.ZipFile(outfile, **kwargs) as zf:
|
||||
for src in self.inputs:
|
||||
infile = src.path_from(src.ctx.launch_node())
|
||||
arcfile = src.path_from(self.relative_to)
|
||||
|
||||
# TODO: pass excluded list from TaskGen
|
||||
Logs.debug('%s: %s <- %s as %s', self.__class__.__name__, outfile, infile, arcfile)
|
||||
zf.write(infile, arcfile)
|
||||
|
||||
if infile.endswith('.png'):
|
||||
zf.write(infile, arcfile, zipfile.ZIP_STORED)
|
||||
else:
|
||||
zf.write(infile, arcfile)
|
||||
|
||||
@TaskGen.feature('zip')
|
||||
def create_zip_archive(self):
|
||||
|
||||
Reference in New Issue
Block a user