From 4d5020f2b96d93722447d30a715ec34906069f08 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Fri, 1 Mar 2024 01:41:24 +0100 Subject: [PATCH] winziprint.py: Fix list index out of range error --- src/winziprint.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/winziprint.py b/src/winziprint.py index 61d9521..f48d6b0 100755 --- a/src/winziprint.py +++ b/src/winziprint.py @@ -16,7 +16,7 @@ import weasyprint import pypdf -VERSION = __version__ = '0.2.0' +VERSION = __version__ = '0.2.1' SOCKET_ADDRESS = ('127.0.0.1', 30983) BATCH_SIZE = 10 @@ -41,7 +41,7 @@ def convert_part(output_file: str, batch: list[str], step_cb: Callable, encoding def convert(input_files: list[str], - output_files: str, + output_file: str, encoding: str = None, padding: bool = False, progress: bool = False, @@ -62,7 +62,7 @@ def convert(input_files: list[str], try: tmp_page_nums = [] for i in range(0, len(html_files), BATCH_SIZE): - tmp_file = f'{output_files}.{i:04}.part' + tmp_file = f'{output_file}.{i:04}.part' tmp_file_names.append(tmp_file) batch = html_files[i:i + BATCH_SIZE] tmp_page_nums += convert_part(tmp_file, batch, next_step, encoding=encoding) @@ -83,11 +83,11 @@ def convert(input_files: list[str], batch_page_nums = tmp_page_nums[i // BATCH_SIZE * BATCH_SIZE:(i // BATCH_SIZE + 1) * BATCH_SIZE] page_start = sum(batch_page_nums[:i % BATCH_SIZE]) if file_name.startswith('#'): - r = pypdf.PdfReader(tmp_file_names[n // BATCH_SIZE]) + r = pypdf.PdfReader(tmp_file_names[i // BATCH_SIZE]) letterhead = r.pages[0] del r else: - merger.append(tmp_file_names[n // BATCH_SIZE], pages=(page_start, page_start + tmp_page_nums[i])) + merger.append(tmp_file_names[i // BATCH_SIZE], pages=(page_start, page_start + tmp_page_nums[i])) i += 1 p1 = len(merger.pages) page_nums.append(p1 - p0) @@ -102,7 +102,7 @@ def convert(input_files: list[str], merger.insert_blank_page(index=1) page_nums.pop(0) page_nums.insert(0, 1) - merger.write(output_files) + merger.write(output_file) merger.close() del merger finally: @@ -145,7 +145,7 @@ def _wrapper_convert(args: list[str], total = sum(p + 1 if padding and p % 2 != 0 else p for p in pages) t1 = time.process_time() print(f'success: ' - f'{len(args) - 1} documents, ' + f'{len(inputs)} documents, ' f'{total} pages ({", ".join(str(p) for p in pages)}), ' f'{t1 - t0:.1f} sec', file=out, flush=True)