From bad7612027f013e1c5054cdd564e4cf31bcbe05f Mon Sep 17 00:00:00 2001 From: Esa Kataja Date: Tue, 3 Dec 2024 20:55:56 +0200 Subject: [PATCH] feat: Add cleanup of temporary files in finalize command - Remove all temporary PNG files after PDF creation - Remove temporary directory - Update command feedback messages --- pdf_cleaner.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pdf_cleaner.py b/pdf_cleaner.py index 57a2a74..3bb3463 100755 --- a/pdf_cleaner.py +++ b/pdf_cleaner.py @@ -120,7 +120,8 @@ def deskew(): @cli.command() @click.argument('output_pdf', type=click.Path()) def finalize(output_pdf): - """Combine processed pages into final PDF.""" + """Combine processed pages into final PDF and clean up.""" + temp_dir = ensure_temp_dir() temp_files = get_temp_files() if not temp_files: print("No pages found in temporary directory. Run 'extract' first.") @@ -132,8 +133,13 @@ def finalize(output_pdf): with open(output_pdf, "wb") as f: f.write(img2pdf.convert(temp_files)) - print("PDF created successfully!") - print("Note: Temporary files were kept for further processing if needed.") + # Clean up temporary files + print("Cleaning up temporary files...") + for file_path in temp_files: + os.remove(file_path) + os.rmdir(temp_dir) + + print("PDF created successfully and temporary files removed!") if __name__ == '__main__': cli()