Update pzztest.py

gestion des tests :
    unpack / pack
    unpzz / pzz
-tbunpzzpzz :
ERROR - INVALID FILE : pl080d.pzz
Invalid files : 1/255
ERROR - INVALID FILE : pl080d.pzz
Invalid files : 1/255
This commit is contained in:
tmpz23 2021-11-20 14:03:30 +01:00 committed by GitHub
parent ad57860498
commit 5fe8aecfbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,12 +1,27 @@
import argparse import argparse
from pathlib import Path
import pzztool
import hashlib import hashlib
import os import os
from pathlib import Path
import pzztool
import shutil
TPL_MAGIC_FILE = b"\x00\x20\xAF\x30" # http://virtualre.rf.gd/index.php/TPL_(Format_de_fichier) TPL_MAGIC_FILE = b"\x00\x20\xAF\x30" # http://virtualre.rf.gd/index.php/TPL_(Format_de_fichier)
# compare le sha256 de chaque PZZ des dossiers passés en argument
# -> affiche le nom de fichier en cas de différence
def verify_sha256(folder1: Path, folder2: Path):
invalid_files_count = 0
for pzz_file_name in os.listdir(folder1):
with open(folder1 / pzz_file_name, "rb") as f1, open(folder2 / pzz_file_name, "rb") as f2:
if hashlib.sha256( f1.read() ).hexdigest() != hashlib.sha256( f2.read() ).hexdigest() :
print(f"ERROR - INVALID FILE : {pzz_file_name}")
invalid_files_count +=1
print(f"Invalid files : {invalid_files_count}/{len(os.listdir(folder1))}")
def get_argparser(): def get_argparser():
parser = argparse.ArgumentParser(description='TEST TOOL') parser = argparse.ArgumentParser(description='TEST TOOL')
parser.add_argument('input_path', metavar='INPUT', help='') parser.add_argument('input_path', metavar='INPUT', help='')
@ -15,17 +30,22 @@ def get_argparser():
group.add_argument('-tdc', '--test-decompress-compress', action='store_true', help="") group.add_argument('-tdc', '--test-decompress-compress', action='store_true', help="")
group.add_argument('-tbup', '--test-batch-unpack-pack', action='store_true', help=""" group.add_argument('-tbup', '--test-batch-unpack-pack', action='store_true', help="""
-tbup source_pzz_folder -tbup source_pzz_folder
source_pzz_folder : put all pzz in this folder source_pzz_folder : put all pzz in this folder
pzzu : will be created with all unpacked pzz from pzz folder pzzu : will be created with all unpacked pzz from pzz folder
pzz2 : will be created with all packed pzz from pzzu folder pzz2 : will be created with all packed pzz from pzzu folder
then it will print the file name when file sha256 is different between source_pzz_folder and pzz2 folder""") print file_name when sha256 is different between source_pzz_folder and pzz2 folder""")
group.add_argument('-tbunpzzpzz', '--test-batch-unpzz-pzz', action='store_true', help="""
-tbunpzzpzz source_pzz_folder
source_pzz_folder : put all pzz in this folder
pzzu : will be created with all unpzz pzz from pzz folder
pzz2 : will be created with all pzz(pzz_folder) from pzzu folder
print file_name when sha256 is different between source_pzz_folder and pzz2 folder""")
group.add_argument('-tctplh', '--test-check-tpl-headers', action='store_true', help="-tctplh afs_data_folder : check all files headers in the afs_data and print those who have the tpl magicfile") group.add_argument('-tctplh', '--test-check-tpl-headers', action='store_true', help="-tctplh afs_data_folder : check all files headers in the afs_data and print those who have the tpl magicfile")
group.add_argument('-td', '--test-decompress', action='store_true', help=""" group.add_argument('-td', '--test-decompress', action='store_true', help="""
pzz : put all pzz in this folder pzz : put all pzz in this folder
then tip "pzztool.py -td" then tip "pzztool.py -td"
decompressed_tpl_files : will be created with all decompressed files from pzzu having the tpl header decompressed_tpl_files : will be created with all decompressed files from pzzu having the tpl header
The script will then check that tpls are correctly decompressed with their specific characteristics""") The script will then check that tpls are correctly decompressed with their specific characteristics""")
return parser return parser
@ -54,18 +74,34 @@ if __name__ == '__main__':
for invalid in listofinvalid: for invalid in listofinvalid:
print(invalid) print(invalid)
elif args.test_batch_unpack_pack: elif args.test_batch_unpack_pack:
# compare le sha256 de chaque PZZ du dossier passé en argument et pzz2 puis affiche le nom de fichier en cas de différence
print("# TEST : BATCH UNPACK PACK") print("# TEST : BATCH UNPACK PACK")
os.system(f"python pzztool.py -bu {args.input_path} pzzu -v")
os.system("python pzztool.py -bp pzzu pzz2 -v")
invalid_files_count = 0 os.system(f"python pzztool.py -bu {args.input_path} pzzu")
for pzz_file_name in os.listdir(p_input): os.system("python pzztool.py -bp pzzu pzz2")
with open(p_input / pzz_file_name, "rb") as f1, open(f"pzz2/{pzz_file_name}", "rb") as f2: verify_sha256(p_input, Path("pzz2"))
if hashlib.sha256( f1.read() ).hexdigest() != hashlib.sha256( f2.read() ).hexdigest() : elif args.test_batch_unpzz_pzz:
print(f"ERROR - INVALID FILE : {pzz_file_name}") os.system(f"python pzztool.py -bunpzz {args.input_path} pzzu")
invalid_files_count +=1 os.system("python pzztool.py -bpzz pzzu pzz2")
print(f"Invalid files : {invalid_files_count}/{len(os.listdir(p_input))}") verify_sha256(p_input, Path("pzz2"))
# Clean du dossier pzz2 généré par le script
shutil.rmtree("pzz2")
"""
si pzz : U -> decomp / testé sur les fichiers car l'unpzz décompresse par défaut
si pzz : U -> comp / à tester
si pzz : C -> decomp / testé sur les fichiers car l'unpzz décompresse par défaut
si pzz : C -> comp / à tester
"""
# On parcours tous les dossiers : si U -> comp ; si C -> comp : compression de tous les fichiers peu importe le type
for pzz_folder in os.listdir("pzzu"):
for pzz_file_part_name in os.listdir("pzzu/"+pzz_folder):
# créé un nouveau fichier compressé, à côté de l'original
os.system(f"python pzztool.py -c pzzu/{pzz_folder}/{pzz_file_part_name}")
# supprime l'original
os.remove(f"pzzu/{pzz_folder}/{pzz_file_part_name}")
os.system("python pzztool.py -bpzz pzzu pzz2")
verify_sha256(p_input, Path("pzz2"))
elif args.test_check_tpl_headers: elif args.test_check_tpl_headers:
# Démontre que SEUL les TPLs ont ce magicfile # Démontre que SEUL les TPLs ont ce magicfile
# TEST OK # TEST OK