From d77aa0b1673139b766f4dafbaedc4dba6ec045d6 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 27 Feb 2024 22:33:57 +0100 Subject: [PATCH] Removed legacy `backend.scard`. Closes: #303 --- docs/source/backends.rst | 1 - docs/source/platypush/backend/scard.rst | 6 -- platypush/backend/scard/__init__.py | 87 ------------------------- platypush/backend/scard/manifest.yaml | 17 ----- 4 files changed, 111 deletions(-) delete mode 100644 docs/source/platypush/backend/scard.rst delete mode 100644 platypush/backend/scard/__init__.py delete mode 100644 platypush/backend/scard/manifest.yaml diff --git a/docs/source/backends.rst b/docs/source/backends.rst index c69afb069..e7aad8389 100644 --- a/docs/source/backends.rst +++ b/docs/source/backends.rst @@ -15,7 +15,6 @@ Backends platypush/backend/music.spotify.rst platypush/backend/nodered.rst platypush/backend/redis.rst - platypush/backend/scard.rst platypush/backend/sensor.ir.zeroborg.rst platypush/backend/sensor.leap.rst platypush/backend/stt.deepspeech.rst diff --git a/docs/source/platypush/backend/scard.rst b/docs/source/platypush/backend/scard.rst deleted file mode 100644 index 59c23f7cf..000000000 --- a/docs/source/platypush/backend/scard.rst +++ /dev/null @@ -1,6 +0,0 @@ -``scard`` -=========================== - -.. automodule:: platypush.backend.scard - :members: - diff --git a/platypush/backend/scard/__init__.py b/platypush/backend/scard/__init__.py deleted file mode 100644 index 210467bb3..000000000 --- a/platypush/backend/scard/__init__.py +++ /dev/null @@ -1,87 +0,0 @@ -from platypush.backend import Backend -from platypush.message.event.scard import SmartCardDetectedEvent, SmartCardRemovedEvent - - -class ScardBackend(Backend): - """ - Generic backend to read smart cards and NFC tags and trigger an event - whenever a device is detected. - - Extend this backend to implement more advanced communication with custom - smart cards. - """ - - def __init__(self, atr=None, *args, **kwargs): - """ - :param atr: If set, the backend will trigger events only for card(s) - with the specified ATR(s). It can be either an ATR string - (space-separated hex octects) or a list of ATR strings. Default: - none (any card will be detected). - """ - - from smartcard.CardType import AnyCardType, ATRCardType - - super().__init__(*args, **kwargs) - self.ATRs = [] - - if atr: - if isinstance(atr, str): - self.ATRs = [atr] - elif isinstance(atr, list): - self.ATRs = atr - else: - raise RuntimeError( - f"Unsupported ATR: \"{atr}\" - type: {type(atr)}, " - + "supported types: string, list" - ) - - self.cardtype = ATRCardType(*[self._to_bytes(atr) for atr in self.ATRs]) - else: - self.cardtype = AnyCardType() - - @staticmethod - def _to_bytes(data) -> bytes: - if isinstance(data, str): - data = data.encode() - return data - - def run(self): - from smartcard.CardRequest import CardRequest - from smartcard.Exceptions import NoCardException, CardConnectionException - from smartcard.util import toHexString - - super().run() - - self.logger.info( - 'Initialized smart card reader backend - ATR filter: {}'.format(self.ATRs) - ) - - prev_atr = None - reader = None - - while not self.should_stop(): - try: - cardrequest = CardRequest(timeout=None, cardType=self.cardtype) - cardservice = cardrequest.waitforcard() - cardservice.connection.connect() - - reader = cardservice.connection.getReader() - atr = toHexString(cardservice.connection.getATR()) - - if atr != prev_atr: - self.logger.info( - 'Smart card detected on reader {}, ATR: {}'.format(reader, atr) - ) - - self.bus.post(SmartCardDetectedEvent(atr=atr, reader=reader)) - prev_atr = atr - except Exception as e: - if isinstance(e, (NoCardException, CardConnectionException)): - self.bus.post(SmartCardRemovedEvent(atr=prev_atr, reader=reader)) - else: - self.logger.exception(e) - - prev_atr = None - - -# vim:sw=4:ts=4:et: diff --git a/platypush/backend/scard/manifest.yaml b/platypush/backend/scard/manifest.yaml deleted file mode 100644 index 97164d685..000000000 --- a/platypush/backend/scard/manifest.yaml +++ /dev/null @@ -1,17 +0,0 @@ -manifest: - events: - platypush.message.event.scard.SmartCardDetectedEvent: when a smart card is detected - platypush.message.event.scard.SmartCardRemovedEvent: when a smart card is removed - install: - apk: - - py3-pyscard - apt: - - python3-pyscard - dnf: - - python-pyscard - pacman: - - python-pyscard - pip: - - pyscard - package: platypush.backend.scard - type: backend