home
·
contact
·
privacy
projects
/
bookmaker
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0819ce9
)
Only import what's needed.
master
author
Plom Heller
<plom@plomlompom.com>
Sun, 5 Apr 2026 21:52:22 +0000
(23:52 +0200)
committer
Plom Heller
<plom@plomlompom.com>
Sun, 5 Apr 2026 21:52:22 +0000
(23:52 +0200)
bookmaker.py
patch
|
blob
|
history
diff --git
a/bookmaker.py
b/bookmaker.py
index b60576de6bd8794b4e60f066dcf38acdd5c48fcf..66cc6b3f3bbdfa67556e0892dd817463c61df07c 100755
(executable)
--- a/
bookmaker.py
+++ b/
bookmaker.py
@@
-4,10
+4,14
@@
bookmaker.py helps optimizing PDFs for the production of small self-printed,
self-bound physical books; towards this goal offers various PDF manipulation
options that may also be used indepéndently and for other purposes.
"""
self-bound physical books; towards this goal offers various PDF manipulation
options that may also be used indepéndently and for other purposes.
"""
-import argparse
-import io
-import os
-import sys
+from argparse import (
+ ArgumentParser,
+ Namespace as ArgsNamespace,
+ RawDescriptionHelpFormatter
+ )
+from io import BufferedReader, BytesIO
+from os.path import isfile
+from sys import exit as sys_exit
from typing import Any, Optional
from typing import Any, Optional
@@
-16,7
+20,7
@@
def handled_error_exit(
) -> None:
'Print msg, then exit(1).'
print(f'ERROR: {msg}')
) -> None:
'Print msg, then exit(1).'
print(f'ERROR: {msg}')
- sys
.
exit(1)
+ sys
_
exit(1)
try:
try:
@@
-138,14
+142,14
@@
class ArgFail(Exception):
def parse_args(
def parse_args(
- ) ->
argparse.
Namespace:
+ ) ->
Args
Namespace:
'Collect command line arguments.'
help_epilogue = ('See README.txt for detailed usage instructions, '
'command examples, etc.')
'Collect command line arguments.'
help_epilogue = ('See README.txt for detailed usage instructions, '
'command examples, etc.')
- parser =
argparse.
ArgumentParser(
+ parser = ArgumentParser(
description=__doc__,
epilog=help_epilogue,
description=__doc__,
epilog=help_epilogue,
- formatter_class=
argparse.
RawDescriptionHelpFormatter)
+ formatter_class=RawDescriptionHelpFormatter)
parser.add_argument('-i',
'--input_file',
action='append',
parser.add_argument('-i',
'--input_file',
action='append',
@@
-200,7
+204,7
@@
def parse_args(
def validate_args_syntax(
def validate_args_syntax(
- args:
argparse.
Namespace
+ args:
Args
Namespace
) -> None:
'Check command args against general syntax expectations.'
) -> None:
'Check command args against general syntax expectations.'
@@
-315,13
+319,13
@@
def parse_page_range(
def args_to_pagelist(
args_input_file: list[str],
args_page_range: list[str]
def args_to_pagelist(
args_input_file: list[str],
args_page_range: list[str]
- ) -> tuple[list[pypdf.PageObject], list[
io.
BufferedReader]]:
+ ) -> tuple[list[pypdf.PageObject], list[BufferedReader]]:
'Follow args_input_file ranged by args_page_range into pages, open files.'
pages_to_add = []
opened_files = []
new_page_num = 0
for i, filename in enumerate(args_input_file):
'Follow args_input_file ranged by args_page_range into pages, open files.'
pages_to_add = []
opened_files = []
new_page_num = 0
for i, filename in enumerate(args_input_file):
- if not
os.path.
isfile(filename):
+ if not isfile(filename):
raise ArgFail('i', f'{filename} is not a file')
file = open(filename, 'rb')
opened_files += [file]
raise ArgFail('i', f'{filename} is not a file')
file = open(filename, 'rb')
opened_files += [file]
@@
-349,7
+353,7
@@
def args_to_pagelist(
def validate_ranges(
def validate_ranges(
- args:
argparse.
Namespace,
+ args:
Args
Namespace,
pages_to_add: list[pypdf.PageObject]
) -> None:
'Check command args\' ranges fit into pages_to_add count.'
pages_to_add: list[pypdf.PageObject]
) -> None:
'Check command args\' ranges fit into pages_to_add count.'
@@
-600,7
+604,7
@@
def ornate_nup4(
'Apply nup4 line guides onto new_page.'
if args_analyze:
# borders
'Apply nup4 line guides onto new_page.'
if args_analyze:
# borders
- packet =
io.
BytesIO()
+ packet = BytesIO()
c = canvas_class(packet, pagesize=A4)
c.setLineWidth(0.1)
c.line(0, A4_HEIGHT, A4_WIDTH, A4_HEIGHT)
c = canvas_class(packet, pagesize=A4)
c.setLineWidth(0.1)
c.line(0, A4_HEIGHT, A4_WIDTH, A4_HEIGHT)
@@
-621,7
+625,7
@@
def ornate_nup4(
x_left_spine_limit = A4_HALF_WIDTH * nup4_geometry.shrink_for_spine
x_right_spine_limit = A4_WIDTH - x_left_spine_limit
if args_analyze or is_front_page:
x_left_spine_limit = A4_HALF_WIDTH * nup4_geometry.shrink_for_spine
x_right_spine_limit = A4_WIDTH - x_left_spine_limit
if args_analyze or is_front_page:
- packet =
io.
BytesIO()
+ packet = BytesIO()
c = canvas_class(packet, pagesize=A4)
if args_analyze:
# spine lines
c = canvas_class(packet, pagesize=A4)
if args_analyze:
# spine lines