-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplitter.py
More file actions
51 lines (43 loc) · 2.7 KB
/
splitter.py
File metadata and controls
51 lines (43 loc) · 2.7 KB
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
'''Running the splitter by argument'''
from argparse import ArgumentParser, Namespace
from multiprocessing import freeze_support
from config import SOURCE_DIR, DESTINATION_DIR, TEMP_DIR, IMG_DIR, LOG_DIR, BACKUP_DIR
from src.main import PathConfig, run as run_by_arg_run
parser: ArgumentParser = ArgumentParser(
prog = "PDF Splitter",
description = "Split PDF files into individual pages and renames them by reading the barcode on each page" # pylint: disable=line-too-long
)
arg_list: list[list[any]] = [["-s","--source", str, "Directory containing PDF files"],
["-d", "--destination", str, "Directory to store output files"],
["-b", "--backup", str, "Directory to store backup files"],
["-l", "--log", str, "Directory to store log files"],
["-t", "--temp", str, "Temporary directory to store split PDF files"],
["-i", "--image", str, "Temporary directory to store the images"],
["-m", "--mode", str, "Mode of operation (single|multi), by default is single"], # pylint: disable=line-too-long
["-p", "--processes", int, "Maximum number of processes to run, by default is the number of CPU threads"], # pylint: disable=line-too-long
["-f", "--prefixes", str, "Prefixes for OCR reading if barcode not found (ex.: 'KSZ,EKSZ'), if left empty then OCR won't run"], # pylint: disable=line-too-long
["-r", "--ratio", float, "Image ratio to check for OCR, only neccessary if `--text-prefixes` is given (ex.: 0.4 means it scans from top to bottom 40%% of the image)"]] # pylint: disable=line-too-long
for arg in arg_list:
parser.add_argument(arg[0],
arg[1],
type = arg[2],
help = arg[3])
args: Namespace = parser.parse_args()
def main() -> None:
'''
Main function
'''
path_config: PathConfig = PathConfig(source = args.source or SOURCE_DIR,
destination = args.destination or DESTINATION_DIR,
temp = args.temp or TEMP_DIR,
image = args.image or IMG_DIR,
backup = args.backup or BACKUP_DIR,
log = args.log or LOG_DIR)
run_by_arg_run(path_config = path_config,
mode = args.mode,
max_processes = args.processes,
ocr_prefixes = args.prefixes,
ratio = args.ratio)
if __name__ == '__main__':
freeze_support()
main()