Simple/Complex templates / parsers

This commit is contained in:
Piotr Dec 2025-11-03 21:56:59 +01:00
parent e3a37419e8
commit 3dc27cc868
Signed by: stawros
GPG key ID: 74B18A3F0F1E99C0
4 changed files with 38 additions and 19 deletions

View file

@ -33,13 +33,27 @@ class Passwords:
output = {}
for k in keys:
key_parts = k.split(".")
path = key_parts[:-2] if len(key_parts) > 2 else None
path = key_parts[:-1] if len(key_parts) > 2 else None
entry_name = key_parts[-2]
field_name = key_parts[-1]
kp_entry = self._kp_org.find_entries(path=path, first=True, title=entry_name)[0]
output[k] = kp_entry[field_name] # TODO: TypeError: 'Entry' object is not subscriptable
kp_entry = self._kp_org.find_entries(path=path, first=True, title=entry_name)
output[k] = self._get_field_value(kp_entry, field_name)
return output
@staticmethod
def _get_field_value(kp_entry, field_name):
if kp_entry is None:
return None
match field_name:
case "username":
return kp_entry.username
case "password":
return kp_entry.password
case "url":
return kp_entry.url
case _:
return kp_entry.get_custom_property(field_name)
def save(self):
# nadpisz plik źródłowy zmianami z lock
self._kp.save()