2023-07-03 13:06:54 +00:00
|
|
|
import subprocess
|
2023-07-03 13:28:23 +00:00
|
|
|
from os.path import exists
|
2023-07-03 13:06:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def output_yielder(command):
|
|
|
|
with subprocess.Popen(
|
|
|
|
command,
|
|
|
|
shell=False,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
universal_newlines=True,
|
|
|
|
) as handle:
|
|
|
|
for line in iter(handle.stdout.readline, ""):
|
|
|
|
if "NOTICE:" not in line:
|
|
|
|
yield line
|
2023-07-03 13:28:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
def sync(src_path: str, dest_path: str):
|
|
|
|
"""a wrapper around rclone sync"""
|
|
|
|
|
|
|
|
if not exists(src_path):
|
|
|
|
raise ValueError("source dir for rclone sync must exist")
|
|
|
|
|
|
|
|
rclone_command = ["rclone", "sync", "-P", src_path, dest_path]
|
|
|
|
for raw_message in output_yielder(rclone_command):
|
|
|
|
if "ERROR" in raw_message:
|
|
|
|
raise ValueError(raw_message)
|