From 3d4ec54b5f54f7783d5547d7d0fcde78a2381798 Mon Sep 17 00:00:00 2001 From: ljf Date: Fri, 31 Aug 2018 20:29:36 +0200 Subject: [PATCH] [fix] Purge option on removing repositories --- data/actionsmap/yunohost.yml | 3 +++ src/yunohost/repository.py | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 2e1b5b831..2ccc64243 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1008,6 +1008,9 @@ backup: help: Name of the backup repository to remove extra: pattern: *pattern_backup_repository_name + --purge: + help: Remove all archives and data inside repository + action: store_false ############################# # Monitor # diff --git a/src/yunohost/repository.py b/src/yunohost/repository.py index d07409d29..d3212b5ba 100644 --- a/src/yunohost/repository.py +++ b/src/yunohost/repository.py @@ -71,12 +71,13 @@ def backup_repository_info(name, human_readable=True, space_used=False): 'backup_repository_doesnt_exists', name=name)) if space_used: - logger.info("--space-used option not yet implemented") + try: + repository['used'] = _get_repository_used_space(name) if human_readable: if 'quota' in repository: repository['quota'] = binary_to_human(repository['quota']) - if 'used' in repository: + if 'used' in repository and isinstance(repository['used', int): repository['used'] = binary_to_human(repository['used']) return repository @@ -146,7 +147,7 @@ def backup_repository_update(operation_logger, name, description=None, path=repository['path'])) @is_unit_operation() -def backup_repository_remove(operation_logger, name): +def backup_repository_remove(operation_logger, name, purge=False): """ Remove a backup repository @@ -204,3 +205,16 @@ def _get_repositories(): exc_info=1) return repositories + + +def _get_repository_used_space(path, methods=None): + """ + Return the used space on a repository or 'unknown' if method don't support + this feature + + Keyword argument: + path -- Path of the repository + + """ + logger.info("--space-used option not yet implemented") + return 'unknown'