summaryrefslogtreecommitdiff
path: root/bin
diff options
authorJonathan Cave <jonathan.cave@canonical.com>2020-11-13 14:54:35 +0000
committerJonathan Cave <jonathan.cave@canonical.com>2020-11-13 14:54:35 +0000
commit1a8d22521219cb2708eda343cdbd73ce362dc8b8 (patch)
treecf0bc217abd879e6b014ef91f1f8e7dab621754c /bin
parentbdc86628231781b858ebae9f06d5f9701de3c3d9 (diff)
roundtrip_qr.py: detect the active tty
UC20 seems to deviate from the norm of tty1 being the active tty after install. Update the script to detect which is active.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/roundtrip_qr.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/bin/roundtrip_qr.py b/bin/roundtrip_qr.py
index e2eb5b5..c3494e2 100755
--- a/bin/roundtrip_qr.py
+++ b/bin/roundtrip_qr.py
@@ -61,8 +61,14 @@ def generate_qr_code(data):
return pyqrcode.create(data)
-def display_code(qr):
- with open('/dev/tty1', 'wb+', buffering=0) as term:
+def get_active_tty():
+ with open('/sys/class/tty/tty0/active', 'r') as active_f:
+ return active_f.read().strip()
+
+
+def display_code(qr, tty):
+ device = '/dev/{}'.format(tty)
+ with open(device, 'wb+', buffering=0) as term:
# clear the tty so the qr is always printed at the top of the sceen
term.write(str.encode('\033c'))
# print the qr code
@@ -98,8 +104,15 @@ def main():
print('Generating QR code...', flush=True)
qr = generate_qr_code(test_str)
+ tty = 'tty1'
+ try:
+ tty = get_active_tty()
+ print('Identified {} as the active vt'.format(tty))
+ except IOError:
+ print('Failed to read active tty, using default {}'.format(tty))
+
print('Displaying on screen', flush=True)
- display_code(qr)
+ display_code(qr, tty)
print('Capture image of screen', flush=True)
if name == 'vchiq':