Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: fixes error on updated file bug #7

Merged
merged 1 commit into from Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rkale"
version = "0.2.6"
version = "0.2.7"
description = "Rclone wrapper to manage multiple datasets in a project"
authors = ["Joar Gruneau <joar@aiwizo.com>"]

Expand Down
2 changes: 1 addition & 1 deletion rkale/__init__.py
@@ -1 +1 @@
__version__ = "0.2.6"
__version__ = "0.2.7"
19 changes: 15 additions & 4 deletions rkale/operations.py
Expand Up @@ -15,7 +15,7 @@ def get_input(verbose_info):
def get_answers(operation, checks, paths, force=False):
answers = []
for check, (source, destination) in zip(checks, paths):
missing_src, missing_dst = read(check.src_out), read(check.dst_out)
missing_src, missing_dst, diff = read(check.src_out), read(check.dst_out), read(check.diff_out)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I personally would keep these as separate statements on separate lines for readability :)

if check.stderr:
print(check.stderr)
answers.append(False)
Expand All @@ -30,8 +30,11 @@ def get_answers(operation, checks, paths, force=False):
if operation == "sync" and missing_src:
print(f"WARNING! {len(missing_src)} files will be removed")
verbose_info.extend(["Files to be removed:\n", *missing_src])
if diff:
print(f"WARNING! {len(diff)} files will be replaced")
verbose_info.extend(["Files to be replaced:\n", *diff])

if (operation == "sync" and missing_src) or missing_dst:
if (operation == "sync" and missing_src) or missing_dst or diff:
answers.append(get_input("".join(verbose_info)))
else:
print(f"Source and destination match, no files to {operation}")
Expand All @@ -46,8 +49,13 @@ def handle_copy(paths, force=False):
answers = get_answers("copy", checks, paths, force=force)
for answer, check, (source, destination) in zip(answers, checks, paths):
if answer:
print(f"Copying files to {destination}...")
sync(source, destination, files_from=check.dst_out, progress=True, flags=flags)
if read(check.dst_out):
print(f"Copying files to {destination}...")
sync(source, destination, files_from=check.dst_out, progress=True, flags=flags)
if read(check.diff_out):
print(f"Updating files on {destination}...")
sync(source, destination, files_from=check.diff_out, progress=True, flags=flags)



def handle_sync(paths, force=False):
Expand All @@ -63,3 +71,6 @@ def handle_sync(paths, force=False):
if read(check.dst_out):
print(f"Copying files to {destination}...")
sync(source, destination, files_from=check.dst_out, progress=True, flags=flags)
if read(check.diff_out):
print(f"Replacing files on {destination}...")
sync(source, destination, files_from=check.diff_out, progress=True, flags=flags)
19 changes: 14 additions & 5 deletions rkale/utils.py
Expand Up @@ -17,15 +17,18 @@ def read(file_path):

@contextmanager
def check_files(paths):
Check = namedtuple("Check", ["src_out", "dst_out", "stderr"])
Check = namedtuple("Check", ["src_out", "dst_out", "diff_out", "stderr"])
checks = []
for source, destination in paths:
print(f"Comparing paths {source} and {destination}...")
src_out, dst_out, error_out = (tempfile.mkstemp()[1] for _ in range(3))
src_out, dst_out, diff_out, error_out = (
tempfile.mkstemp()[1] for _ in range(4)
)
result = subprocess.run(
f"rclone check {source} {destination}"
+ f" --missing-on-src {src_out}"
+ f" --missing-on-dst {dst_out} --error {error_out}",
+ f" --missing-on-dst {dst_out}"
+ f" --error {error_out} --differ {diff_out}",
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand All @@ -42,18 +45,24 @@ def check_files(paths):
)
stderr = (
result.stderr.decode("utf-8")
if (not read(src_out) and not read(dst_out) and result.returncode == 1)
if (
not read(src_out)
and not read(dst_out)
and not read(diff_out)
and result.returncode == 1
)
else files_stderr
)
os.remove(error_out)
checks.append(Check(src_out, dst_out, stderr))
checks.append(Check(src_out, dst_out, diff_out, stderr))

try:
yield checks
finally:
for check in checks:
os.remove(check.src_out)
os.remove(check.dst_out)
os.remove(check.diff_out)


def check_paths(paths):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rkale.py
Expand Up @@ -9,7 +9,7 @@


def test_version():
assert __version__ == "0.2.6"
assert __version__ == "0.2.7"


def test_path():
Expand Down