Update pzztool.py

This commit is contained in:
tmpz23 2021-11-28 07:41:22 +01:00 committed by GitHub
parent fea899f380
commit 43f58389ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ from struct import unpack
from os import listdir from os import listdir
import logging import logging
__version__ = "0.14.2" __version__ = "0.14.3"
__author__ = "rigodron, algoflash, GGLinnk" __author__ = "rigodron, algoflash, GGLinnk"
__OriginalAutor__ = "infval" __OriginalAutor__ = "infval"
__license__ = "MIT" __license__ = "MIT"
@ -258,7 +258,7 @@ def pzz_pack(src_path: Path, dest_file: Path, auto_compress: bool = False):
if dest_file == Path('.'): if dest_file == Path('.'):
dest_file = src_path.with_suffix(".pzz") dest_file = src_path.with_suffix(".pzz")
if dest_file.suffix != ".pzz": if dest_file.suffix != ".pzz":
logging.warning("Invalid file format : dest must be a pzz") logging.warning(f"Invalid file format '{dest_file.suffix}' : dest must be a pzz")
# On récupère les fichiers du dossier à compresser # On récupère les fichiers du dossier à compresser
src_files = listdir(src_path) src_files = listdir(src_path)
@ -361,7 +361,9 @@ if __name__ == '__main__':
p_output = Path(p_input.with_suffix(".pzzp")) p_output = Path(p_input.with_suffix(".pzzp"))
# Si on a pas la bonne extension on ne compresse pas le fichier # Si on a pas la bonne extension on ne compresse pas le fichier
if not args.disable_ignore and p_output.suffix != ".pzzp": if not args.disable_ignore and p_input.suffix == ".pzzp":
logging.warning(f"Ignored - {p_input} - bad extension - must not be a pzzp")
elif not args.disable_ignore and p_output.suffix != ".pzzp":
logging.warning(f"Ignored - {p_output} - bad extension - must be a pzzp") logging.warning(f"Ignored - {p_output} - bad extension - must be a pzzp")
else: else:
logging.info(f"Compressing {p_input} in {p_output}") logging.info(f"Compressing {p_input} in {p_output}")
@ -381,6 +383,8 @@ if __name__ == '__main__':
p_output.write_bytes(output_file_content) p_output.write_bytes(output_file_content)
elif args.batch_compress: elif args.batch_compress:
logging.info("### Batch Compress") logging.info("### Batch Compress")
if(p_output == Path(".")):
p_output = Path(p_input)
p_output.mkdir(exist_ok=True) p_output.mkdir(exist_ok=True)
for filename in listdir(p_input): for filename in listdir(p_input):
@ -393,6 +397,8 @@ if __name__ == '__main__':
(p_output / (Path(filename).stem + ".pzzp")).write_bytes(pzz_compress((p_input / filename).read_bytes())) (p_output / (Path(filename).stem + ".pzzp")).write_bytes(pzz_compress((p_input / filename).read_bytes()))
elif args.batch_decompress: elif args.batch_decompress:
logging.info("### Batch Decompress") logging.info("### Batch Decompress")
if(p_output == Path(".")):
p_output = Path(p_input)
p_output.mkdir(exist_ok=True) p_output.mkdir(exist_ok=True)
for filename in listdir(p_input): for filename in listdir(p_input):