From 774bc86b72397c465942df012af8ec3db0972996 Mon Sep 17 00:00:00 2001 From: deajan Date: Tue, 29 Oct 2024 18:25:16 +0100 Subject: [PATCH] Refactor repo anonymizer code --- README.md | 2 +- npbackup/restic_wrapper/__init__.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3ec7ae5..377d5fe 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ The x64 binary is compatible with Windows 10+. The x86 binary is compatible with ### PyPI installation -If you don't want to use the pre-built executables, you can install via pip with `pip install npbackup`. +If you don't want to use the pre-built executables, you can install via pip with `pip install npbackup` or `pip install npbackup==3.0.0rc8` currently. Python requirement: 3.7+ diff --git a/npbackup/restic_wrapper/__init__.py b/npbackup/restic_wrapper/__init__.py index 999ba25..9f898fb 100644 --- a/npbackup/restic_wrapper/__init__.py +++ b/npbackup/restic_wrapper/__init__.py @@ -151,7 +151,7 @@ class ResticRunner: """ os.environ["RESTIC_PASSWORD"] = "o_O" os.environ["RESTIC_REPOSITORY"] = ( - self.repository.split(":")[0] + ":_(o_O)_hidden_by_npbackup" + self.repository_anonymous ) for env_variable in self.environment_variables.keys(): @@ -261,6 +261,12 @@ class ResticRunner: @property def executor_running(self) -> bool: return self._executor_running + + @property + def repository_anonymous(self): + if self.repository: + return self.repository.split(":")[0] + ":_(o_O)_hidden_by_npbackup" + return None def write_logs( self, @@ -627,7 +633,7 @@ class ResticRunner: self.write_logs("Repository is not initialized or accessible", level="info") output = output.replace( self.repository, - self.repository.split(":")[0] + ":_(o_O)_hidden_by_npbackup", + self.repository_anonymous, ) return self._is_init, output @@ -668,7 +674,7 @@ class ResticRunner: # pylint: disable=E1101 (no-member) output = output.replace( self.repository, - self.repository.split(":")[0] + ":_(o_O)_hidden_by_npbackup", + self.repository_anonymous, ) if ( "repository is already locked" in output