Skip to content

Commit 17db2ec

Browse files
committed
Shift the image factory code to work with the output parameter
1 parent cd3cd7b commit 17db2ec

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

qrcode/console_scripts.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,28 @@ def raise_error(msg: str) -> NoReturn:
112112
else:
113113
qr.add_data(data, optimize=opts.optimize)
114114

115+
if image_factory is None and (os.isatty(sys.stdout.fileno()) or opts.ascii):
116+
qr.print_ascii(tty=not opts.ascii)
117+
return
118+
119+
kwargs = {}
120+
aliases: Optional[DrawerAliases] = getattr(qr.image_factory, "drawer_aliases", None)
121+
if opts.factory_drawer:
122+
if not aliases:
123+
raise_error("The selected factory has no drawer aliases.")
124+
if opts.factory_drawer not in aliases:
125+
raise_error(
126+
f"{opts.factory_drawer} factory drawer not found."
127+
f" Expected {commas(aliases)}"
128+
)
129+
drawer_cls, drawer_kwargs = aliases[opts.factory_drawer]
130+
kwargs["module_drawer"] = drawer_cls(**drawer_kwargs)
131+
115132
if opts.output:
116-
img = qr.make_image()
133+
img = qr.make_image(**kwargs)
117134
with open(opts.output, "wb") as out:
118135
img.save(out)
119136
else:
120-
if image_factory is None and (os.isatty(sys.stdout.fileno()) or opts.ascii):
121-
qr.print_ascii(tty=not opts.ascii)
122-
return
123-
124-
kwargs = {}
125-
aliases: Optional[DrawerAliases] = getattr(
126-
qr.image_factory, "drawer_aliases", None
127-
)
128-
if opts.factory_drawer:
129-
if not aliases:
130-
raise_error("The selected factory has no drawer aliases.")
131-
if opts.factory_drawer not in aliases:
132-
raise_error(
133-
f"{opts.factory_drawer} factory drawer not found."
134-
f" Expected {commas(aliases)}"
135-
)
136-
drawer_cls, drawer_kwargs = aliases[opts.factory_drawer]
137-
kwargs["module_drawer"] = drawer_cls(**drawer_kwargs)
138137
img = qr.make_image(**kwargs)
139138

140139
sys.stdout.flush()

0 commit comments

Comments
 (0)