python qr

This commit is contained in:
elwrcl committed 2026-08-27 21:17:32 +03:00
1 parent f379e7368e
commit bc367e4f2e
1 file changed
+24 -17
+24 -17
View File
@@ -65,11 +65,33 @@
''; '';
}; };
panicInflate = pkgs.writers.writePython3Bin "drm-panic-inflate" {
flakeIgnore = [ "E501" ];
} ''
import sys
import zlib
data = sys.stdin.buffer.read()
if not data:
sys.exit("Could not read QR: try a clearer, straighter photo")
# Try raw deflate, then zlib-wrapped, then gzip.
for wbits in (-15, 15, 47):
try:
sys.stdout.buffer.write(zlib.decompress(data, wbits))
break
except zlib.error:
continue
else:
sys.stderr.write("warning: could not decompress, printing raw bytes\n")
sys.stdout.buffer.write(data)
'';
drmPanicDecode = pkgs.writeShellApplication { drmPanicDecode = pkgs.writeShellApplication {
name = "drm-panic-decode"; name = "drm-panic-decode";
runtimeInputs = [ runtimeInputs = [
pkgs.zbar pkgs.zbar
pkgs.python3 panicInflate
]; ];
text = '' text = ''
if [ "$#" -lt 1 ]; then if [ "$#" -lt 1 ]; then
@@ -77,22 +99,7 @@
exit 1 exit 1
fi fi
zbarimg --raw -q --oneshot -Sbinary "$1" | python3 -c ' zbarimg --raw -q --oneshot -Sbinary "$1" | drm-panic-inflate
import sys, zlib
data = sys.stdin.buffer.read()
if not data:
sys.exit("Could not read QR: try taking a clearer/straighter photo")
# Try raw deflate, zlib-wrapped, and gzip variants in order
for wbits in (-15, 15, 47):
try:
sys.stdout.buffer.write(zlib.decompress(data, wbits))
break
except zlib.error:
continue
else:
sys.stderr.write("warning: could not decompress, printing raw data\n")
sys.stdout.buffer.write(data)
'
''; '';
}; };
in in