|
24 | 24 |
|
25 | 25 | from .local_changes import LocalChange, LocalChanges |
26 | 26 |
|
27 | | -from .common import UPLOAD_CHUNK_ATTEMPT_WAIT, UPLOAD_CHUNK_ATTEMPTS, UPLOAD_CHUNK_SIZE, ClientError, ErrorCode |
| 27 | +from .common import ( |
| 28 | + MAX_UPLOAD_VERSIONED_SIZE, |
| 29 | + UPLOAD_CHUNK_ATTEMPT_WAIT, |
| 30 | + UPLOAD_CHUNK_ATTEMPTS, |
| 31 | + UPLOAD_CHUNK_SIZE, |
| 32 | + MAX_UPLOAD_MEDIA_SIZE, |
| 33 | + ClientError, |
| 34 | +) |
28 | 35 | from .merginproject import MerginProject |
29 | 36 | from .editor import filter_changes |
30 | 37 | from .utils import get_data_checksum |
@@ -296,28 +303,23 @@ def push_project_async(mc, directory) -> Optional[UploadJob]: |
296 | 303 | mp.log.info(f"--- push {project_path} - nothing to do") |
297 | 304 | return |
298 | 305 |
|
299 | | - mp.log.debug("push changes:\n" + pprint.pformat(changes)) |
| 306 | + mp.log.debug("push changes:\n" + pprint.pformat(asdict(changes))) |
300 | 307 | tmp_dir = tempfile.TemporaryDirectory(prefix="python-api-client-") |
301 | 308 |
|
302 | 309 | # If there are any versioned files (aka .gpkg) that are not updated through a diff, |
303 | 310 | # we need to make a temporary copy somewhere to be sure that we are uploading full content. |
304 | 311 | # That's because if there are pending transactions, checkpointing or switching from WAL mode |
305 | 312 | # won't work, and we would end up with some changes left in -wal file which do not get |
306 | 313 | # uploaded. The temporary copy using geodiff uses sqlite backup API and should copy everything. |
307 | | - for f in changes["updated"]: |
308 | | - if mp.is_versioned_file(f["path"]) and "diff" not in f: |
| 314 | + for f in changes.updated: |
| 315 | + if mp.is_versioned_file(f.path) and not f.diff: |
309 | 316 | mp.copy_versioned_file_for_upload(f, tmp_dir.name) |
310 | 317 |
|
311 | | - for f in changes["added"]: |
312 | | - if mp.is_versioned_file(f["path"]): |
| 318 | + for f in changes.added: |
| 319 | + if mp.is_versioned_file(f.path): |
313 | 320 | mp.copy_versioned_file_for_upload(f, tmp_dir.name) |
314 | 321 |
|
315 | | - local_changes = LocalChanges( |
316 | | - added=[LocalChange(**change) for change in changes["added"]], |
317 | | - updated=[LocalChange(**change) for change in changes["updated"]], |
318 | | - removed=[LocalChange(**change) for change in changes["removed"]], |
319 | | - ) |
320 | | - job = create_upload_job(mc, mp, local_changes, tmp_dir) |
| 322 | + job = create_upload_job(mc, mp, changes, tmp_dir) |
321 | 323 | return job |
322 | 324 |
|
323 | 325 |
|
@@ -471,12 +473,27 @@ def remove_diff_files(job: UploadJob) -> None: |
471 | 473 | os.remove(diff_file) |
472 | 474 |
|
473 | 475 |
|
474 | | -def get_push_changes_batch(mc, mp: MerginProject) -> Tuple[dict, int]: |
| 476 | +def get_push_changes_batch(mc, mp: MerginProject) -> Tuple[LocalChanges, int]: |
475 | 477 | """ |
476 | 478 | Get changes that need to be pushed to the server. |
477 | 479 | """ |
478 | 480 | changes = mp.get_push_changes() |
479 | 481 | project_role = mp.project_role() |
480 | 482 | changes = filter_changes(mc, project_role, changes) |
481 | 483 |
|
482 | | - return changes, sum(len(v) for v in changes.values()) |
| 484 | + local_changes = LocalChanges( |
| 485 | + added=[LocalChange(**change) for change in changes["added"]], |
| 486 | + updated=[LocalChange(**change) for change in changes["updated"]], |
| 487 | + removed=[LocalChange(**change) for change in changes["removed"]], |
| 488 | + ) |
| 489 | + if local_changes.get_media_upload_size() > MAX_UPLOAD_MEDIA_SIZE: |
| 490 | + raise ClientError( |
| 491 | + f"Total size of media files to upload exceeds the maximum allowed size of {MAX_UPLOAD_MEDIA_SIZE / (1024**3)} GiB." |
| 492 | + ) |
| 493 | + |
| 494 | + if local_changes.get_gpgk_upload_size() > MAX_UPLOAD_VERSIONED_SIZE: |
| 495 | + raise ClientError( |
| 496 | + f"Total size of GPKG files to upload exceeds the maximum allowed size of {MAX_UPLOAD_VERSIONED_SIZE / (1024**3)} GiB." |
| 497 | + ) |
| 498 | + |
| 499 | + return local_changes, sum(len(v) for v in changes.values()) |
0 commit comments