mirror of
https://github.com/elwrcl/copnix.git
synced 2026-10-31 14:28:02 +03:00
python qr
This commit is contained in:
1 file changed
+24
-17
@@ -65,24 +65,17 @@
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
drmPanicDecode = pkgs.writeShellApplication {
|
panicInflate = pkgs.writers.writePython3Bin "drm-panic-inflate" {
|
||||||
name = "drm-panic-decode";
|
flakeIgnore = [ "E501" ];
|
||||||
runtimeInputs = [
|
} ''
|
||||||
pkgs.zbar
|
import sys
|
||||||
pkgs.python3
|
import zlib
|
||||||
];
|
|
||||||
text = ''
|
|
||||||
if [ "$#" -lt 1 ]; then
|
|
||||||
echo "usage: drm-panic-decode <panic-screen-photo>" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
zbarimg --raw -q --oneshot -Sbinary "$1" | python3 -c '
|
|
||||||
import sys, zlib
|
|
||||||
data = sys.stdin.buffer.read()
|
data = sys.stdin.buffer.read()
|
||||||
if not data:
|
if not data:
|
||||||
sys.exit("Could not read QR: try taking a clearer/straighter photo")
|
sys.exit("Could not read QR: try a clearer, straighter photo")
|
||||||
# Try raw deflate, zlib-wrapped, and gzip variants in order
|
|
||||||
|
# Try raw deflate, then zlib-wrapped, then gzip.
|
||||||
for wbits in (-15, 15, 47):
|
for wbits in (-15, 15, 47):
|
||||||
try:
|
try:
|
||||||
sys.stdout.buffer.write(zlib.decompress(data, wbits))
|
sys.stdout.buffer.write(zlib.decompress(data, wbits))
|
||||||
@@ -90,9 +83,23 @@ for wbits in (-15, 15, 47):
|
|||||||
except zlib.error:
|
except zlib.error:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
sys.stderr.write("warning: could not decompress, printing raw data\n")
|
sys.stderr.write("warning: could not decompress, printing raw bytes\n")
|
||||||
sys.stdout.buffer.write(data)
|
sys.stdout.buffer.write(data)
|
||||||
'
|
'';
|
||||||
|
|
||||||
|
drmPanicDecode = pkgs.writeShellApplication {
|
||||||
|
name = "drm-panic-decode";
|
||||||
|
runtimeInputs = [
|
||||||
|
pkgs.zbar
|
||||||
|
panicInflate
|
||||||
|
];
|
||||||
|
text = ''
|
||||||
|
if [ "$#" -lt 1 ]; then
|
||||||
|
echo "usage: drm-panic-decode <panic-screen-photo>" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
zbarimg --raw -q --oneshot -Sbinary "$1" | drm-panic-inflate
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|||||||
Reference in new issue
Block a user