WebDavClient¶
- class webdavclient.WebDavClient(hostname: str, username: str, password: str)[source]¶
Bases:
object
A simple WebDav client for downloading files and complete folder hierarchies from a remote host (f.e. cloud provider).
- hostname¶
full address to webdav host
- Type:
str
- username¶
username of connection
- Type:
str
- password¶
most properly a token generated for AUTH
- Type:
str
- download_all_files_iterative(a, b)[source]¶
Downloads all files from a and stroes them under b locally.
- subtract(a, b)¶
Returns the difference between a and b.
- download_all_files_iterative(remote_base_path: str, local_base_path: str) None [source]¶
This method downloads all files from your WebDav host that stay under the remote_base_path. All subfolders will also be downloaded and folder structure is preserved
- Parameters:
remote_base_path (str) – Folder on host which should be primary source for downloading files
local_base_path (str) – all files (with preserved folder structures) are put inside this local path
- Returns:
None
- Return type:
type
- Raises:
None directly –
Examples
Example usage of the method:
>>> hostname = "https://yourhost.de/webdav" >>> username = "Schlawiner23" >>> password = "YOUR_PERSONAL_TOKEN" >>> remote_base_path = "MyProjectFolder" >>> local_base_path = "assets" >>> webdevclient = WebDavClient(args.hostname, args.username, args.password) >>> webdevclient.download_all_files_iterative( >>> args.remote_base_path, args.local_base_path >>> )
- download_files(global_remote_base_path: str, remote_base_path: str, local_base_path: str) None [source]¶
This method downloads all files from your WebDav host that stay EXACTLY under the remote_base_path. No subfolders are considered.
- Parameters:
remote_base_path (str) – Folder on host which should be primary source for downloading files
local_base_path (str) – all files (with preserved folder structures) are put inside this local path
- Returns:
None
- Return type:
type
- Raises:
None directly –
Examples
Example usage of the method:
>>> hostname = "https://yourhost.de/webdav" >>> username = "Schlawiner23" >>> password = "YOUR_PERSONAL_TOKEN" >>> remote_base_path = "MyProjectFolder" >>> local_base_path = "assets" >>> auth: HTTPBasicAuth = HTTPBasicAuth(username, password) >>> download_files(hostname, auth, current_remote_path, local_base_path)
- ensure_folder_exists(path: str) None [source]¶
This method ensures that the given folder will exist
- Parameters:
path (str) – Path to folder.
- Returns:
None
- Return type:
type
- Raises:
None directly –
- filter_after_global_base_path(path: str, remote_base_path: str) str [source]¶
This method removes the hostname and the remote_base_path from an path :param path: Url to host, e.g. https://host.org :type path: str :param remote_base_path: single folder on remote host e.g. data :type remote_base_path: str
- Returns:
str
- Return type:
type
- Raises:
None directly –
- Example: host-url= https://host.org/
remote_base_path = data path = https://host.org/data/example1
“example1” ist returned
- get_sub_path(full_path: str, initial_part: str) str [source]¶
Returns the sub-path after the initial part of the path.
- Parameters:
full_path (str) – The full path string. Does NOT have host url within
initial_part (str) – The initial part of the path string to be removed.
- Returns:
str: The sub-path string after the initial part.
- Return type:
type
- Example 1:
full_path = /data/subfolder1/text.txt initial_part (str) = data returns ==> subfolder1/text.txt
- Raises:
ValueError –
- list_files(url: str) list[str] [source]¶
This method list all files from your WebDav host that stay under the url
- Parameters:
url (str) – web dev host url.
- Returns:
list[str] list of all files who stay under the url (no recursion)
- Return type:
type
- Raises:
OSError –
Examples
Example usage of the method:
>>> hostname = "https://yourhost.de/webdav" >>> username = "Schlawiner23" >>> password = "YOUR_PERSONAL_TOKEN" >>> remote_base_path = "MyProjectFolder" >>> auth: HTTPBasicAuth = HTTPBasicAuth(username, password) >>> webdevclient = WebDavClient(hostname, username, password) >>> files = webdevclient.list_files(os.path.join(hostname, remote_base_path))
- list_folders(remote_base_path: str) list[str] [source]¶
This method list all folders from your WebDav host that stay EXACTLY under the remote_base_path. No subfolders are considered.
- Parameters:
remote_base_path (str) – Folder on host for which the folders should be listed
- Returns:
list[str] list of all folders who stay under the parent folder
- Return type:
type
- Raises:
OSError –
Examples
Example usage of the method:
>>> hostname = "https://yourhost.de/webdav" >>> username = "Schlawiner23" >>> password = "YOUR_PERSONAL_TOKEN" >>> remote_base_path = "MyProjectFolder" >>> webdevclient = WebDavClient(args.hostname, args.username, args.password) >>> webdevclient.list_folders(remote_base_path)