-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (45 loc) · 1.84 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
debug = False
from gui import SilkyArcToolGUI
def test(mode: str) -> None:
"""Test the program. Pick one of the mods:
{"unpack", "pack", "decompress", "compress", "compare_dirs", "compare_files"}"""
import filecmp
import os
from silky_arc import SilkyArc
arc_file = 'Script.arc'
true_arc_file = 'Script.arc_good'
folder = 'Script'
etalon = "_good"
good_folder = folder + etalon
comp_file = 'AP_SCENE_01.MES_i'
dec_file = "AP_SCENE_01.MES_o"
true_comp_file = 'AP_SCENE_01.MES_gi'
true_dec_file = "AP_SCENE_01.MES_go"
if mode == "unpack":
arc_archive = SilkyArc(arc_file, folder, integrity_check=True)
arc_archive.unpack()
elif mode == "pack":
arc_archive = SilkyArc(arc_file, folder, integrity_check=True)
arc_archive.pack()
elif mode == "decompress":
with open(comp_file, 'rb') as iner, open(dec_file, 'wb') as outer:
outer.write(SilkyArc.lzss_decompress(iner.read()))
print(filecmp.cmp(dec_file, true_dec_file, shallow=False))
elif mode == "compress":
with open(comp_file, 'wb') as outer, open(dec_file, 'rb') as iner:
outer.write(SilkyArc.lzss_compress(iner.read()))
print(filecmp.cmp(comp_file, true_comp_file, shallow=False))
elif mode == "compare_dirs":
for root, dirs, files in os.walk(folder):
for file in files:
if not filecmp.cmp(os.path.join(folder, file), os.path.join(good_folder, file), shallow=False):
print(file)
elif mode == "compare_files":
print("Равны ль файлы? Ответ: {}".format(filecmp.cmp(arc_file, true_arc_file)))
def main():
new_gui = SilkyArcToolGUI()
if __name__ == '__main__':
if debug:
test("compare_files")
else:
main()