Make neighbor card generation work in Python < 3.10 (#665)

Co-authored-by: Daniel Albert <esclear@users.noreply.github.com>
Co-authored-by: Johannes <johannes+develop+github@braun-rheingau.de>
This commit is contained in:
Daniel Albert
2023-01-04 21:18:38 +01:00
committed by GitHub
parent c692c7fb56
commit fa916931c1

View File

@@ -1,4 +1,3 @@
from itertools import pairwise
import secrets
import string
@@ -163,20 +162,18 @@ class LuiBackendConfig(object):
# parse cards
for card in self.get("cards"):
self._config_cards.append(Card(card))
# setup prev and next uuids
top_level_cards = filter(lambda card: not card.hidden, self._config_cards)
first_card = None
last_card = None
for cur, next in pairwise(top_level_cards):
if first_card is None:
first_card = cur
last_card = next
cur.uuid_next = next.uuid
next.uuid_prev = cur.uuid
# if there is only one top level card first and last card will be none
if first_card and last_card:
first_card.uuid_prev = last_card.uuid
last_card.uuid_next = first_card.uuid
top_level_cards = list(filter(lambda card: not card.hidden, self._config_cards))
card_ids = [card.id for card in top_level_cards]
prev_ids = card_ids[-1:] + card_ids[:-1]
next_ids = card_ids[ 1:] + card_ids[: 1]
if len(card_ids) > 1:
for prev_id, card, next_id in zip(prev_ids, top_level_cards, next_ids):
(card.uuid_prev, card.uuid_next) = (prev_id, next_id)
# parse screensaver
self._config_screensaver = Card(self.get("screensaver"))