From 3ec43be650e10b8f8e8e8b18d4c7133766b2a520 Mon Sep 17 00:00:00 2001 From: ljf Date: Fri, 16 Aug 2019 19:44:19 +0200 Subject: [PATCH] [fix] Be able to call some repositories actions --- data/actionsmap/yunohost.yml | 17 +++++++++-------- src/yunohost/backup.py | 33 +++++++++++++++++++++++++++++++++ src/yunohost/repository.py | 12 +++++++----- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 5bbd6e0dd..b5cc4c575 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1039,19 +1039,20 @@ backup: add: action_help: Add a backup repository api: POST /backup/repository/ - configuration: - authenticate: all - authenticator: ldap-anonymous arguments: - path: - help: Path eventually on another server + location: + help: Location on this server or on an other extra: - pattern: *pattern_backup_repository_path + pattern: &pattern_backup_repository_location + - !!str ^((ssh://)?[a-z_]\w*@\[\w\-\.]+:)?(~?/)?[\w/]*$ + - "pattern_backup_repository_location" -n: full: --name help: Name of the repository extra: - pattern: *pattern_backup_repository_name + pattern: &pattern_backup_repository_name + - !!str ^\w+$ + - "pattern_backup_repository_name" -d: full: --description help: Short description of the repository @@ -1061,7 +1062,7 @@ backup: -q: full: --quota help: Quota to configure with this repository - --e: + -e: full: --encryption help: Type of encryption diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index d7a0fbafc..8f256491d 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -2571,6 +2571,39 @@ def backup_delete(name): logger.success(m18n.n('backup_deleted')) + +# +# Repository subcategory +# +import yunohost.repository + + +def backup_repository_list(full): + return yunohost.repository.backup_repository_list(full) + + +def backup_repository_info(name, human_readable, space_used): + return yunohost.repository.backup_repository_info(name, human_readable, space_used) + + +def backup_repository_add(location, name, description, methods, quota, encryption): + return yunohost.repository.backup_repository_add(location, name, description, methods, quota, encryption) + + +def backup_repository_update(name, description, quota, password): + return yunohost.repository.backup_repository_update(name, description, quota, password) + + +def backup_repository_remove(name, purge): + return yunohost.repository.backup_repository_remove(name, purge) + + + +# +# End Repository subcategory +# + + # # Misc helpers # # diff --git a/src/yunohost/repository.py b/src/yunohost/repository.py index d7b4f9742..cedafa8ae 100644 --- a/src/yunohost/repository.py +++ b/src/yunohost/repository.py @@ -32,13 +32,12 @@ from moulinette import msignals, m18n from moulinette.core import MoulinetteError from moulinette.utils import filesystem from moulinette.utils.log import getActionLogger -from moulinette.utils.filesystem import read_file, read_json, write_to_json +from moulinette.utils.filesystem import read_file, read_yaml, write_to_json from yunohost.utils.error import YunohostError from yunohost.monitor import binary_to_human from yunohost.log import OperationLogger, is_unit_operation -from yunohost.backup import BackupMethod logger = getActionLogger('yunohost.repository') REPOSITORIES_PATH = '/etc/yunohost/repositories.yml' @@ -75,7 +74,7 @@ class BackupRepository(object): if os.path.exists(REPOSITORIES_PATH): try: - cls.repositories = read_json(REPOSITORIES_PATH) + cls.repositories = read_yaml(REPOSITORIES_PATH)['repositories'] except MoulinetteError as e: raise YunohostError( 'backup_cant_open_repositories_file', reason=e) @@ -94,6 +93,7 @@ class BackupRepository(object): def __init__(self, created, location, name=None, description=None, method=None, encryption=None, quota=None): + from yunohost.backup import BackupMethod self.location = location self._split_location() @@ -154,7 +154,8 @@ class BackupRepository(object): self.domain = location_match.group('domain') self.path = location_match.group('path') -def backup_repository_list(name, full=False): + +def backup_repository_list(full=False): """ List available repositories where put archives """ @@ -165,6 +166,7 @@ def backup_repository_list(name, full=False): else: return repositories.keys() + def backup_repository_info(name, human_readable=True, space_used=False): """ Show info about a repository @@ -189,7 +191,7 @@ def backup_repository_info(name, human_readable=True, space_used=False): @is_unit_operation() def backup_repository_add(operation_logger, location, name, description=None, - methods=None, quota=None, encryption="passphrase"): + methods=None, quota=None, encryption="passphrase"): """ Add a backup repository