@@ -27,7 +27,7 @@ def spears():
27
27
'''Configure automatic package migration.'''
28
28
29
29
30
- def _add_migration_task (repo_name : str , source_suites : T .List [str ], target_suite : str , delays : dict [str , int ]):
30
+ def _add_migration_task (repo_name : str , source_suites : T .List [str ], target_suite : str , delays : dict [str , int ]) -> str :
31
31
"""Add or update a migration task."""
32
32
33
33
from laniakea .db import ChangesUrgency , SpearsMigrationTask
@@ -58,6 +58,8 @@ def _add_migration_task(repo_name: str, source_suites: T.List[str], target_suite
58
58
raise ValueError ('The priority value "{}" is unknown!' .format (prio_name ))
59
59
stask .delays [prio_name ] = days
60
60
61
+ return stask .make_migration_unique_name ()
62
+
61
63
62
64
@spears .command ()
63
65
def configure_all ():
@@ -133,13 +135,26 @@ def remove_hint(source_suite, target_suite, hint):
133
135
134
136
@spears .command ()
135
137
@click .argument ('config_fname' , nargs = 1 )
136
- def add_from_config (config_fname ):
138
+ def update_from_config (config_fname ):
137
139
"""Add/update migration tasks from a TOML config file."""
140
+ from laniakea .db import SpearsMigrationTask
141
+
138
142
try :
139
143
with open (config_fname , 'r' , encoding = 'utf-8' ) as f :
140
144
conf = tomlkit .load (f )
141
145
except Exception as e :
142
146
print_error_exit ('Unable to load data from configuration file: {}' .format (str (e )))
143
147
144
- for task_d in conf .get ('MigrationTasks' , []):
145
- _add_migration_task (** task_d )
148
+ with session_scope () as session :
149
+ entries = session .query (SpearsMigrationTask ).all ()
150
+ known_tasks = {}
151
+ for e in entries :
152
+ known_tasks [e .make_migration_unique_name ()] = e
153
+
154
+ for task_d in conf .get ('MigrationTasks' , []):
155
+ unq_name = _add_migration_task (** task_d )
156
+ known_tasks .pop (unq_name )
157
+
158
+ # delete the remaining, orphaned entries
159
+ for task in known_tasks .values ():
160
+ session .delete (task )
0 commit comments