1- from webdav3 .client import Client
1+ from webdav4 .client import Client
22from os import path
33import os
44import configReader
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 ()
3131def cli ():
@@ -69,8 +69,7 @@ def ensure_remote_directory(remote_dir):
6969 try :
7070 client .mkdir (remote_dir )
7171 except Exception as e :
72- pass
73-
72+ click .echo (click .style (f"Error ensuring remote directory { remote_dir } : { e } " , fg = "red" ))
7473
7574 for root , _ , files in os .walk (copy_dir ):
7675 for file in files :
@@ -106,7 +105,24 @@ def pull():
106105 elif path .isdir (item_path ):
107106 shutil .rmtree (item_path )
108107
109- client .download_directory (remote_path , cwd )
108+ # Recursive function to download all files and directories
109+ def download_recursive (remote_dir , local_dir ):
110+ for item in client .ls (remote_dir ):
111+ if isinstance (item , str ):
112+ continue
113+ elif isinstance (item , dict ):
114+ if item ['type' ] == 'directory' :
115+ os .makedirs (path .join (local_dir , item ['name' ]), exist_ok = True )
116+ download_recursive (path .join (remote_dir , item ['name' ]), path .join (local_dir , item ['name' ]))
117+ else :
118+ remote_file_path = path .join (remote_dir , item ['name' ])
119+ local_file_path = path .join (local_dir , item ['name' ])
120+ client .download_file (remote_file_path , local_file_path )
121+ click .echo (f"Downloaded: { item ['name' ]} " )
122+
123+ # Start the recursive download
124+ download_recursive (remote_path , cwd )
125+
110126 click .echo (click .style ("Pull complete. Local repository updated to latest version." , fg = "green" ))
111127 except Exception as e :
112128 click .echo (click .style (f"Pull failed: { e } " , fg = "red" ))
@@ -119,9 +135,27 @@ def diff():
119135 repo_config = json .load (f )
120136 if path .exists (path .join (cwd , ".kst-git" , "copy" )):
121137 shutil .rmtree (path .join (cwd , ".kst-git" , "copy" ), ignore_errors = True )
122- # pull from server
138+ remote_path = repo_config [ "path" ]
123139 click .echo ("Downloading server version..." , color = "yellow" )
124- client .download_directory (repo_config ["path" ], path .join (cwd , ".kst-git" , "copy" ))
140+
141+ # Recursive function to download all files and directories
142+ def download_recursive (remote_dir , local_dir ):
143+ for item in client .ls (remote_dir ):
144+ if isinstance (item , str ):
145+ continue
146+ elif isinstance (item , dict ):
147+ if item ['type' ] == 'directory' :
148+ os .makedirs (path .join (local_dir , item ['name' ]), exist_ok = True )
149+ download_recursive (path .join (remote_dir , item ['name' ]), path .join (local_dir , item ['name' ]))
150+ else :
151+ remote_file_path = path .join (remote_dir , item ['name' ])
152+ local_file_path = path .join (local_dir , item ['name' ])
153+ client .download_file (remote_file_path , local_file_path )
154+ click .echo (f"Downloaded: { item ['name' ]} " )
155+
156+ # Start the recursive download for diff command
157+ download_recursive (remote_path , path .join (cwd , ".kst-git" , "copy" ))
158+
125159 click .echo ("Comparing local changes..." )
126160
127161 local_dir = cwd
0 commit comments