Kataglyphis-WebDavClient

Kataglyphis-WebDavClient#

WebDAV client implementation for listing and downloading remote files.

class kataglyphis_webdavclient.webdavclient.WebDavClient(hostname: str, username: str, password: str)[source]

Bases: object

A simple WebDav client for downloading files and folders.

It supports listing folders, listing files, and iterative downloads from a remote host (for example a 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 stores them under b locally.

download_all_files_iterative(remote_base_path: str, local_base_path: str) None[source]

Download all files recursively below a remote base path.

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]

Download all files directly below a remote base path.

This method downloads all files from your WebDav host that stay EXACTLY under the remote_base_path. No subfolders are considered.

Parameters:
  • global_remote_base_path (str) – Root folder that anchors relative paths.

  • 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]

Ensure that the given folder exists.

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]

Remove hostname and base path prefix from a remote URL path.

Parameters:
  • path (str) – Url to host, e.g. https://host.org

  • remote_base_path (str) – single folder on remote host e.g. data

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” is 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]

List all files directly below a given WebDAV 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]

List all folders directly below a remote base path.

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)