[fix] Be able to call some repositories actions

This commit is contained in:
ljf 2019-08-16 19:44:19 +02:00
parent f46160da64
commit 3ec43be650
3 changed files with 49 additions and 13 deletions

View file

@ -1039,19 +1039,20 @@ backup:
add: add:
action_help: Add a backup repository action_help: Add a backup repository
api: POST /backup/repository/<name> api: POST /backup/repository/<name>
configuration:
authenticate: all
authenticator: ldap-anonymous
arguments: arguments:
path: location:
help: Path eventually on another server help: Location on this server or on an other
extra: extra:
pattern: *pattern_backup_repository_path pattern: &pattern_backup_repository_location
- !!str ^((ssh://)?[a-z_]\w*@\[\w\-\.]+:)?(~?/)?[\w/]*$
- "pattern_backup_repository_location"
-n: -n:
full: --name full: --name
help: Name of the repository help: Name of the repository
extra: extra:
pattern: *pattern_backup_repository_name pattern: &pattern_backup_repository_name
- !!str ^\w+$
- "pattern_backup_repository_name"
-d: -d:
full: --description full: --description
help: Short description of the repository help: Short description of the repository
@ -1061,7 +1062,7 @@ backup:
-q: -q:
full: --quota full: --quota
help: Quota to configure with this repository help: Quota to configure with this repository
--e: -e:
full: --encryption full: --encryption
help: Type of encryption help: Type of encryption

View file

@ -2571,6 +2571,39 @@ def backup_delete(name):
logger.success(m18n.n('backup_deleted')) 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 # # Misc helpers #
# #

View file

@ -32,13 +32,12 @@ from moulinette import msignals, m18n
from moulinette.core import MoulinetteError from moulinette.core import MoulinetteError
from moulinette.utils import filesystem from moulinette.utils import filesystem
from moulinette.utils.log import getActionLogger 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.utils.error import YunohostError
from yunohost.monitor import binary_to_human from yunohost.monitor import binary_to_human
from yunohost.log import OperationLogger, is_unit_operation from yunohost.log import OperationLogger, is_unit_operation
from yunohost.backup import BackupMethod
logger = getActionLogger('yunohost.repository') logger = getActionLogger('yunohost.repository')
REPOSITORIES_PATH = '/etc/yunohost/repositories.yml' REPOSITORIES_PATH = '/etc/yunohost/repositories.yml'
@ -75,7 +74,7 @@ class BackupRepository(object):
if os.path.exists(REPOSITORIES_PATH): if os.path.exists(REPOSITORIES_PATH):
try: try:
cls.repositories = read_json(REPOSITORIES_PATH) cls.repositories = read_yaml(REPOSITORIES_PATH)['repositories']
except MoulinetteError as e: except MoulinetteError as e:
raise YunohostError( raise YunohostError(
'backup_cant_open_repositories_file', reason=e) '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, def __init__(self, created, location, name=None, description=None, method=None,
encryption=None, quota=None): encryption=None, quota=None):
from yunohost.backup import BackupMethod
self.location = location self.location = location
self._split_location() self._split_location()
@ -154,7 +154,8 @@ class BackupRepository(object):
self.domain = location_match.group('domain') self.domain = location_match.group('domain')
self.path = location_match.group('path') 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 List available repositories where put archives
""" """
@ -165,6 +166,7 @@ def backup_repository_list(name, full=False):
else: else:
return repositories.keys() return repositories.keys()
def backup_repository_info(name, human_readable=True, space_used=False): def backup_repository_info(name, human_readable=True, space_used=False):
""" """
Show info about a repository Show info about a repository
@ -189,7 +191,7 @@ def backup_repository_info(name, human_readable=True, space_used=False):
@is_unit_operation() @is_unit_operation()
def backup_repository_add(operation_logger, location, name, description=None, 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 Add a backup repository