From 52f7d7fb68ab90c79f99c6c6348b84732593eef0 Mon Sep 17 00:00:00 2001 From: Niyaz Ahmad Date: Mon, 21 Nov 2022 17:17:54 +0530 Subject: [PATCH] Added cleanup option/arg. No cleanup by default. --- archive-org-downloader.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/archive-org-downloader.py b/archive-org-downloader.py index e9754be..58726e3 100644 --- a/archive-org-downloader.py +++ b/archive-org-downloader.py @@ -165,6 +165,7 @@ def make_pdf(pdf, title, directory): my_parser.add_argument('-r', '--resolution', help='Image resolution (10 to 0, 0 is the highest), [default 3]', type=int, default=3) my_parser.add_argument('-t', '--threads', help="Maximum number of threads, [default 50]", type=int, default=50) my_parser.add_argument('-j', '--jpg', help="Output to individual JPG's rather than a PDF", action='store_true') + my_parser.add_argument('-c', '--clean', help="Clean up downloaded files", type=str, default='No') if len(sys.argv) == 1: my_parser.print_help(sys.stderr) @@ -259,9 +260,14 @@ def make_pdf(pdf, title, directory): pdf = img2pdf.convert(images, **pdfmeta) make_pdf(pdf, title, args.dir if args.dir != None else "") - try: - shutil.rmtree(directory) - except OSError as e: - print ("Error: %s - %s." % (e.filename, e.strerror)) + if args.clean == "Yes": + print ("Clean up opted") + try: + print ("Removing downloaded files in %s" % (directory)) + shutil.rmtree(directory) + except OSError as e: + print ("Error: %s - %s." % (e.filename, e.strerror)) + else: + print ("Clean up not opted.\nLeaving downloaded files in %s" % (directory)) return_loan(session, book_id)