mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Be able to list only pending or done migrations
This commit is contained in:
parent
c568b04459
commit
c266147fd9
3 changed files with 32 additions and 12 deletions
|
@ -1575,6 +1575,13 @@ tools:
|
|||
list:
|
||||
action_help: List migrations
|
||||
api: GET /migrations
|
||||
arguments:
|
||||
--pending:
|
||||
help: list only pending migrations
|
||||
action: store_true
|
||||
--done:
|
||||
help: list only migrations already performed
|
||||
action: store_true
|
||||
|
||||
### tools_migrations_migrate()
|
||||
migrate:
|
||||
|
|
|
@ -230,6 +230,7 @@
|
|||
"migrations_current_target": "Migration target is {}",
|
||||
"migrations_error_failed_to_load_migration": "ERROR: failed to load migration {migration_id}",
|
||||
"migrations_forward": "Migrating forward",
|
||||
"migrations_list_conflict_pending_done": "You cannot use both --previous and --done at the same time.",
|
||||
"migrations_loading_migration": "Loading migration {migration_id}...",
|
||||
"migrations_migration_has_failed": "Migration {number} {name} has failed with exception {exception}, aborting",
|
||||
"migrations_no_migrations_to_run": "No migrations to run",
|
||||
|
|
|
@ -733,24 +733,36 @@ def tools_reboot(force=False):
|
|||
subprocess.check_call(['systemctl', 'reboot'])
|
||||
|
||||
|
||||
def tools_migrations_list():
|
||||
def tools_migrations_list(pending=False, done=False):
|
||||
"""
|
||||
List existing migrations
|
||||
"""
|
||||
|
||||
migrations = {"migrations": []}
|
||||
# Check for option conflict
|
||||
if pending and done:
|
||||
raise MoulinetteError(errno.EINVAL, m18n.n("migrations_list_conflict_pending_done"))
|
||||
|
||||
for migration in _get_migrations_list():
|
||||
migrations["migrations"].append({
|
||||
"id": migration.id,
|
||||
# Get all migrations
|
||||
migrations = _get_migrations_list()
|
||||
|
||||
# If asked, filter pending or done migrations
|
||||
if pending or done:
|
||||
last_migration = tools_migrations_state()["last_run_migration"]
|
||||
last_migration = last_migration["number"] if last_migration else -1
|
||||
if done:
|
||||
migrations = [m for m in migrations if m.number <= last_migration]
|
||||
if pending:
|
||||
migrations = [m for m in migrations if m.number > last_migration]
|
||||
|
||||
# Reduce to dictionnaries
|
||||
migrations = [{ "id": migration.id,
|
||||
"number": migration.number,
|
||||
"name": migration.name,
|
||||
"mode": migration.mode,
|
||||
"description": migration.description,
|
||||
"disclaimer": migration.disclaimer
|
||||
})
|
||||
"disclaimer": migration.disclaimer } for migration in migrations ]
|
||||
|
||||
return migrations
|
||||
return {"migrations": migrations}
|
||||
|
||||
|
||||
def tools_migrations_migrate(target=None, skip=False, auto=False):
|
||||
|
|
Loading…
Add table
Reference in a new issue