From 6d88d24e226c427094828738f077dd6ffe53537f Mon Sep 17 00:00:00 2001 From: AlphaJack Date: Mon, 26 Aug 2024 21:45:28 +0200 Subject: [PATCH] change: supporting only rustic == 0.7, requiring both rustic and rclone to be installed --- rusticlone/cli.py | 4 ++- rusticlone/helpers/requirements.py | 55 ++++++++++++++++++++++++++++++ rusticlone/processing/atomic.py | 4 --- rusticlone/processing/profile.py | 32 +---------------- 4 files changed, 59 insertions(+), 36 deletions(-) create mode 100644 rusticlone/helpers/requirements.py diff --git a/rusticlone/cli.py b/rusticlone/cli.py index 61cc9d6..9de5389 100755 --- a/rusticlone/cli.py +++ b/rusticlone/cli.py @@ -24,6 +24,7 @@ # rusticlone from rusticlone.helpers.custom import load_customizations +from rusticlone.helpers.requirements import check_rustic_version, check_rclone_version # ################################################################ FUNCTIONS @@ -93,7 +94,8 @@ def main(): # parse arguments # print(sys.argv) args = parse_args() - load_customizations(args) + if check_rustic_version() and check_rclone_version(): + load_customizations(args) # ################################################################ ENTRY POINT diff --git a/rusticlone/helpers/requirements.py b/rusticlone/helpers/requirements.py new file mode 100644 index 0000000..e9da93b --- /dev/null +++ b/rusticlone/helpers/requirements.py @@ -0,0 +1,55 @@ +""" +Utility functions for version checking +""" + +# ┌───────────────────────────────────────────────────────────────┐ +# │ Contents of requirements.py │ +# ├───────────────────────────────────────────────────────────────┘ +# │ +# ├── IMPORTS +# ├── FUNCTIONS +# │ +# └─────────────────────────────────────────────────────────────── + +# ################################################################ IMPORTS + +# rusticlone +from rusticlone.helpers.action import Action +from rusticlone.helpers.rclone import Rclone +from rusticlone.helpers.rustic import Rustic + +# ################################################################ FUNCTIONS + + +def check_rustic_version() -> bool: + """ + Check that the installed Rustic version is supported + """ + action = Action("Checking Rustic version") + rustic = Rustic("", "--version") + version = rustic.stdout.splitlines()[0].replace("rustic ", "") + try: + major_version = int(version.split(".")[0]) + minor_version = int(version.split(".")[1]) + except (ValueError, TypeError): + return action.abort("Rustic == 0.7 is required") + if major_version != 0 or minor_version != 7: + return action.abort("Rustic == 0.7 is required") + return action.stop() + + +def check_rclone_version() -> bool: + """ + Check that the installed Rclone version is supported + """ + action = Action("Checking Rclone version") + rclone = Rclone(default_flags=None) + version = rclone.stdout.splitlines()[0].replace("rclone v", "") + try: + major_version = int(version.split(".")[0]) + minor_version = int(version.split(".")[1]) + except (ValueError, TypeError): + return action.abort("Rclone >= 1.67 is required") + if major_version <= 1 and minor_version < 67: + return action.abort("Rclone >= 1.67 is required") + return action.stop() diff --git a/rusticlone/processing/atomic.py b/rusticlone/processing/atomic.py index 9f2ba20..b4fb55d 100644 --- a/rusticlone/processing/atomic.py +++ b/rusticlone/processing/atomic.py @@ -36,7 +36,6 @@ def profile_archive( action = Action(name, parallel, "[archive]") timer = Timer(parallel) profile = Profile(name, parallel) - profile.check_rustic_version() profile.read_rustic_config() profile.parse_rustic_config() profile.set_log_file(log_file) @@ -62,7 +61,6 @@ def profile_upload( action = Action(name, parallel, "[upload]") timer = Timer(parallel) profile = Profile(name, parallel) - profile.check_rclone_version() profile.read_rustic_config() profile.parse_rustic_config() profile.parse_rclone_config() @@ -86,7 +84,6 @@ def profile_download( action = Action(name, parallel, "[download]") timer = Timer(parallel) profile = Profile(name, parallel) - profile.check_rclone_version() profile.read_rustic_config() profile.parse_rustic_config() profile.parse_rclone_config() @@ -108,7 +105,6 @@ def profile_extract( action = Action(name, parallel, "[extract]") timer = Timer(parallel) profile = Profile(name, parallel) - profile.check_rustic_version() profile.read_rustic_config() profile.parse_rustic_config() profile.set_log_file(log_file) diff --git a/rusticlone/processing/profile.py b/rusticlone/processing/profile.py index 27a8f4a..a9ef2ee 100644 --- a/rusticlone/processing/profile.py +++ b/rusticlone/processing/profile.py @@ -61,36 +61,6 @@ def __init__(self, profile: str, parallel: bool = False) -> None: self.config = "" # self.repo_info = "" - def check_rustic_version(self) -> None: - """ - Check that the installed Rustic version is supported - """ - if self.result: - action = Action("Checking Rustic version", self.parallel) - rustic = Rustic(self.profile_name, "--version") - version = rustic.stdout.splitlines()[0].replace("rustic ", "") - major_version = int(version.split(".")[0]) - minor_version = int(version.split(".")[1]) - if major_version <= 0 and minor_version < 7: - self.result = action.abort(f"Rustic >= 0.7 is required") - else: - action.stop("Rustic version is supported") - - def check_rclone_version(self) -> None: - """ - Check that the installed Rclone version is supported - """ - if self.result: - action = Action("Checking Rclone version", self.parallel) - rclone = Rclone(default_flags=None) - version = rclone.stdout.splitlines()[0].replace("rclone v", "") - major_version = int(version.split(".")[0]) - minor_version = int(version.split(".")[1]) - if major_version <= 1 and minor_version < 67: - self.result = action.abort(f"Rclone >= 1.67 is required") - else: - action.stop("Rclone version is supported") - def read_rustic_config(self) -> None: """ Read the profile configuration by running Rustic @@ -549,7 +519,7 @@ def latest(self) -> None: parallel=self.parallel, ) else: - self.result = action.abort("Cannot parse timestamp") + self.result = action.abort("Could not parse timestamp") else: self.result = action.abort("Repo does not have snapshots") # else: