diff --git a/fck/cktype/__init__.py b/fck/cktype/__init__.py index 807210d..43058e5 100644 --- a/fck/cktype/__init__.py +++ b/fck/cktype/__init__.py @@ -6,7 +6,8 @@ CKTYPES = [ (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. Can be overridden with cstype. diff --git a/fck/file.py b/fck/file.py index c53f669..6e39160 100644 --- a/fck/file.py +++ b/fck/file.py @@ -13,10 +13,11 @@ class FILE: 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.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): return self.fname diff --git a/fck/fileutils.py b/fck/fileutils.py index ed88883..6318ede 100644 --- a/fck/fileutils.py +++ b/fck/fileutils.py @@ -3,7 +3,13 @@ from os import listdir, path 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. @@ -16,17 +22,14 @@ def search(pathlist: List[str]) -> Generator[FILE, None, None]: +--------+ | Yields | ---------+ - | file: Tuple[(None, str)] - | file is a Tuple containing: - | - a files path string - | - a crc32 sum (None if unknown) + | file path string """ for fpath in pathlist: if path.isfile(fpath): if len(fpath) > 4 and fpath[-4:] == ".sfv": yield from sfv_read(fpath) else: - yield FILE(path.realpath(fpath)) + yield fpath continue if path.isdir(fpath): yield from search([path.join(fpath, x) for x in listdir(fpath)]) diff --git a/scripts/fck b/scripts/fck index 815269c..bf97aa0 100755 --- a/scripts/fck +++ b/scripts/fck @@ -5,10 +5,14 @@ +---------------------------------+ """ +from typing import Optional import argparse 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: """ @@ -34,8 +38,8 @@ def main() -> None: file_list = fileutils.search(args.files) ppool = Pool(processes=args.processes) - file_list_checked = ppool.starmap(checker.check, [(x, args.bigfiles) - for x in list(file_list)]) + file_list_checked = ppool.starmap(check_file, [(fpath, args.bigfiles, args.type) + for fpath in list(file_list)]) ppool.close() print(f"[{len([x for x in file_list_checked if x])}/{len(file_list_checked)}] Files passed")