bumblebee-status/bumblebee_status/modules/contrib/yubikey.py

42 lines
1 KiB
Python
Raw Normal View History

2020-04-13 09:32:41 +02:00
# pylint: disable=C0111,R0903
"""Shows yubikey information
Requires: https://github.com/Yubico/python-yubico
The output indicates that a YubiKey is not connected or it displays
the corresponding serial number.
contributed by `EmmaTinten <https://github.com/EmmaTinten>`_ - many thanks!
2020-04-13 09:32:41 +02:00
"""
import yubico
2020-04-13 09:40:24 +02:00
import core.module
import core.widget
import core.decorators
2020-04-13 09:32:41 +02:00
2020-04-13 09:40:24 +02:00
class Module(core.module.Module):
@core.decorators.every(seconds=5)
def __init__(self, config, theme):
super().__init__(config, theme, core.widget.Widget(self.keystate))
self.__keystate = "No YubiKey"
2020-04-13 09:32:41 +02:00
def keystate(self, widget):
2020-04-13 09:40:24 +02:00
return self.__keystate
2020-04-13 09:32:41 +02:00
2020-04-13 09:40:24 +02:00
def update(self):
2020-04-13 09:32:41 +02:00
try:
self.__keystate = "YubiKey: " + str(
yubico.find_yubikey(debug=False).serial()
)
2020-04-13 09:32:41 +02:00
except yubico.yubico_exception.YubicoError:
2020-04-13 09:40:24 +02:00
self.__keystate = "No YubiKey"
except Exception:
self.__keystate = "n/a"
2020-04-13 09:32:41 +02:00
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4