diff --git a/src/borgstore/backends/rclone.py b/src/borgstore/backends/rclone.py index 904e3ea..a54a3f9 100644 --- a/src/borgstore/backends/rclone.py +++ b/src/borgstore/backends/rclone.py @@ -44,19 +44,24 @@ def get_rclone_backend(url): rclone:remote: rclone:remote:path """ + + if not url.startswith("rclone:"): + return None + + try: + # Check rclone is on the path + info = json.loads(subprocess.check_output([RCLONE, "rc", "--loopback", "core/version"])) + except Exception: + raise BackendDoesNotExist("rclone binary not found on the path or not working properly") + if info["decomposed"] < [1, 57, 0]: + raise BackendDoesNotExist(f"rclone version must be at least v1.57.0 - found {info['version']}") + rclone_regex = r""" rclone: (?P(.*)) """ m = re.match(rclone_regex, url, re.VERBOSE) if m: - # Check rclone is on the path - try: - info = json.loads(subprocess.check_output([RCLONE, "rc", "--loopback", "core/version"])) - except Exception: - raise BackendDoesNotExist("rclone binary not found on the path or not working properly") - if info["decomposed"] < [1, 57, 0]: - raise BackendDoesNotExist(f"rclone version must be at least v1.57.0 - found {info['version']}") return Rclone(path=m["path"]) diff --git a/src/borgstore/backends/s3.py b/src/borgstore/backends/s3.py index c4fa602..f29982d 100644 --- a/src/borgstore/backends/s3.py +++ b/src/borgstore/backends/s3.py @@ -24,9 +24,13 @@ def get_s3_backend(url: str): Supports URLs of the form: (s3|b2):[profile|(access_key_id:access_key_secret)@][schema://hostname[:port]]/bucket/path """ - if boto3 is None: + + if not url.startswith(("s3:", "b2:")): return None + if boto3 is None: + raise BackendDoesNotExist("The S3 backend requires dependencies. Install them with: 'pip install borgstore[s3]'") + # (s3|b2):[profile|(access_key_id:access_key_secret)@][schema://hostname[:port]]/bucket/path s3_regex = r""" (?P(s3|b2)): diff --git a/src/borgstore/backends/sftp.py b/src/borgstore/backends/sftp.py index 6906358..99c1ab4 100644 --- a/src/borgstore/backends/sftp.py +++ b/src/borgstore/backends/sftp.py @@ -21,6 +21,14 @@ def get_sftp_backend(url): """Get SFTP backend from URL.""" + + if not url.startswith("sftp:"): + return None + + if paramiko is None: + raise BackendDoesNotExist("The SFTP backend requires dependencies. Install them with: 'pip install borgstore[sftp]'") + + # sftp://username@hostname:22/path # Notes: # - username and port are optional @@ -34,10 +42,9 @@ def get_sftp_backend(url): (?P([^:/]+))(?::(?P\d+))?/ # slash as separator, not part of the path (?P(.+)) # path may or may not start with a slash, must not be empty """ - if paramiko is not None: - m = re.match(sftp_regex, url, re.VERBOSE) - if m: - return Sftp(username=m["username"], hostname=m["hostname"], port=int(m["port"] or "0"), path=m["path"]) + m = re.match(sftp_regex, url, re.VERBOSE) + if m: + return Sftp(username=m["username"], hostname=m["hostname"], port=int(m["port"] or "0"), path=m["path"]) class Sftp(BackendBase):