Add missing class properties to propagate verbose /dry_run properly

This commit is contained in:
Orsiris de Jong 2023-01-29 09:33:59 +01:00
parent d9f5d6d66d
commit ce0e7dc1a1
3 changed files with 35 additions and 6 deletions

View file

@ -129,6 +129,7 @@ class NPBackupRunner:
if not isinstance(value, bool):
raise ValueError("Bogus dry_run parameter given: {}".format(value))
self._dry_run = value
self.apply_config_to_restic_runner()
@property
def verbose(self):
@ -139,6 +140,7 @@ class NPBackupRunner:
if not isinstance(value, bool):
raise ValueError("Bogus verbose parameter given: {}".format(value))
self._verbose = value
self.apply_config_to_restic_runner()
@property
def stdout(self):
@ -154,6 +156,7 @@ class NPBackupRunner:
):
raise ValueError("Bogus stdout parameter given: {}".format(value))
self._stdout = value
self.apply_config_to_restic_runner()
@property
def has_binary(self):
@ -192,7 +195,6 @@ class NPBackupRunner:
self.restic_runner = ResticRunner(
repository=repository,
password=password,
verbose=self.verbose,
binary_search_paths=[BASEDIR, CURRENT_DIR],
)
@ -280,6 +282,10 @@ class NPBackupRunner:
except (KeyError, ValueError):
self.minimum_backup_age = 86400
self.restic_runner.verbose = self.verbose
self.restic_runner.dry_run = self.dry_run
self.restic_runner.stdout = self.stdout
@exec_timer
def list(self) -> Optional[dict]:
logger.info("Listing snapshots")
@ -325,7 +331,6 @@ class NPBackupRunner:
"""
Run backup after checking if no recent backup exists, unless force == True
"""
# Preflight checks
try:
paths = self.config_dict["backup"]["paths"]

View file

@ -324,6 +324,7 @@ def _restore_window(
config_dict: dict, snapshot: str, target: str, restore_includes: Optional[List]
) -> Future:
runner = NPBackupRunner(config_dict=config_dict)
runner.verbose = True
result = runner.restore(snapshot, target, restore_includes)
THREAD_SHARED_DICT["exec_time"] = runner.exec_time
return result
@ -395,7 +396,7 @@ def _gui_backup(config_dict, stdout) -> Future:
)
runner.stdout = stdout
result = runner.backup(
force=True
force=True,
) # Since we run manually, force backup regardless of recent backup state
THREAD_SHARED_DICT["exec_time"] = runner.exec_time
return result

View file

@ -31,12 +31,13 @@ class ResticRunner:
self,
repository: str,
password: str,
verbose: bool = False,
binary_search_paths: List[str] = None,
) -> None:
self.repository = repository
self.password = password
self.verbose = verbose
self._verbose = False
self._dry_run = False
self._stdout = None
self._binary = None
self.binary_search_paths = binary_search_paths
self._get_binary()
@ -101,9 +102,31 @@ class ResticRunner:
return self._stdout
@stdout.setter
def stdout(self, value):
def stdout(self, value: Optional[Union[int, str, Callable, queue.Queue]]):
self._stdout = value
@property
def verbose(self) -> bool:
return self._verbose
@verbose.setter
def verbose(self, value):
if isinstance(value, bool):
self._verbose = value
else:
raise ValueError("Bogus verbose value given")
@property
def dry_run(self) -> bool:
return self._dry_run
@dry_run.setter
def dry_run(self, value: bool):
if isinstance(value, bool):
self._dry_run = value
else:
raise ValueError("Bogus dry run value givne")
@property
def exec_time(self) -> Optional[int]:
return self._exec_time