mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[wip] One BackupMethod by BackupRepo
This commit is contained in:
parent
e96d76814f
commit
48f7e51dd8
1 changed files with 16 additions and 15 deletions
|
@ -50,6 +50,12 @@ class BackupRepository(object):
|
||||||
"""
|
"""
|
||||||
repositories = {}
|
repositories = {}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create(cls, location, name, *args, **kwargs):
|
||||||
|
cls.load()
|
||||||
|
|
||||||
|
return BackupRepository(True, location, name, *args, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get(cls, name):
|
def get(cls, name):
|
||||||
cls.load()
|
cls.load()
|
||||||
|
@ -57,14 +63,15 @@ class BackupRepository(object):
|
||||||
if name not in cls.repositories:
|
if name not in cls.repositories:
|
||||||
raise YunohostError('backup_repository_doesnt_exists', name=name)
|
raise YunohostError('backup_repository_doesnt_exists', name=name)
|
||||||
|
|
||||||
return BackupRepository(**cls.repositories[name])
|
return BackupRepository(False, **cls.repositories[name])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls):
|
def load(cls):
|
||||||
"""
|
"""
|
||||||
Read repositories configuration from file
|
Read repositories configuration from file
|
||||||
"""
|
"""
|
||||||
cls.repositories = {}
|
if cls.repositories != {}:
|
||||||
|
return cls.repositories
|
||||||
|
|
||||||
if os.path.exists(REPOSITORIES_PATH):
|
if os.path.exists(REPOSITORIES_PATH):
|
||||||
try:
|
try:
|
||||||
|
@ -83,15 +90,15 @@ class BackupRepository(object):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise YunohostError('backup_cant_save_repositories_file', reason=e)
|
raise YunohostError('backup_cant_save_repositories_file', reason=e)
|
||||||
|
|
||||||
def __init__(self, location, name=None, description=None, method=None,
|
def __init__(self, created=True, location, name=None, description=None, method=None,
|
||||||
encryption=None, quota=None):
|
encryption=None, quota=None):
|
||||||
|
|
||||||
self.location = location
|
self.location = location
|
||||||
self._split_location()
|
self._split_location()
|
||||||
|
|
||||||
self.name = location if name is None else name
|
self.name = location if name is None else name
|
||||||
if self.name in BackupMethod.repositories:
|
if created and self.name in BackupMethod.repositories:
|
||||||
raise YunohostError('backup_repository_already_exists', repositories=name)
|
raise YunohostError('backup_repository_already_exists', repositories=self.name)
|
||||||
|
|
||||||
self.description = description
|
self.description = description
|
||||||
self.encryption = encryption
|
self.encryption = encryption
|
||||||
|
@ -99,17 +106,11 @@ class BackupRepository(object):
|
||||||
|
|
||||||
if method is None:
|
if method is None:
|
||||||
method = 'tar' if self.domain is None else 'borg'
|
method = 'tar' if self.domain is None else 'borg'
|
||||||
self.method = BackupMethod.create(method, self)
|
if created:
|
||||||
|
self.method = BackupMethod.create(method, self)
|
||||||
# Check for forbidden folders
|
else:
|
||||||
if self.path.startswith(ARCHIVES_PATH) or \
|
self.method = BackupMethod.get(method, self)
|
||||||
re.match(r'^/(|(bin|boot|dev|etc|lib|root|run|sbin|sys|usr|var)(|/.*))$',
|
|
||||||
self.path):
|
|
||||||
raise YunohostError('backup_output_directory_forbidden')
|
|
||||||
|
|
||||||
# Check that output directory is empty
|
|
||||||
if os.path.isdir(location) and os.listdir(location):
|
|
||||||
raise YunohostError('backup_output_directory_not_empty')
|
|
||||||
|
|
||||||
def compute_space_used(self):
|
def compute_space_used(self):
|
||||||
if self.used is None:
|
if self.used is None:
|
||||||
|
|
Loading…
Add table
Reference in a new issue