synchroniser : move backup options to init

Moves the backup options from sync_files to init.
The options are needed in links (to ignore the backup folders)
so it is way easier to have them as attributes.
To do this we move everything related to backup into __init__.
Also remove the option from the runner.
This commit is contained in:
2026-01-20 10:33:13 +01:00
parent cf49ffb8e8
commit 5ec43f9166
2 changed files with 37 additions and 30 deletions

View File

@@ -11,7 +11,7 @@ def unisync_sync(synchroniser:Synchroniser, paths_manager:PathsManager, config:
return 1
print("Connected to the remote.")
synchroniser.sync_files(paths_manager.get_paths_to_sync(), backup=config.backup)
synchroniser.sync_files(paths_manager.get_paths_to_sync())
synchroniser.sync_links(paths_manager.get_paths_to_sync())
# TODO check the config options and do or don't do the following

View File

@@ -49,8 +49,10 @@ class Synchroniser:
Currently unused.
"""
def __init__(self, remote:str, local:str, user:str, ip:str,
port:int=22, args_bool:list=[], args_value:dict={}, ssh_settings:dict={}):
def __init__(self, remote:str, local:str, user:str, ip:str, port:int=22,
args_bool:list=[], args_value:dict={}, ssh_settings:dict={},
backup:BackupConfig | None = None
):
"""Initialises an instance of Synchroniser.
"""
self.remote_dir:str = remote
@@ -61,6 +63,34 @@ class Synchroniser:
self.remote_user:str = user
self.remote_ip:str = ip
self.remote_port:int = port
self.files_extra:list = list()
self.links_extra:list = list()
if(backup != None and backup.enabled):
backup = cast(BackupConfig, backup)
self.files_extra.append("-backup")
if(backup.selection != ""):
self.files_extra.append(backup.selection)
else:
self.files_extra.append("Name *")
self.files_extra.extend([
"-backuploc",
backup.location,
"-maxbackups",
str(backup.max_backups),
"-backupsuffix",
backup.backupsuffix,
"-backupprefix",
backup.backupprefix,
"-ignore",
f"Name {backup.backupprefix[:-1]}"
])
self.links_extra.extend([
"-ignore",
f"Name {backup.backupprefix[:-1]}"
])
def create_ssh_master_connection(self, control_path:str="~/.ssh/control_%C", connection_timeout:int=60) -> int:
"""Creates an ssh master connection.
@@ -119,9 +149,7 @@ class Synchroniser:
close = subprocess.Popen(command)
return close.wait()
def sync_files(self, paths:list, force:bool=False,
backup:BackupConfig | None = None
) -> int:
def sync_files(self, paths:list, force:bool=False) -> int:
"""Synchronises the files.
Args:
@@ -131,35 +159,13 @@ class Synchroniser:
Returns:
The return code of sync.
"""
other = list()
if(backup != None and backup.enabled):
backup = cast(BackupConfig, backup)
other.append("-backup")
if(backup.selection != ""):
other.append(backup.selection)
else:
other.append("Name *")
other.extend([
"-backuploc",
backup.location,
"-maxbackups",
str(backup.max_backups),
"-backupsuffix",
backup.backupsuffix,
"-backupprefix",
backup.backupprefix,
"-ignore",
backup.backupprefix
])
return self.sync(
f"ssh://{self.remote_user}@{self.remote_ip}/{self.remote_dir}/.data",
self.local,
paths=paths,
force=force,
other=other
other=self.files_extra
)
def sync_links(self, ignore:list) -> int:
@@ -174,7 +180,8 @@ class Synchroniser:
return self.sync(
f"ssh://{self.remote_user}@{self.remote_ip}/{self.remote_dir}/links",
self.local,
ignore=ignore
ignore=ignore,
other=self.links_extra
)
def sync(self, remote_root:str, local_root:str,