|
|
@@ -1,5 +1,7 @@
|
|
1
|
1
|
from __future__ import annotations
|
|
2
|
2
|
|
|
|
3
|
+import os
|
|
|
4
|
+import sys
|
|
3
|
5
|
from pathlib import Path
|
|
4
|
6
|
from typing import Annotated
|
|
5
|
7
|
|
|
|
@@ -15,23 +17,21 @@ from src.split.slicer import (
|
|
15
|
17
|
rotate_image,
|
|
16
|
18
|
)
|
|
17
|
19
|
|
|
18
|
|
-app = typer.Typer(add_completion=False)
|
|
|
20
|
+app = typer.Typer(add_completion=False, no_args_is_help=True)
|
|
19
|
21
|
|
|
20
|
22
|
|
|
21
|
23
|
@app.command()
|
|
22
|
24
|
def slice_pages(
|
|
23
|
25
|
input: Annotated[
|
|
24
|
|
- Path,
|
|
|
26
|
+ Path | None,
|
|
25
|
27
|
typer.Option(
|
|
26
|
28
|
"--input",
|
|
27
|
29
|
"-i",
|
|
28
|
|
- exists=True,
|
|
29
|
30
|
file_okay=True,
|
|
30
|
31
|
dir_okay=False,
|
|
31
|
|
- readable=True,
|
|
32
|
32
|
help="Путь к входному изображению (JPEG, PNG, TIFF)",
|
|
33
|
33
|
),
|
|
34
|
|
- ],
|
|
|
34
|
+ ] = None,
|
|
35
|
35
|
slice: Annotated[
|
|
36
|
36
|
str | None,
|
|
37
|
37
|
typer.Option(
|
|
|
@@ -86,6 +86,16 @@ def slice_pages(
|
|
86
|
86
|
] = False,
|
|
87
|
87
|
) -> None:
|
|
88
|
88
|
"""Разрезать отсканированное изображение на отдельные страницы по геометрической сетке."""
|
|
|
89
|
+ if input is None:
|
|
|
90
|
+ raise typer.BadParameter("Укажите путь к входному изображению", param_hint="--input")
|
|
|
91
|
+
|
|
|
92
|
+ if not input.exists():
|
|
|
93
|
+ raise typer.BadParameter(f"Файл не найден: {input}", param_hint="--input")
|
|
|
94
|
+ if not input.is_file():
|
|
|
95
|
+ raise typer.BadParameter(f"Не является файлом: {input}", param_hint="--input")
|
|
|
96
|
+ if not os.access(input, os.R_OK):
|
|
|
97
|
+ raise typer.BadParameter(f"Нет доступа на чтение: {input}", param_hint="--input")
|
|
|
98
|
+
|
|
89
|
99
|
if pre_rotate is not None and pre_rotate not in VALID_ROTATIONS:
|
|
90
|
100
|
raise typer.BadParameter(
|
|
91
|
101
|
f"Недопустимый угол: {pre_rotate}. Допустимые: {sorted(VALID_ROTATIONS)}"
|
|
|
@@ -124,6 +134,9 @@ def slice_pages(
|
|
124
|
134
|
|
|
125
|
135
|
|
|
126
|
136
|
def main() -> None:
|
|
|
137
|
+ if len(sys.argv) == 1:
|
|
|
138
|
+ app(["--help"], standalone_mode=False)
|
|
|
139
|
+ return
|
|
127
|
140
|
app()
|
|
128
|
141
|
|
|
129
|
142
|
|