77import uuid
88import tempfile
99from datetime import datetime
10+ from typing import List , Dict
1011from dateutil .tz import tzlocal
1112
12- from .client_push import UploadChanges
1313from .editor import prevent_conflicted_copy
1414
1515from .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