From 168054eccf74c07c109d2f045ea61564fbeefedc Mon Sep 17 00:00:00 2001 From: stoppedwumm Date: Wed, 26 Feb 2025 19:21:03 +0100 Subject: [PATCH 1/3] Addition --- __main__.py | 39 +++++++++++++++++++++++++++++++++++---- requirements.txt | 3 ++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/__main__.py b/__main__.py index ac168bc..ea1e26e 100644 --- a/__main__.py +++ b/__main__.py @@ -1,4 +1,4 @@ -from webdav3.client import Client +from webdav4.client import Client from os import path import os import configReader @@ -25,7 +25,7 @@ 'webdav_login': config.getConfig()["username"], 'webdav_password': config.getConfig()["password"] } -client = Client(options) +client = Client(options["webdav_hostname"], auth=(options["webdav_login"], options["webdav_password"])) @click.group() def cli(): @@ -106,7 +106,15 @@ def pull(): elif path.isdir(item_path): shutil.rmtree(item_path) - client.download_directory(remote_path, cwd) + # loop through every file and download it + # fuck you webdav4 for not having a recursive download function + for file in client.ls(remote_path): + remote_file_path = path.join(remote_path, file) + local_file_path = path.join(cwd, file) + os.makedirs(path.dirname(local_file_path), exist_ok=True) + client.download_file(remote_file_path, local_file_path) + click.echo(f"Downloaded: {file}") + click.echo(click.style("Pull complete. Local repository updated to latest version.", fg="green")) except Exception as e: click.echo(click.style(f"Pull failed: {e}", fg="red")) @@ -119,9 +127,32 @@ def diff(): repo_config = json.load(f) if path.exists(path.join(cwd, ".kst-git", "copy")): shutil.rmtree(path.join(cwd, ".kst-git", "copy"), ignore_errors=True) + remote_path = repo_config["path"] # pull from server click.echo("Downloading server version...", color="yellow") - client.download_directory(repo_config["path"], path.join(cwd, ".kst-git", "copy")) + # loop through every file and download it + # fuck you webdav4 for not having a recursive download function + def loopThrough(p): + global folder + for _ in client.ls(p): + file = "" + folder = False + if type(_) == "str": + continue + elif type(_) == "dict": + file = _["name"] + folder = True + if folder: + loopThrough(path.join(p, file)) + else: + remote_file_path = path.join(p, file) + local_file_path = path.join(path.join(cwd, ".kst-git", "copy"), file) + print(local_file_path, remote_file_path) + os.makedirs(path.dirname(local_file_path), exist_ok=True) + client.download_file(remote_file_path, local_file_path) + click.echo(f"Downloaded: {file}") + + loopThrough(remote_path) click.echo("Comparing local changes...") local_dir = cwd diff --git a/requirements.txt b/requirements.txt index b6f13ca..caa3789 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ webdavclient3 -click \ No newline at end of file +click +webdav4 \ No newline at end of file From 5c18fd6fa82810fddf2164982273cc8585bd0f2e Mon Sep 17 00:00:00 2001 From: StoppedwummPython Date: Mon, 10 Mar 2025 11:49:11 +0100 Subject: [PATCH 2/3] Update __main__.py by Copilot --- __main__.py | 71 ++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/__main__.py b/__main__.py index ea1e26e..52398bb 100644 --- a/__main__.py +++ b/__main__.py @@ -69,8 +69,7 @@ def ensure_remote_directory(remote_dir): try: client.mkdir(remote_dir) except Exception as e: - pass - + click.echo(click.style(f"Error ensuring remote directory {remote_dir}: {e}", fg="red")) for root, _, files in os.walk(copy_dir): for file in files: @@ -106,15 +105,24 @@ def pull(): elif path.isdir(item_path): shutil.rmtree(item_path) - # loop through every file and download it - # fuck you webdav4 for not having a recursive download function - for file in client.ls(remote_path): - remote_file_path = path.join(remote_path, file) - local_file_path = path.join(cwd, file) - os.makedirs(path.dirname(local_file_path), exist_ok=True) - client.download_file(remote_file_path, local_file_path) - click.echo(f"Downloaded: {file}") - + # Recursive function to download all files and directories + def download_recursive(remote_dir, local_dir): + for item in client.ls(remote_dir): + if isinstance(item, str): + continue + elif isinstance(item, dict): + if item['type'] == 'directory': + os.makedirs(path.join(local_dir, item['name']), exist_ok=True) + download_recursive(path.join(remote_dir, item['name']), path.join(local_dir, item['name'])) + else: + remote_file_path = path.join(remote_dir, item['name']) + local_file_path = path.join(local_dir, item['name']) + client.download_file(remote_file_path, local_file_path) + click.echo(f"Downloaded: {item['name']}") + + # Start the recursive download + download_recursive(remote_path, cwd) + click.echo(click.style("Pull complete. Local repository updated to latest version.", fg="green")) except Exception as e: click.echo(click.style(f"Pull failed: {e}", fg="red")) @@ -128,31 +136,26 @@ def diff(): if path.exists(path.join(cwd, ".kst-git", "copy")): shutil.rmtree(path.join(cwd, ".kst-git", "copy"), ignore_errors=True) remote_path = repo_config["path"] - # pull from server click.echo("Downloading server version...", color="yellow") - # loop through every file and download it - # fuck you webdav4 for not having a recursive download function - def loopThrough(p): - global folder - for _ in client.ls(p): - file = "" - folder = False - if type(_) == "str": + + # Recursive function to download all files and directories + def download_recursive(remote_dir, local_dir): + for item in client.ls(remote_dir): + if isinstance(item, str): continue - elif type(_) == "dict": - file = _["name"] - folder = True - if folder: - loopThrough(path.join(p, file)) - else: - remote_file_path = path.join(p, file) - local_file_path = path.join(path.join(cwd, ".kst-git", "copy"), file) - print(local_file_path, remote_file_path) - os.makedirs(path.dirname(local_file_path), exist_ok=True) - client.download_file(remote_file_path, local_file_path) - click.echo(f"Downloaded: {file}") - - loopThrough(remote_path) + elif isinstance(item, dict): + if item['type'] == 'directory': + os.makedirs(path.join(local_dir, item['name']), exist_ok=True) + download_recursive(path.join(remote_dir, item['name']), path.join(local_dir, item['name'])) + else: + remote_file_path = path.join(remote_dir, item['name']) + local_file_path = path.join(local_dir, item['name']) + client.download_file(remote_file_path, local_file_path) + click.echo(f"Downloaded: {item['name']}") + + # Start the recursive download for diff command + download_recursive(remote_path, path.join(cwd, ".kst-git", "copy")) + click.echo("Comparing local changes...") local_dir = cwd From 735211cd0dd0b3673bdf6cc25da2eca4e12337b2 Mon Sep 17 00:00:00 2001 From: StoppedwummPython Date: Mon, 10 Mar 2025 11:53:27 +0100 Subject: [PATCH 3/3] Remove dependency --- requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index caa3789..2bff8b3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ -webdavclient3 click -webdav4 \ No newline at end of file +webdav4