abort instead of assertion

This commit is contained in:
scito 2023-01-01 19:55:28 +01:00
parent 8545dab7a5
commit e177f860e1
2 changed files with 5 additions and 7 deletions

View file

@ -57,7 +57,7 @@ cd extract_otp_secret_keys
## Program help: arguments and options ## Program help: arguments and options
<pre>usage: extract_otp_secrets.py [-h] [--camera NUMBER] [--qr {QREADER,DEEP_QREADER,ZBAR,CV2,WECHAT}] [--json FILE] [--csv FILE] [--keepass FILE] [--printqr] [--saveqr DIR] [--verbose | --quiet] [infile ...] <pre>usage: extract_otp_secrets.py [-h] [--camera NUMBER] [--qr {QREADER,DEEP_QREADER,ZBAR,CV2,CV2_WECHAT}] [--json FILE] [--csv FILE] [--keepass FILE] [--printqr] [--saveqr DIR] [--no-color] [--verbose | --quiet] [infile ...]
Extracts one time password (OTP) secret keys from QR codes, e.g. from Google Authenticator app. Extracts one time password (OTP) secret keys from QR codes, e.g. from Google Authenticator app.
If no infiles are provided, the QR codes are interactively captured from the camera. If no infiles are provided, the QR codes are interactively captured from the camera.
@ -69,13 +69,14 @@ positional arguments:
options: options:
-h, --help show this help message and exit -h, --help show this help message and exit
--camera NUMBER, -C NUMBER camera number of system (default camera: 0) --camera NUMBER, -C NUMBER camera number of system (default camera: 0)
--qr {QREADER,DEEP_QREADER,ZBAR,CV2,WECHAT}, -Q {QREADER,DEEP_QREADER,ZBAR,CV2,WECHAT} --qr {QREADER,DEEP_QREADER,ZBAR,CV2,CV2_WECHAT}, -Q {QREADER,DEEP_QREADER,ZBAR,CV2,CV2_WECHAT}
QR reader (default: ZBAR) QR reader (default: ZBAR)
--json FILE, -j FILE export json file or - for stdout --json FILE, -j FILE export json file or - for stdout
--csv FILE, -c FILE export csv file or - for stdout --csv FILE, -c FILE export csv file or - for stdout
--keepass FILE, -k FILE export totp/hotp csv file(s) for KeePass, - for stdout --keepass FILE, -k FILE export totp/hotp csv file(s) for KeePass, - for stdout
--printqr, -p print QR code(s) as text to the terminal (requires qrcode module) --printqr, -p print QR code(s) as text to the terminal (requires qrcode module)
--saveqr DIR, -s DIR save QR code(s) as images to the given folder (requires qrcode module) --saveqr DIR, -s DIR save QR code(s) as images to the given folder (requires qrcode module)
--no-color, -n do not use ANSI colors in console output
--verbose, -v verbose output --verbose, -v verbose output
--quiet, -q no stdout output, except output set by - --quiet, -q no stdout output, except output set by -

View file

@ -253,7 +253,7 @@ def extract_otps_from_camera(args: Args) -> Otps:
success, img = cam.read() success, img = cam.read()
new_otps_count = 0 new_otps_count = 0
if not success: if not success:
log_error("Failed to capture image") log_error("Failed to capture image from camera")
break break
try: try:
if qr_mode in [QRMode.QREADER, QRMode.DEEP_QREADER]: if qr_mode in [QRMode.QREADER, QRMode.DEEP_QREADER]:
@ -281,10 +281,7 @@ def extract_otps_from_camera(args: Args) -> Otps:
new_otps_count = extract_otps_from_otp_url(otp_url, otp_urls, otps, args) new_otps_count = extract_otps_from_otp_url(otp_url, otp_urls, otps, args)
cv2_draw_box(img, raw_pts, get_color(new_otps_count, otp_url)) cv2_draw_box(img, raw_pts, get_color(new_otps_count, otp_url))
else: else:
assert False, f"Wrong QReader mode {qr_mode.name}" abort(f"Invalid QReader mode: {qr_mode.name}")
except AssertionError as e:
# Exceptions not to log, but to pass further
raise e
except Exception as e: except Exception as e:
log_error(f'An error occured during QR detection and decoding for QR reader {qr_mode}. Changed to the next QR reader.', e) log_error(f'An error occured during QR detection and decoding for QR reader {qr_mode}. Changed to the next QR reader.', e)
qr_mode = next_qr_mode(qr_mode) qr_mode = next_qr_mode(qr_mode)