Skip to content

Commit 168054e

Browse files
committed
Addition
1 parent 1e021d5 commit 168054e

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

__main__.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from webdav3.client import Client
1+
from webdav4.client import Client
22
from os import path
33
import os
44
import configReader
@@ -25,7 +25,7 @@
2525
'webdav_login': config.getConfig()["username"],
2626
'webdav_password': config.getConfig()["password"]
2727
}
28-
client = Client(options)
28+
client = Client(options["webdav_hostname"], auth=(options["webdav_login"], options["webdav_password"]))
2929

3030
@click.group()
3131
def cli():
@@ -106,7 +106,15 @@ def pull():
106106
elif path.isdir(item_path):
107107
shutil.rmtree(item_path)
108108

109-
client.download_directory(remote_path, cwd)
109+
# loop through every file and download it
110+
# fuck you webdav4 for not having a recursive download function
111+
for file in client.ls(remote_path):
112+
remote_file_path = path.join(remote_path, file)
113+
local_file_path = path.join(cwd, file)
114+
os.makedirs(path.dirname(local_file_path), exist_ok=True)
115+
client.download_file(remote_file_path, local_file_path)
116+
click.echo(f"Downloaded: {file}")
117+
110118
click.echo(click.style("Pull complete. Local repository updated to latest version.", fg="green"))
111119
except Exception as e:
112120
click.echo(click.style(f"Pull failed: {e}", fg="red"))
@@ -119,9 +127,32 @@ def diff():
119127
repo_config = json.load(f)
120128
if path.exists(path.join(cwd, ".kst-git", "copy")):
121129
shutil.rmtree(path.join(cwd, ".kst-git", "copy"), ignore_errors=True)
130+
remote_path = repo_config["path"]
122131
# pull from server
123132
click.echo("Downloading server version...", color="yellow")
124-
client.download_directory(repo_config["path"], path.join(cwd, ".kst-git", "copy"))
133+
# loop through every file and download it
134+
# fuck you webdav4 for not having a recursive download function
135+
def loopThrough(p):
136+
global folder
137+
for _ in client.ls(p):
138+
file = ""
139+
folder = False
140+
if type(_) == "str":
141+
continue
142+
elif type(_) == "dict":
143+
file = _["name"]
144+
folder = True
145+
if folder:
146+
loopThrough(path.join(p, file))
147+
else:
148+
remote_file_path = path.join(p, file)
149+
local_file_path = path.join(path.join(cwd, ".kst-git", "copy"), file)
150+
print(local_file_path, remote_file_path)
151+
os.makedirs(path.dirname(local_file_path), exist_ok=True)
152+
client.download_file(remote_file_path, local_file_path)
153+
click.echo(f"Downloaded: {file}")
154+
155+
loopThrough(remote_path)
125156
click.echo("Comparing local changes...")
126157

127158
local_dir = cwd

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
webdavclient3
2-
click
2+
click
3+
webdav4

0 commit comments

Comments
 (0)