fck/scripts/fck

51 lines
1.7 KiB
Python
Executable file

#!/usr/bin/env python3
"""
+---------------------------------+
| CRC32 sum generator CLI utility |
+---------------------------------+
"""
from typing import Optional
import argparse
from multiprocessing import Pool
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:
"""
Main function, should only run when programm gets directly invoked.
"""
parser = argparse.ArgumentParser(description="Calculate CRC32 of files")
parser.add_argument("-b", "--bigfiles",
help="parse files that exceed your memory limit",
action="store_true")
parser.add_argument("-p", "--processes",
help="",
default=2,
type=int)
parser.add_argument("-c", "--checksfv",
help="",
default="",
type=str)
parser.add_argument("files",
help="files and folders to process",
nargs='*',
default=[])
args = parser.parse_args()
file_list = fileutils.search(args.files)
ppool = Pool(processes=args.processes)
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")
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print("Exception: KeyboardInterrupt")