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)
|
||||
]
|
||||
|
||||
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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)])
|
||||
|
|
10
scripts/fck
10
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")
|
||||
|
||||
|
|
Loading…
Reference in a new issue