|
3 | 3 | import os |
4 | 4 | import json |
5 | 5 | import shutil |
| 6 | +import time |
6 | 7 | import zlib |
7 | 8 | import base64 |
8 | 9 | import urllib.parse |
@@ -400,8 +401,7 @@ def server_features(self): |
400 | 401 | return self._server_features |
401 | 402 | config = self.server_config() |
402 | 403 | 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), |
405 | 405 | "v2_pull_enabled": config.get("v2_pull_enabled", False), |
406 | 406 | } |
407 | 407 | return self._server_features |
@@ -1485,3 +1485,33 @@ def create_invitation(self, workspace_id: int, email: str, workspace_role: Works |
1485 | 1485 | params = {"email": email, "role": workspace_role.value} |
1486 | 1486 | ws_inv = self.post(f"v2/workspaces/{workspace_id}/invitations", params, json_headers) |
1487 | 1487 | 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