Skip to content

Commit

Permalink
admin: spears: Remove unused entries when updating from config
Browse files Browse the repository at this point in the history
  • Loading branch information
ximion committed May 9, 2024
1 parent 500dfc9 commit e7eb1c7
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/lkadmin/spears.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def _add_migration_task(repo_name: str, source_suites: T.List[str], target_suite
raise ValueError('The priority value "{}" is unknown!'.format(prio_name))
stask.delays[prio_name] = days

return stask.name


@spears.command()
def configure_all():
Expand Down Expand Up @@ -133,13 +135,26 @@ def remove_hint(source_suite, target_suite, hint):

@spears.command()
@click.argument('config_fname', nargs=1)
def add_from_config(config_fname):
def update_from_config(config_fname):
"""Add/update migration tasks from a TOML config file."""
from laniakea.db import SpearsMigrationTask

try:
with open(config_fname, 'r', encoding='utf-8') as f:
conf = tomlkit.load(f)
except Exception as e:
print_error_exit('Unable to load data from configuration file: {}'.format(str(e)))

for task_d in conf.get('MigrationTasks', []):
_add_migration_task(**task_d)
with session_scope() as session:
entries = session.query(SpearsMigrationTask).all()
known_tasks = {}
for e in entries:
known_tasks[e.name] = e

for task_d in conf.get('MigrationTasks', []):
task_name = _add_migration_task(**task_d)
known_tasks.pop(task_name)

# delete the remaining, orphaned entries
for task in known_tasks.values():
session.delete(task)

0 comments on commit e7eb1c7

Please sign in to comment.