VolumeBackupConfig: Parse commands to ShellCommand

main
Felix Stupp 2 years ago
parent 10d0c52e8e
commit b5904b2d63
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -60,6 +60,7 @@ from podman_compose_tools.executor import (
CompletedExec, CompletedExec,
ExecutorTarget, ExecutorTarget,
HostExecutor, HostExecutor,
ShellCommand,
) )
from podman_compose_tools.executor.base import ( from podman_compose_tools.executor.base import (
combine_cmds, combine_cmds,
@ -137,6 +138,11 @@ def parse_bool(val: str | bool) -> bool:
# === code # === code
# required because of mypy attrs converter restrictions
def shell_cmd_from_str(command: str) -> ShellCommand:
return ShellCommand.from_str(command=command)
@define(kw_only=True) @define(kw_only=True)
class VolumeBackupConfig: class VolumeBackupConfig:
# === Backups # === Backups
@ -145,12 +151,24 @@ class VolumeBackupConfig:
image: str = field(default=DEFAULT_BACKUP_IMAGE) image: str = field(default=DEFAULT_BACKUP_IMAGE)
mount_target: str = field(default=DEFAULT_MOUNT_TARGET) mount_target: str = field(default=DEFAULT_MOUNT_TARGET)
stop: bool = field(converter=parse_bool, default=False) stop: bool = field(converter=parse_bool, default=False)
backup_cmd: str = field(default=DEFAULT_BACKUP_CMD) backup_cmd: ShellCommand = field(
restore_cmd: str = field(default=DEFAULT_RESTORE_CMD) converter=shell_cmd_from_str,
default=shell_cmd_from_str(DEFAULT_BACKUP_CMD),
)
restore_cmd: ShellCommand = field(
converter=shell_cmd_from_str,
default=shell_cmd_from_str(DEFAULT_RESTORE_CMD),
)
# === Compressing # === Compressing
compress_image: Optional[str] = field(default=None) compress_image: Optional[str] = field(default=None)
compress_cmd: Optional[str] = field(default=None) compress_cmd: Optional[ShellCommand] = field(
decompress_cmd: Optional[str] = field(default=None) converter=shell_cmd_from_str,
default=None,
)
decompress_cmd: Optional[ShellCommand] = field(
converter=shell_cmd_from_str,
default=None,
)
@classmethod @classmethod
def from_labels(cls, labels: LabelDict) -> VolumeBackupConfig: def from_labels(cls, labels: LabelDict) -> VolumeBackupConfig:

@ -124,6 +124,12 @@ class ShellCommand(Command):
return decorated return decorated
@classmethod
def from_str(cls, command: str) -> ShellCommand:
return cls(
command=command,
)
@_extract_other @_extract_other
def __or__(self, other_cmd: str) -> str: # | def __or__(self, other_cmd: str) -> str: # |
return f"({self.command}) | ({other_cmd})" return f"({self.command}) | ({other_cmd})"

Loading…
Cancel
Save