Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ htmlcov
deps
venv
.vscode/settings.json
debug.py
57 changes: 54 additions & 3 deletions mergin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def __init__(
self._user_info = None
self._server_type = None
self._server_version = None
self._server_features = {}
self.client_version = "Python-client/" + __version__
if plugin_version is not None: # this could be e.g. "Plugin/2020.1 QGIS/3.14"
self.client_version += " " + plugin_version
Expand Down Expand Up @@ -309,6 +310,13 @@ def delete(self, path, validate_auth=True):
request = urllib.request.Request(url, method="DELETE")
return self._do_request(request, validate_auth=validate_auth)

def head(self, path, data=None, headers={}, validate_auth=True):
url = urllib.parse.urljoin(self.url, urllib.parse.quote(path))
if data:
url += "?" + urllib.parse.urlencode(data)
request = urllib.request.Request(url, headers=headers, method="HEAD")
return self._do_request(request, validate_auth=validate_auth)

def login(self, login, password):
"""
Authenticate login credentials and store session token
Expand Down Expand Up @@ -412,6 +420,19 @@ def server_version(self):

return self._server_version

def server_features(self):
"""
Returns feature flags of the server.
"""
if self._server_features:
return self._server_features
config = self.server_config()
self._server_features = {
"v2_push_enabled": config.get("v2_push_enabled", False),
"v2_pull_enabled": config.get("v2_pull_enabled", False),
}
return self._server_features

def workspaces_list(self):
"""
Find all available workspaces
Expand Down Expand Up @@ -699,6 +720,36 @@ def project_info(self, project_path_or_id, since=None, version=None):
resp = self.get("/v1/project/{}".format(project_path_or_id), params)
return json.load(resp)

def project_info_v2(self, project_id: str, files_at_version=None):
"""
Fetch info about project.

:param project_path_or_id: Project's full name (<namespace>/<name>) or id
:type project_path_or_id: String
:param files_at_version: Version to track files at given version
:type files_at_version: String
"""
# since and version are mutually exclusive
params = {}
if files_at_version:
params = {"files_at_version": files_at_version}
resp = self.get(f"/v2/projects/{project_id}", params)
return json.load(resp)

def get_project_delta(self, project_id: str, since: str):
"""
Fetch info about project delta since given version.

:param project_id: Project's id
:type project_id: String
:param since: Version to track history of geodiff files from
:type since: String
:rtype: Dict
"""
params = {"since": since}
resp = self.get(f"/v2/projects/{project_id}/delta", params)
return json.load(resp)

def paginated_project_versions(self, project_path, page, per_page=100, descending=False):
"""
Get records of project's versions (history) using calculated pagination.
Expand Down Expand Up @@ -789,11 +840,11 @@ def download_project(self, project_path, directory, version=None):
:param project_path: Project's full name (<namespace>/<name>)
:type project_path: String

:param version: Project version to download, e.g. v42
:type version: String

:param directory: Target directory
:type directory: String

:param version: Project version to download, e.g. v42
:type version: String
"""
job = download_project_async(self, project_path, directory, version)
download_project_wait(job)
Expand Down
Loading
Loading