|
19 | 19 | from .common import UPLOAD_CHUNK_SIZE, ClientError |
20 | 20 | from .merginproject import MerginProject |
21 | 21 | from .editor import filter_changes |
| 22 | +from .utils import is_qgis_file, is_versioned_file |
22 | 23 |
|
23 | 24 |
|
24 | 25 | class UploadJob: |
@@ -122,6 +123,23 @@ def push_project_async(mc, directory): |
122 | 123 |
|
123 | 124 | changes = mp.get_push_changes() |
124 | 125 | changes = filter_changes(mc, project_info, changes) |
| 126 | + |
| 127 | + blocking_changes, non_blocking_changes = split_changes(changes) |
| 128 | + |
| 129 | + blocking_job = ( |
| 130 | + _prepare_upload_job(mp, mc, project_path, local_version, blocking_changes) |
| 131 | + if any(len(v) for v in blocking_changes.values()) |
| 132 | + else None |
| 133 | + ) |
| 134 | + non_blocking_job = ( |
| 135 | + _prepare_upload_job(mp, mc, project_path, local_version, non_blocking_changes) |
| 136 | + if any(len(v) for v in non_blocking_changes.values()) |
| 137 | + else None |
| 138 | + ) |
| 139 | + |
| 140 | + return blocking_job, non_blocking_job |
| 141 | + |
| 142 | +def _prepare_upload_job(mp, mc, project_path, local_version, changes): |
125 | 143 | mp.log.debug("push changes:\n" + pprint.pformat(changes)) |
126 | 144 |
|
127 | 145 | tmp_dir = tempfile.TemporaryDirectory(prefix="python-api-client-") |
@@ -206,10 +224,8 @@ def push_project_async(mc, directory): |
206 | 224 | for item in upload_queue_items: |
207 | 225 | future = job.executor.submit(_do_upload, item, job) |
208 | 226 | job.futures.append(future) |
209 | | - |
210 | 227 | return job |
211 | 228 |
|
212 | | - |
213 | 229 | def push_project_wait(job): |
214 | 230 | """blocks until all upload tasks are finished""" |
215 | 231 |
|
@@ -334,3 +350,26 @@ def remove_diff_files(job) -> None: |
334 | 350 | diff_file = job.mp.fpath_meta(change["diff"]["path"]) |
335 | 351 | if os.path.exists(diff_file): |
336 | 352 | os.remove(diff_file) |
| 353 | + |
| 354 | + |
| 355 | +def split_changes(changes): |
| 356 | + """Split changes into blocking and non-blocking. |
| 357 | +
|
| 358 | + Blocking criteria: |
| 359 | + - any updated files |
| 360 | + - any removed files |
| 361 | + - added files that are .gpkg or .qgz (.ggs) |
| 362 | + """ |
| 363 | + blocking = non_blocking = {"added": [], "updated": [], "removed": [], "renamed": []} |
| 364 | + |
| 365 | + blocking["updated"] = changes["updated"] |
| 366 | + blocking["removed"] = changes["removed"] |
| 367 | + blocking["renamed"] = changes["renamed"] |
| 368 | + |
| 369 | + for f in changes["added"]: |
| 370 | + if is_qgis_file(f["path"]) or is_versioned_file(f["path"]): |
| 371 | + blocking["added"].append(f) |
| 372 | + else: |
| 373 | + non_blocking["added"].append(f) |
| 374 | + |
| 375 | + return blocking, non_blocking |
0 commit comments