Skip to content

Commit

Permalink
change: supporting only rustic == 0.7, requiring both rustic and rclo…
Browse files Browse the repository at this point in the history
…ne to be installed
  • Loading branch information
AlphaJack committed Aug 26, 2024
1 parent b52a1c6 commit 6d88d24
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 36 deletions.
4 changes: 3 additions & 1 deletion rusticlone/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

# rusticlone
from rusticlone.helpers.custom import load_customizations
from rusticlone.helpers.requirements import check_rustic_version, check_rclone_version

# ################################################################ FUNCTIONS

Expand Down Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions rusticlone/helpers/requirements.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 0 additions & 4 deletions rusticlone/processing/atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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)
Expand Down
32 changes: 1 addition & 31 deletions rusticlone/processing/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6d88d24

Please sign in to comment.