Skip to content

Commit 27a3efa

Browse files
committed
Some fix and logs
1 parent a46e310 commit 27a3efa

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

Diff for: scan_to_paperless/process.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import matplotlib.pyplot as plt
2828
import numpy as np
2929
import pikepdf
30-
import ruamel.yaml.compat
3130
from deskew import determine_skew_debug_images
3231
from PIL import Image, ImageDraw, ImageFont
3332
from ruamel.yaml.main import YAML
@@ -74,13 +73,17 @@ async def add_intermediate_error(
7473
try:
7574
config["intermediate_error"].append({"error": str(error), "traceback": traceback_})
7675
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())
7879
except Exception as exception: # noqa: BLE001
7980
print(exception)
8081
config["intermediate_error"] = old_intermediate_error
8182
config["intermediate_error"].append({"error": str(error), "traceback": traceback_})
8283
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())
8487
temp_path.rename(config_file_name)
8588

8689

@@ -1981,7 +1984,9 @@ async def save_config(config: schema.Configuration, config_file_name: Path) -> N
19811984
yaml.default_flow_style = False
19821985
temp_path = Path(str(config_file_name) + "_")
19831986
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())
19851990
temp_path.rename(config_file_name)
19861991

19871992

@@ -2083,26 +2088,29 @@ async def _process(
20832088
yaml = YAML(typ="safe")
20842089
yaml.default_flow_style = False
20852090
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())
20902095
except Exception as exception2: # noqa: BLE001
20912096
print(exception2)
20922097
print(traceback.format_exc())
20932098
yaml = YAML()
20942099
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())
20992104
return dirty
21002105

21012106

21022107
async def _task(status: scan_to_paperless.status.Status) -> None:
21032108
while True:
21042109
status.set_current_folder(None)
2110+
# Be sure that the status is up to date
2111+
await asyncio.sleep(0.1)
21052112
name, job_type, step = status.get_next_job()
2113+
print(f"Processing '{name}' as {job_type}...")
21062114

21072115
if job_type in (
21082116
scan_to_paperless.status.JobType.TRANSFORM,
@@ -2183,6 +2191,8 @@ async def _task(status: scan_to_paperless.status.Status) -> None:
21832191
msg = f"Unknown job type: {job_type}"
21842192
raise ValueError(msg)
21852193

2194+
print(f"End processing '{name}' as {job_type}...")
2195+
21862196

21872197
def main() -> None:
21882198
"""Process the scanned documents."""

0 commit comments

Comments
 (0)