mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
When splitting via barcodes, cleanup the split documents better
This commit is contained in:
parent
1d5eb983ea
commit
8b3d01c49b
@ -325,11 +325,10 @@ def save_to_dir(
|
|||||||
Optionally rename the file.
|
Optionally rename the file.
|
||||||
"""
|
"""
|
||||||
if os.path.isfile(filepath) and os.path.isdir(target_dir):
|
if os.path.isfile(filepath) and os.path.isdir(target_dir):
|
||||||
dst = shutil.copy(filepath, target_dir)
|
dest = target_dir
|
||||||
logging.debug(f"saved {str(filepath)} to {str(dst)}")
|
if newname is not None:
|
||||||
if newname:
|
dest = os.path.join(dest, newname)
|
||||||
dst_new = os.path.join(target_dir, newname)
|
shutil.copy(filepath, dest)
|
||||||
logger.debug(f"moving {str(dst)} to {str(dst_new)}")
|
logging.debug(f"saved {str(filepath)} to {str(dest)}")
|
||||||
os.rename(dst, dst_new)
|
|
||||||
else:
|
else:
|
||||||
logger.warning(f"{str(filepath)} or {str(target_dir)} don't exist.")
|
logger.warning(f"{str(filepath)} or {str(target_dir)} don't exist.")
|
||||||
|
@ -128,13 +128,6 @@ def consume_file(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if document_list:
|
if document_list:
|
||||||
for n, document in enumerate(document_list):
|
|
||||||
# save to consumption dir
|
|
||||||
# rename it to the original filename with number prefix
|
|
||||||
if override_filename:
|
|
||||||
newname = f"{str(n)}_" + override_filename
|
|
||||||
else:
|
|
||||||
newname = None
|
|
||||||
|
|
||||||
# If the file is an upload, it's in the scratch directory
|
# If the file is an upload, it's in the scratch directory
|
||||||
# Move it to consume directory to be picked up
|
# Move it to consume directory to be picked up
|
||||||
@ -147,12 +140,26 @@ def consume_file(
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
save_to_dir = path.parent
|
save_to_dir = path.parent
|
||||||
|
|
||||||
|
for n, document in enumerate(document_list):
|
||||||
|
# save to consumption dir
|
||||||
|
# rename it to the original filename with number prefix
|
||||||
|
if override_filename:
|
||||||
|
newname = f"{str(n)}_" + override_filename
|
||||||
|
else:
|
||||||
|
newname = None
|
||||||
|
|
||||||
barcodes.save_to_dir(
|
barcodes.save_to_dir(
|
||||||
document,
|
document,
|
||||||
newname=newname,
|
newname=newname,
|
||||||
target_dir=save_to_dir,
|
target_dir=save_to_dir,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Split file has been copied safely, remove it
|
||||||
|
os.remove(document)
|
||||||
|
|
||||||
|
# And clean up the directory as well, now it's empty
|
||||||
|
shutil.rmtree(os.path.dirname(document_list[0]))
|
||||||
|
|
||||||
# Delete the PDF file which was split
|
# Delete the PDF file which was split
|
||||||
os.remove(doc_barcode_info.pdf_path)
|
os.remove(doc_barcode_info.pdf_path)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user