Skip to content

Commit 2220abc

Browse files
committed
Initial dirty version of v2 pull integration + porject info v2
+ tests for both v2 and v1 features + projectinfo v2 compatibility test
1 parent 843133c commit 2220abc

File tree

9 files changed

+703
-145
lines changed

9 files changed

+703
-145
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ htmlcov
1313
deps
1414
venv
1515
.vscode/settings.json
16+
debug.py

mergin/client.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def __init__(
119119
self._user_info = None
120120
self._server_type = None
121121
self._server_version = None
122+
self._server_features = {}
122123
self.client_version = "Python-client/" + __version__
123124
if plugin_version is not None: # this could be e.g. "Plugin/2020.1 QGIS/3.14"
124125
self.client_version += " " + plugin_version
@@ -309,6 +310,13 @@ def delete(self, path, validate_auth=True):
309310
request = urllib.request.Request(url, method="DELETE")
310311
return self._do_request(request, validate_auth=validate_auth)
311312

313+
def head(self, path, data=None, headers={}, validate_auth=True):
314+
url = urllib.parse.urljoin(self.url, urllib.parse.quote(path))
315+
if data:
316+
url += "?" + urllib.parse.urlencode(data)
317+
request = urllib.request.Request(url, headers=headers, method="HEAD")
318+
return self._do_request(request, validate_auth=validate_auth)
319+
312320
def login(self, login, password):
313321
"""
314322
Authenticate login credentials and store session token
@@ -412,6 +420,19 @@ def server_version(self):
412420

413421
return self._server_version
414422

423+
def server_features(self):
424+
"""
425+
Returns feature flags of the server.
426+
"""
427+
if self._server_features:
428+
return self._server_features
429+
config = self.server_config()
430+
self._server_features = {
431+
"v2_push_enabled": config.get("v2_push_enabled", False),
432+
"v2_pull_enabled": config.get("v2_pull_enabled", False),
433+
}
434+
return self._server_features
435+
415436
def workspaces_list(self):
416437
"""
417438
Find all available workspaces
@@ -699,6 +720,36 @@ def project_info(self, project_path_or_id, since=None, version=None):
699720
resp = self.get("/v1/project/{}".format(project_path_or_id), params)
700721
return json.load(resp)
701722

723+
def project_info_v2(self, project_id: str, files_at_version=None):
724+
"""
725+
Fetch info about project.
726+
727+
:param project_path_or_id: Project's full name (<namespace>/<name>) or id
728+
:type project_path_or_id: String
729+
:param files_at_version: Version to track files at given version
730+
:type files_at_version: String
731+
"""
732+
# since and version are mutually exclusive
733+
params = {}
734+
if files_at_version:
735+
params = {"files_at_version": files_at_version}
736+
resp = self.get(f"/v2/projects/{project_id}", params)
737+
return json.load(resp)
738+
739+
def get_project_delta(self, project_id: str, since: str):
740+
"""
741+
Fetch info about project delta since given version.
742+
743+
:param project_id: Project's id
744+
:type project_id: String
745+
:param since: Version to track history of geodiff files from
746+
:type since: String
747+
:rtype: Dict
748+
"""
749+
params = {"since": since}
750+
resp = self.get(f"/v2/projects/{project_id}/delta", params)
751+
return json.load(resp)
752+
702753
def paginated_project_versions(self, project_path, page, per_page=100, descending=False):
703754
"""
704755
Get records of project's versions (history) using calculated pagination.
@@ -789,11 +840,11 @@ def download_project(self, project_path, directory, version=None):
789840
:param project_path: Project's full name (<namespace>/<name>)
790841
:type project_path: String
791842
792-
:param version: Project version to download, e.g. v42
793-
:type version: String
794-
795843
:param directory: Target directory
796844
:type directory: String
845+
846+
:param version: Project version to download, e.g. v42
847+
:type version: String
797848
"""
798849
job = download_project_async(self, project_path, directory, version)
799850
download_project_wait(job)

0 commit comments

Comments
 (0)