MCPcopy Create free account
hub / github.com/CloudPolis/webdav-client-python / pull

Method pull

webdav/client.py:998–1031  ·  view source on GitHub ↗
(self, remote_directory, local_directory)

Source from the content-addressed store, hash-verified

996 self.upload_file(remote_path=remote_path, local_path=local_path)
997
998 def pull(self, remote_directory, local_directory):
999
1000 def prune(src, exp):
1001 return [sub(exp, "", item) for item in src]
1002
1003 urn = Urn(remote_directory, directory=True)
1004
1005 if not self.is_dir(urn.path()):
1006 raise OptionNotValid(name="remote_path", value=remote_directory)
1007
1008 if not os.path.exists(local_directory):
1009 raise LocalResourceNotFound(local_directory)
1010
1011 local_resource_names = listdir(local_directory)
1012
1013 paths = self.list(urn.path())
1014 expression = "{begin}{end}".format(begin="^", end=remote_directory)
1015 remote_resource_names = prune(paths, expression)
1016
1017 for remote_resource_name in remote_resource_names:
1018
1019 local_path = os.path.join(local_directory, remote_resource_name)
1020 remote_path = "{remote_directory}{resource_name}".format(remote_directory=urn.path(), resource_name=remote_resource_name)
1021
1022 remote_urn = Urn(remote_path)
1023
1024 if self.is_dir(remote_urn.path()):
1025 if not os.path.exists(local_path):
1026 os.mkdir(local_path)
1027 self.pull(remote_directory=remote_path, local_directory=local_path)
1028 else:
1029 if remote_resource_name in local_resource_names:
1030 continue
1031 self.download_file(remote_path=remote_path, local_path=local_path)
1032
1033 def sync(self, remote_directory, local_directory):
1034

Callers 1

syncMethod · 0.95

Calls 9

is_dirMethod · 0.95
pathMethod · 0.95
listMethod · 0.95
download_fileMethod · 0.95
UrnClass · 0.90
OptionNotValidClass · 0.85
listdirFunction · 0.85
mkdirMethod · 0.80

Tested by

no test coverage detected