Skip to content

Commit 7081687

Browse files
committed
Put changes dicts back
1 parent ff3afac commit 7081687

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

mergin/client_push.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import tempfile
1616
import concurrent.futures
1717
import os
18-
from typing import Dict, List
18+
from typing import Dict, List, Optional
1919

2020
from .common import UPLOAD_CHUNK_SIZE, ClientError
2121
from .merginproject import MerginProject
@@ -139,7 +139,7 @@ def split_by_type(self) -> List[Dict[str, List[dict]]]:
139139
return result
140140

141141

142-
def push_project_async(mc, directory) -> List[UploadJob]:
142+
def push_project_async(mc, directory) -> Optional[List[UploadJob]]:
143143
"""Starts push of a project and returns pending upload jobs"""
144144

145145
mp = MerginProject(directory)
@@ -164,8 +164,8 @@ def push_project_async(mc, directory) -> List[UploadJob]:
164164

165165
username = mc.username()
166166
# permissions field contains information about update, delete and upload privileges of the user
167-
# on a specific project. This is more accurate information then "writernames" field, as it takes
168-
# into account namespace privileges. So we have to check only "permissions", namely "upload" one
167+
# on a specific project. This is more accurate information than "writernames" field, as it takes
168+
# into account namespace privileges. So we have to check only "permissions", namely "upload" once
169169
if not mc.has_writing_permissions(project_path):
170170
mp.log.error(f"--- push {project_path} - username {username} does not have write access")
171171
raise ClientError(f"You do not seem to have write access to the project (username '{username}')")
@@ -180,12 +180,12 @@ def push_project_async(mc, directory) -> List[UploadJob]:
180180
changes_handler = UploadChangesHandler(mp, mc, project_info)
181181
changes_groups = changes_handler.split_by_type()
182182

183+
tmp_dir = tempfile.TemporaryDirectory(prefix="python-api-client-")
183184
jobs = []
185+
184186
for changes in changes_groups:
185187
mp.log.debug("push changes:\n" + pprint.pformat(changes))
186188

187-
tmp_dir = tempfile.TemporaryDirectory(prefix="python-api-client-")
188-
189189
# If there are any versioned files (aka .gpkg) that are not updated through a diff,
190190
# we need to make a temporary copy somewhere to be sure that we are uploading full content.
191191
# That's because if there are pending transactions, checkpointing or switching from WAL mode

mergin/editor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from itertools import filterfalse
22
from typing import Callable, Dict, List
33

4-
from .client_push import UploadChanges
5-
from .utils import is_mergin_config, is_qgis_file, is_versioned_file
4+
from .utils import is_qgis_file
65

76
EDITOR_ROLE_NAME = "editor"
87

@@ -37,7 +36,7 @@ def _apply_editor_filters(changes: Dict[str, List[dict]]) -> Dict[str, List[dict
3736
"""
3837
updated = changes.get("updated", [])
3938

40-
changes.updated = list(filterfalse(_disallowed_changes, updated))
39+
changes["updated"] = list(filterfalse(_disallowed_changes, updated))
4140
return changes
4241

4342

mergin/merginproject.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import uuid
88
import tempfile
99
from datetime import datetime
10+
from typing import List, Dict
1011
from dateutil.tz import tzlocal
1112

12-
from .client_push import UploadChanges
1313
from .editor import prevent_conflicted_copy
1414

1515
from .common import UPLOAD_CHUNK_SIZE, InvalidProject, ClientError
@@ -315,13 +315,20 @@ def inspect_files(self):
315315
)
316316
return files_meta
317317

318-
def compare_file_sets(self, origin, current) -> UploadChanges:
319-
"""
320-
Calculate difference between two sets of file metadata using file names and checksums.
321-
322-
:param origin: List of original file metadata
323-
:param current: List of current file metadata
324-
:return: UploadChanges instance with added, updated, removed
318+
def compare_file_sets(self, origin, current) -> Dict[str, List[dict]]:
319+
"""
320+
Calculate difference between two sets of files metadata using file names and checksums.
321+
:Example:
322+
>>> origin = [{'checksum': '08b0e8caddafe74bf5c11a45f65cedf974210fed', 'path': 'base.gpkg', 'size': 2793, 'mtime': '2019-08-26T11:08:34.051221+02:00'}]
323+
>>> current = [{'checksum': 'c9a4fd2afd513a97aba19d450396a4c9df8b2ba4', 'path': 'test.qgs', 'size': 31980, 'mtime': '2019-08-26T11:09:30.051221+02:00'}]
324+
>>> self.compare_file_sets(origin, current)
325+
{"added": [{'checksum': 'c9a4fd2afd513a97aba19d450396a4c9df8b2ba4', 'path': 'test.qgs', 'size': 31980, 'mtime': '2019-08-26T11:09:30.051221+02:00'}], "removed": [[{'checksum': '08b0e8caddafe74bf5c11a45f65cedf974210fed', 'path': 'base.gpkg', 'size': 2793, 'mtime': '2019-08-26T11:08:34.051221+02:00'}]], "renamed": [], "updated": []}
326+
:param origin: origin set of files metadata
327+
:type origin: list[dict]
328+
:param current: current set of files metadata to be compared against origin
329+
:type current: list[dict]
330+
:returns: changes between two sets with change type
331+
:rtype: dict[str, list[dict]]'
325332
"""
326333
origin_map = {f["path"]: f for f in origin}
327334
current_map = {f["path"]: f for f in current}
@@ -338,12 +345,7 @@ def compare_file_sets(self, origin, current) -> UploadChanges:
338345
f["origin_checksum"] = origin_map[path]["checksum"]
339346
updated.append(f)
340347

341-
return UploadChanges(
342-
added=added,
343-
updated=updated,
344-
removed=removed,
345-
)
346-
348+
return {"renamed": [], "added": added, "removed": removed, "updated": updated}
347349

348350
def get_pull_changes(self, server_files):
349351
"""
@@ -401,7 +403,7 @@ def get_pull_changes(self, server_files):
401403
changes["updated"] = [f for f in changes["updated"] if f not in not_updated]
402404
return changes
403405

404-
def get_push_changes(self) -> UploadChanges:
406+
def get_push_changes(self) -> Dict[str, List[dict]]:
405407
"""
406408
Calculate changes needed to be pushed to server.
407409
@@ -425,7 +427,7 @@ def get_push_changes(self) -> UploadChanges:
425427

426428
# need to check for real changes in geodiff files using geodiff tool (comparing checksum is not enough)
427429
not_updated = []
428-
for file in changes.updated:
430+
for file in changes["updated"]:
429431
path = file["path"]
430432
if not self.is_versioned_file(path):
431433
continue
@@ -459,7 +461,7 @@ def get_push_changes(self) -> UploadChanges:
459461
# we will need to do full upload of the file
460462
pass
461463

462-
changes.updated = [f for f in changes.updated if f not in not_updated]
464+
changes["updated"] = [f for f in changes["updated"] if f not in not_updated]
463465
return changes
464466

465467
def copy_versioned_file_for_upload(self, f, tmp_dir):

0 commit comments

Comments
 (0)