config, defaults: add configuration for backups
Add configuration options for creating backups during the synchronisation.
This commit is contained in:
@@ -49,6 +49,18 @@ class UnisonConfig:
|
||||
bools: list
|
||||
values: dict
|
||||
|
||||
@dataclass
|
||||
class BackupConfig:
|
||||
"""
|
||||
Configuration options relative to backing up the files.
|
||||
"""
|
||||
enabled: bool
|
||||
selection: str
|
||||
location: str
|
||||
max_backups: int
|
||||
backupsuffix: str
|
||||
backupprefix: str
|
||||
|
||||
@dataclass
|
||||
class OtherConfig:
|
||||
"""
|
||||
@@ -64,6 +76,7 @@ class Config:
|
||||
server: ServerConfig
|
||||
roots: RootsConfig
|
||||
unison: UnisonConfig
|
||||
backup: BackupConfig
|
||||
other: OtherConfig
|
||||
|
||||
|
||||
@@ -81,6 +94,7 @@ def load_config(config_path:str) -> Config:
|
||||
# Check if sections are provided
|
||||
server_section = "Server" if "Server" in config.sections() else UNNAMED_SECTION
|
||||
roots_section = "Roots" if "Roots" in config.sections() else UNNAMED_SECTION
|
||||
backup_section = "Backup"
|
||||
other_section = "Other" if "Other" in config.sections() else UNNAMED_SECTION
|
||||
|
||||
server_config = ServerConfig(
|
||||
@@ -94,6 +108,14 @@ def load_config(config_path:str) -> Config:
|
||||
config.get(roots_section, "local", fallback=DEFAULT_ROOTS_LOCAL),
|
||||
config.get(roots_section, "remote")
|
||||
)
|
||||
backup_config = BackupConfig(
|
||||
config.getboolean(backup_section, "enabled", fallback=DEFAULT_BACKUP_ENABLED),
|
||||
config.get(backup_section, "selection", fallback=DEFAULT_BACKUP_SELECTION),
|
||||
config.get(backup_section, "loction", fallback=DEFAULT_BACKUP_LOC),
|
||||
config.getint(backup_section, "max_backups", fallback=DEFAULT_BACKUP_MAX_BACKUPS),
|
||||
config.get(backup_section, "backupsuffix", fallback=DEFAULT_BACKUP_BACKUPSUFFIX),
|
||||
config.get(backup_section, "backupprefix", fallback=DEFAULT_BACKUP_BACKUPPREFIX)
|
||||
)
|
||||
other_config = OtherConfig(
|
||||
Path(config.get(other_section, "cache_dir_path", fallback=DEFAULT_MISC_CACHE_DIR_PATH)).expanduser()
|
||||
)
|
||||
@@ -110,4 +132,4 @@ def load_config(config_path:str) -> Config:
|
||||
args_val[key] = val
|
||||
unison_config = UnisonConfig(args_bool, args_val)
|
||||
|
||||
return Config(server_config, roots_config, unison_config, other_config)
|
||||
return Config(server_config, roots_config, unison_config, backup_config, other_config)
|
||||
|
||||
@@ -16,3 +16,10 @@ DEFAULT_ROOTS_LOCAL: str = str(Path("~/files").expanduser())
|
||||
# DEFAULT_ROOTS_REMOTE: str = ""
|
||||
|
||||
DEFAULT_MISC_CACHE_DIR_PATH: str = "~/.unisync"
|
||||
|
||||
DEFAULT_BACKUP_ENABLED: bool = False
|
||||
DEFAULT_BACKUP_SELECTION: str = ""
|
||||
DEFAULT_BACKUP_LOC: str = "local"
|
||||
DEFAULT_BACKUP_MAX_BACKUPS: int = 2
|
||||
DEFAULT_BACKUP_BACKUPSUFFIX: str = ".unison_backups/"
|
||||
DEFAULT_BACKUP_BACKUPPREFIX: str = ".$VERSION.bak"
|
||||
|
||||
Reference in New Issue
Block a user