lacre.admin: Add -r / --reload option to import command

With -r option, import command will first remove all identities and then load
them again from pubring.kbx.
This commit is contained in:
Piotr F. Mieszkowski 2023-12-05 21:49:23 +01:00
parent 94d0a62766
commit abaf8820d7
2 changed files with 13 additions and 1 deletions

View File

@ -70,6 +70,9 @@ def sub_import(args):
conn = repo.connect(conf.get_item('database', 'url'))
identities = repo.IdentityRepository(conn)
if args.reload:
identities.delete_all()
total = 0
for (fingerprint, email) in public.items():
LOG.debug('Importing %s - %s', email, fingerprint)
@ -97,7 +100,10 @@ def main():
cmd_import = sub_commands.add_parser('import',
help='Load identities from GnuPG directory to Lacre database'
)
cmd_import.add_argument('-d', '--homedir', help='specify GnuPG directory (default: use configured dir.)')
cmd_import.add_argument('-d', '--homedir', default=False,
help='specify GnuPG directory (default: use configured dir.)')
cmd_import.add_argument('-r', '--reload',
help='delete all keys from database before importing')
cmd_import.set_defaults(operation=sub_import)
cmd_queue = sub_commands.add_parser('queue',

View File

@ -71,6 +71,12 @@ class IdentityRepository(KeyRing):
self._conn.execute(delq)
def delete_all(self):
LOG.warn('Deleting all identities from the database')
delq = delete(self._identities)
self._conn.execute(delq)
def freeze_identities(self) -> KeyCache:
"""Return a static, async-safe copy of the identity map."""
self._ensure_connected()