cstype is no longer optional, update creation
This commit is contained in:
parent
360d36fa94
commit
0ad9ec320a
4 changed files with 21 additions and 12 deletions
|
@ -6,7 +6,8 @@ CKTYPES = [
|
||||||
(CRC32)
|
(CRC32)
|
||||||
]
|
]
|
||||||
|
|
||||||
def resolve(fname: str, esum: Optional[str] = None, cstype: Optional[str] = None):
|
|
||||||
|
def resolve(fname: str, esum: Optional[str] = None, cstype: str = ""):
|
||||||
"""
|
"""
|
||||||
Checks fname input for checksum pattern and returns first match.
|
Checks fname input for checksum pattern and returns first match.
|
||||||
Can be overridden with cstype.
|
Can be overridden with cstype.
|
||||||
|
|
|
@ -13,10 +13,11 @@ class FILE:
|
||||||
None: "\033[33m?\033[0m",
|
None: "\033[33m?\033[0m",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, fpath: str, esum: Optional[str] = None):
|
def __init__(self, fpath: str, esum: Optional[str] = None, cstype: str = ""):
|
||||||
self.fpath = fpath
|
self.fpath = fpath
|
||||||
self.fname = path.basename(fpath)
|
self.fname = path.basename(fpath)
|
||||||
self.csum, self.esum = cktype.resolve(self.fname, esum)
|
# TODO: Move out expected sum calculation
|
||||||
|
self.csum, self.esum = cktype.resolve(self.fname, esum, cstype)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.fname
|
return self.fname
|
||||||
|
|
|
@ -3,7 +3,13 @@ from os import listdir, path
|
||||||
from .file import FILE
|
from .file import FILE
|
||||||
|
|
||||||
|
|
||||||
def search(pathlist: List[str]) -> Generator[FILE, None, None]:
|
def new_file(fpath: str, cstype: str = "") -> FILE:
|
||||||
|
if path.isfile(fpath):
|
||||||
|
return FILE(path.realpath(fpath), None, cstype)
|
||||||
|
raise FileNotFoundError(fpath)
|
||||||
|
|
||||||
|
|
||||||
|
def search(pathlist: List[str]) -> Generator[str, None, None]:
|
||||||
"""
|
"""
|
||||||
Generate file paths from given list of Paths.
|
Generate file paths from given list of Paths.
|
||||||
|
|
||||||
|
@ -16,17 +22,14 @@ def search(pathlist: List[str]) -> Generator[FILE, None, None]:
|
||||||
+--------+
|
+--------+
|
||||||
| Yields |
|
| Yields |
|
||||||
---------+
|
---------+
|
||||||
| file: Tuple[(None, str)]
|
| file path string
|
||||||
| file is a Tuple containing:
|
|
||||||
| - a files path string
|
|
||||||
| - a crc32 sum (None if unknown)
|
|
||||||
"""
|
"""
|
||||||
for fpath in pathlist:
|
for fpath in pathlist:
|
||||||
if path.isfile(fpath):
|
if path.isfile(fpath):
|
||||||
if len(fpath) > 4 and fpath[-4:] == ".sfv":
|
if len(fpath) > 4 and fpath[-4:] == ".sfv":
|
||||||
yield from sfv_read(fpath)
|
yield from sfv_read(fpath)
|
||||||
else:
|
else:
|
||||||
yield FILE(path.realpath(fpath))
|
yield fpath
|
||||||
continue
|
continue
|
||||||
if path.isdir(fpath):
|
if path.isdir(fpath):
|
||||||
yield from search([path.join(fpath, x) for x in listdir(fpath)])
|
yield from search([path.join(fpath, x) for x in listdir(fpath)])
|
||||||
|
|
10
scripts/fck
10
scripts/fck
|
@ -5,10 +5,14 @@
|
||||||
+---------------------------------+
|
+---------------------------------+
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
import argparse
|
import argparse
|
||||||
from multiprocessing import Pool
|
from multiprocessing import Pool
|
||||||
from fck import checker, fileutils
|
from fck import fileutils
|
||||||
|
|
||||||
|
def check_file(path: str, bigfile: bool, cstype: str = "") -> Optional[bool]:
|
||||||
|
file = fileutils.new_file(path, cstype)
|
||||||
|
return file.check(bigfile)
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -34,8 +38,8 @@ def main() -> None:
|
||||||
|
|
||||||
file_list = fileutils.search(args.files)
|
file_list = fileutils.search(args.files)
|
||||||
ppool = Pool(processes=args.processes)
|
ppool = Pool(processes=args.processes)
|
||||||
file_list_checked = ppool.starmap(checker.check, [(x, args.bigfiles)
|
file_list_checked = ppool.starmap(check_file, [(fpath, args.bigfiles, args.type)
|
||||||
for x in list(file_list)])
|
for fpath in list(file_list)])
|
||||||
ppool.close()
|
ppool.close()
|
||||||
print(f"[{len([x for x in file_list_checked if x])}/{len(file_list_checked)}] Files passed")
|
print(f"[{len([x for x in file_list_checked if x])}/{len(file_list_checked)}] Files passed")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue