mirror of
https://github.com/Virtual-World-RE/NeoGF.git
synced 2024-11-15 08:45:33 +01:00
Update gcmtest.py
free space security check
This commit is contained in:
parent
bedf0784d6
commit
1a4c369684
42
gcmtest.py
42
gcmtest.py
|
@ -5,7 +5,7 @@ import shutil
|
|||
from time import time
|
||||
|
||||
|
||||
__version__ = "0.0.5"
|
||||
__version__ = "0.0.6"
|
||||
__author__ = "rigodron, algoflash, GGLinnk"
|
||||
__license__ = "MIT"
|
||||
__status__ = "developpement"
|
||||
|
@ -26,6 +26,12 @@ repack_path = Path("repack")
|
|||
# if there is a way to create symlinks on GCM filesystem, it could create strange situations
|
||||
|
||||
|
||||
def test_storage():
|
||||
total, used, free = shutil.disk_usage("/")
|
||||
if free - 10**12 < 3 * sum(path.stat().st_size for path in roms_path.glob('*') if path.is_file()):
|
||||
raise Exception("Error - Not enought free space on the disk to run tests.")
|
||||
|
||||
|
||||
def print_paths_differences(folder1_paths:list, folder2_paths:list):
|
||||
backup_paths = folder2_paths.copy()
|
||||
for path in folder1_paths:
|
||||
|
@ -34,10 +40,10 @@ def print_paths_differences(folder1_paths:list, folder2_paths:list):
|
|||
for path in backup_paths:
|
||||
if path in folder1_paths:
|
||||
folder1_paths.remove(path)
|
||||
print("folder1 diff :")
|
||||
print("folder1 diff:")
|
||||
for path in folder1_paths:
|
||||
print(path)
|
||||
print("folder2 diff :")
|
||||
print("folder2 diff:")
|
||||
for path in folder2_paths:
|
||||
print(path)
|
||||
|
||||
|
@ -64,7 +70,7 @@ def compare_GCM(folder1: Path, folder2: Path):
|
|||
folder1_file_count = len(folder1_root_paths)
|
||||
print(f"compare \"{folder1}\" - \"{folder2}\" ({folder1_file_count} files)")
|
||||
if folder1_file_count == 0:
|
||||
raise Exception(f"ERROR - EMPTY FOLDER: {folder1}")
|
||||
raise Exception(f"Error - Empty folder: {folder1}")
|
||||
|
||||
len1 = len(folder1.parts)
|
||||
len2 = len(folder2.parts)
|
||||
|
@ -73,18 +79,18 @@ def compare_GCM(folder1: Path, folder2: Path):
|
|||
folder2_paths = [Path(*path.parts[len2:]) for path in (folder2 / "root").glob('**/*')]
|
||||
if folder1_paths != folder2_paths:
|
||||
print_paths_differences(folder1_paths, folder2_paths)
|
||||
raise Exception(f"Folders \"{folder1}\" and \"{folder2}\" are different (not the same folders or files names).")
|
||||
raise Exception(f"Error - Folders \"{folder1}\" and \"{folder2}\" are different (not the same folders or files names).")
|
||||
# 2. Compare sys files content
|
||||
if not compare_files(folder1/"sys"/"apploader.img", folder2/"sys"/"apploader.img"):
|
||||
raise Exception(f"\"{folder1}/sys/apploader.bin\" and \"{folder2}/sys/apploader.bin\" are different.")
|
||||
if not compare_files(folder1/"sys"/"boot.dol", folder2/"sys"/"boot.dol"):
|
||||
raise Exception(f"\"{folder1}/sys/boot.bin\" and \"{folder2}/sys/boot.bin\" are different.")
|
||||
if not compare_files(folder1 / "sys" / "apploader.img", folder2 / "sys" / "apploader.img"):
|
||||
raise Exception(f"Error - \"{folder1 / 'sys/apploader.bin'}\" and \"{folder2 / 'sys/apploader.bin'}\" are different.")
|
||||
if not compare_files(folder1 / "sys" / "boot.dol", folder2 / "sys" / "boot.dol"):
|
||||
raise Exception(f"Error - \"{folder1 / 'sys/boot.bin'}\" and \"{folder2 / 'sys/boot.bin'}\" are different.")
|
||||
|
||||
for path1 in folder1_root_paths:
|
||||
if path1.is_file():
|
||||
path2 = folder2/Path(*path1.parts[len1:])
|
||||
if not compare_files(path1, path2):
|
||||
raise Exception(f"\"{path1}/\" and \"{path2}\" are different.")
|
||||
raise Exception(f"Error - \"{path1}\" and \"{path2}\" are different.")
|
||||
|
||||
|
||||
##################################################
|
||||
|
@ -92,15 +98,17 @@ def compare_GCM(folder1: Path, folder2: Path):
|
|||
##################################################
|
||||
def gcmtool_unpack(iso_path:Path, folder_path:Path):
|
||||
if os.system(f"python gcmtool.py -u \"{iso_path}\" \"{folder_path}\"") != 0:
|
||||
raise Exception("Error while unpacking gcm.")
|
||||
raise Exception("Error while unpacking GCM.")
|
||||
def gcmtool_pack(folder_path:Path, iso_path:Path):
|
||||
if os.system(f"python gcmtool.py -p \"{folder_path}\" \"{iso_path}\"") != 0:
|
||||
raise Exception("Error while packing gcm.")
|
||||
raise Exception("Error while packing GCM.")
|
||||
def gcmtool_rebuild_fst(folder_path:Path):
|
||||
if os.system(f"python gcmtool.py -r \"{folder_path}\"") != 0:
|
||||
raise Exception("Error while rebuilding FST.")
|
||||
|
||||
|
||||
TEST_COUNT = 3
|
||||
|
||||
start = time()
|
||||
print("###############################################################################")
|
||||
print("# Checking tests folder")
|
||||
|
@ -109,8 +117,10 @@ print("#########################################################################
|
|||
if unpack_path.is_dir() or unpack2_path.is_dir() or repack_path.is_dir():
|
||||
raise Exception(f"Error - Please remove:\n-{unpack_path}\n-{unpack2_path}\n-{repack_path}")
|
||||
|
||||
test_storage()
|
||||
|
||||
print("###############################################################################")
|
||||
print("# TEST 1/3")
|
||||
print(f"# TEST 1/{TEST_COUNT}")
|
||||
print("# Comparing roms_path->unpack->[unpack_path] ROMs with [dolphin_unpack_path]")
|
||||
print("###############################################################################")
|
||||
# unpack ROM in unpack_path
|
||||
|
@ -124,7 +134,7 @@ for folder_path in unpack_path.glob("*"):
|
|||
compare_GCM(folder_path, dolphin_unpack_path / folder_path.name)
|
||||
|
||||
print("###############################################################################")
|
||||
print("# TEST 2/3")
|
||||
print(f"# TEST 2/{TEST_COUNT}")
|
||||
print("# Comparing [unpack_path]->pack->unpack->[unpack2_path]")
|
||||
print("###############################################################################")
|
||||
# repack unpack_path repack_path
|
||||
|
@ -149,7 +159,7 @@ for folder_path in unpack_paths:
|
|||
shutil.rmtree(unpack2_path)
|
||||
|
||||
print("###############################################################################")
|
||||
print("# TEST 3/3")
|
||||
print(f"# TEST 3/{TEST_COUNT}")
|
||||
print("# Comparing [unpack_path]->rebuild_fst->repack->unpack->[unpack2_path]")
|
||||
print("###############################################################################")
|
||||
# rebuild unpack_path FSTs
|
||||
|
@ -183,5 +193,5 @@ shutil.rmtree(unpack2_path)
|
|||
|
||||
end = time()
|
||||
print("###############################################################################")
|
||||
print(f"# All tests are OK - elapsed time : {end - start}")
|
||||
print(f"# All tests are OK - elapsed time: {end - start}")
|
||||
print("###############################################################################")
|
||||
|
|
Loading…
Reference in New Issue
Block a user