Skip to content

Commit 57c6bf4

Browse files
committed
add local changes
- attempts of failing chunks =- init for sync_project
1 parent 216c3bd commit 57c6bf4

File tree

6 files changed

+385
-126
lines changed

6 files changed

+385
-126
lines changed

mergin/client.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import json
55
import shutil
6+
import time
67
import zlib
78
import base64
89
import urllib.parse
@@ -400,8 +401,7 @@ def server_features(self):
400401
return self._server_features
401402
config = self.server_config()
402403
self._server_features = {
403-
"v2_push_enabled": config.get("v2_push_enabled", False)
404-
and is_version_acceptable(self.server_version(), "2025.6.1"),
404+
"v2_push_enabled": config.get("v2_push_enabled", False),
405405
"v2_pull_enabled": config.get("v2_pull_enabled", False),
406406
}
407407
return self._server_features
@@ -1485,3 +1485,33 @@ def create_invitation(self, workspace_id: int, email: str, workspace_role: Works
14851485
params = {"email": email, "role": workspace_role.value}
14861486
ws_inv = self.post(f"v2/workspaces/{workspace_id}/invitations", params, json_headers)
14871487
return json.load(ws_inv)
1488+
1489+
def sync_project(self, project_dir):
1490+
"""
1491+
Syncs project by loop with these steps:
1492+
1. Pull server version
1493+
2. Get local changes
1494+
3. Push first change batch
1495+
Repeat if there are more local changes.
1496+
The batch pushing makes use of the server ability to handle simultaneously exclusive upload (that blocks
1497+
other uploads) and non-exclusive upload (for adding assets)
1498+
"""
1499+
attempts = 2
1500+
for attempt in range(attempts):
1501+
try:
1502+
pull_job = pull_project_async(self, project_dir)
1503+
if pull_job:
1504+
pull_project_wait(pull_job)
1505+
pull_project_finalize(pull_job)
1506+
1507+
job = push_project_async(self, project_dir)
1508+
if job:
1509+
push_project_wait(job)
1510+
push_project_finalize(job)
1511+
break
1512+
except ClientError as e:
1513+
if e.http_error == 409 and attempt < attempts - 1:
1514+
# retry on conflict, e.g. when server has changes that we do not have yet
1515+
time.sleep(5)
1516+
continue
1517+
raise e

0 commit comments

Comments
 (0)