|
27 | 27 | import matplotlib.pyplot as plt
|
28 | 28 | import numpy as np
|
29 | 29 | import pikepdf
|
30 |
| -import ruamel.yaml.compat |
31 | 30 | from deskew import determine_skew_debug_images
|
32 | 31 | from PIL import Image, ImageDraw, ImageFont
|
33 | 32 | from ruamel.yaml.main import YAML
|
@@ -74,13 +73,17 @@ async def add_intermediate_error(
|
74 | 73 | try:
|
75 | 74 | config["intermediate_error"].append({"error": str(error), "traceback": traceback_})
|
76 | 75 | async with aiofiles.open(temp_path, "w", encoding="utf-8") as config_file:
|
77 |
| - await config_file.write(yaml.dump(config)) |
| 76 | + out = io.StringIO() |
| 77 | + yaml.dump(config, out) |
| 78 | + await config_file.write(out.getvalue()) |
78 | 79 | except Exception as exception: # noqa: BLE001
|
79 | 80 | print(exception)
|
80 | 81 | config["intermediate_error"] = old_intermediate_error
|
81 | 82 | config["intermediate_error"].append({"error": str(error), "traceback": traceback_})
|
82 | 83 | async with aiofiles.open(temp_path, "w", encoding="utf-8") as config_file:
|
83 |
| - await config_file.write(yaml.dump(config)) |
| 84 | + out = io.StringIO() |
| 85 | + yaml.dump(config, out) |
| 86 | + await config_file.write(out.getvalue()) |
84 | 87 | temp_path.rename(config_file_name)
|
85 | 88 |
|
86 | 89 |
|
@@ -1981,7 +1984,9 @@ async def save_config(config: schema.Configuration, config_file_name: Path) -> N
|
1981 | 1984 | yaml.default_flow_style = False
|
1982 | 1985 | temp_path = Path(str(config_file_name) + "_")
|
1983 | 1986 | async with aiofiles.open(temp_path, "w", encoding="utf-8") as config_file:
|
1984 |
| - await config_file.write(yaml.dump(config)) |
| 1987 | + out = io.StringIO() |
| 1988 | + yaml.dump(config, out) |
| 1989 | + await config_file.write(out.getvalue()) |
1985 | 1990 | temp_path.rename(config_file_name)
|
1986 | 1991 |
|
1987 | 1992 |
|
@@ -2083,26 +2088,29 @@ async def _process(
|
2083 | 2088 | yaml = YAML(typ="safe")
|
2084 | 2089 | yaml.default_flow_style = False
|
2085 | 2090 | try:
|
2086 |
| - with (root_folder / "error.yaml").open("w", encoding="utf-8") as error_file: |
2087 |
| - yaml.dump(out, error_file) |
2088 |
| - stream = ruamel.yaml.compat.StringIO() |
2089 |
| - yaml.dump(out, stream) |
| 2091 | + async with aiofiles.open(root_folder / "error.yaml", "w", encoding="utf-8") as error_file: |
| 2092 | + yaml_out = io.StringIO() |
| 2093 | + yaml.dump(out, yaml_out) |
| 2094 | + await error_file.write(yaml_out.getvalue()) |
2090 | 2095 | except Exception as exception2: # noqa: BLE001
|
2091 | 2096 | print(exception2)
|
2092 | 2097 | print(traceback.format_exc())
|
2093 | 2098 | yaml = YAML()
|
2094 | 2099 | yaml.default_flow_style = False
|
2095 |
| - with (root_folder / "error.yaml").open("w", encoding="utf-8") as error_file: |
2096 |
| - yaml.dump(out, error_file) |
2097 |
| - stream = ruamel.yaml.compat.StringIO() |
2098 |
| - yaml.dump(out, stream) |
| 2100 | + async with aiofiles.open(root_folder / "error.yaml", "w", encoding="utf-8") as error_file: |
| 2101 | + yaml_out = io.StringIO() |
| 2102 | + yaml.dump(out, yaml_out) |
| 2103 | + await error_file.write(yaml_out.getvalue()) |
2099 | 2104 | return dirty
|
2100 | 2105 |
|
2101 | 2106 |
|
2102 | 2107 | async def _task(status: scan_to_paperless.status.Status) -> None:
|
2103 | 2108 | while True:
|
2104 | 2109 | status.set_current_folder(None)
|
| 2110 | + # Be sure that the status is up to date |
| 2111 | + await asyncio.sleep(0.1) |
2105 | 2112 | name, job_type, step = status.get_next_job()
|
| 2113 | + print(f"Processing '{name}' as {job_type}...") |
2106 | 2114 |
|
2107 | 2115 | if job_type in (
|
2108 | 2116 | scan_to_paperless.status.JobType.TRANSFORM,
|
@@ -2183,6 +2191,8 @@ async def _task(status: scan_to_paperless.status.Status) -> None:
|
2183 | 2191 | msg = f"Unknown job type: {job_type}"
|
2184 | 2192 | raise ValueError(msg)
|
2185 | 2193 |
|
| 2194 | + print(f"End processing '{name}' as {job_type}...") |
| 2195 | + |
2186 | 2196 |
|
2187 | 2197 | def main() -> None:
|
2188 | 2198 | """Process the scanned documents."""
|
|
0 commit comments