@@ -96,36 +96,15 @@ class ChangesHandler:
96
96
- Generating upload-ready change groups for asynchronous job creation.
97
97
"""
98
98
99
- def __init__ (self , client , mp ):
99
+ def __init__ (self , client , project_dir ):
100
100
self .client = client
101
- self .mp = MerginProject (mp )
101
+ self .mp = MerginProject (project_dir )
102
102
self ._raw_changes = self .mp .get_push_changes ()
103
103
104
104
@staticmethod
105
105
def is_blocking_file (file ):
106
106
return is_qgis_file (file ["path" ]) or is_versioned_file (file ["path" ])
107
107
108
- def _filter_changes (self , changes : Dict [str , List [dict ]]) -> Dict [str , List [dict ]]:
109
- """
110
- Filters the given changes dictionary based on the editor's enabled state.
111
-
112
- If the editor is not enabled, the changes dictionary is returned as-is. Otherwise, the changes are passed through the `_apply_editor_filters` method to apply any configured filters.
113
-
114
- Args:
115
- changes (dict[str, list[dict]]): A dictionary mapping file paths to lists of change dictionaries.
116
-
117
- Returns:
118
- dict[str, list[dict]]: The filtered changes dictionary.
119
- """
120
- project_name = self .mp .project_full_name ()
121
- try :
122
- project_info = self .client .project_info (project_name )
123
- except Exception as e :
124
- self .mp .log .error (f"Failed to get project info for project { project_name } : { e } " )
125
- if not is_editor_enabled (self .client , project_info ):
126
- return changes
127
- return _apply_editor_filters (changes )
128
-
129
108
def _split_by_type (self , changes : Dict [str , List [dict ]]) -> List [Dict [str , List [dict ]]]:
130
109
"""
131
110
Split raw filtered changes into two batches:
@@ -159,12 +138,35 @@ def split(self) -> List[Dict[str, List[dict]]]:
159
138
"""
160
139
Applies all configured internal filters and returns a list of change ready to be uploaded.
161
140
"""
162
- changes = self ._filter_changes (self ._raw_changes )
141
+ project_name = self .mp .project_full_name ()
142
+ try :
143
+ project_info = self .client .project_info (project_name )
144
+ except ClientError as e :
145
+ self .mp .log .error (f"Failed to get project info for project { project_name } : { e } " )
146
+ raise
147
+ changes = self .filter_changes (self .client , project_info , self ._raw_changes )
163
148
changes_list = self ._split_by_type (changes )
164
149
# TODO: apply limits; changes = self._limit_by_file_count(changes)
165
150
return changes_list
166
151
167
152
153
+ def filter_changes (mc , project_info , changes : Dict [str , List [dict ]]) -> Dict [str , List [dict ]]:
154
+ """
155
+ Filters the given changes dictionary based on the editor's enabled state.
156
+
157
+ If the editor is not enabled, the changes dictionary is returned as-is. Otherwise, the changes are passed through the `_apply_editor_filters` method to apply any configured filters.
158
+
159
+ Args:
160
+ changes (dict[str, list[dict]]): A dictionary mapping file paths to lists of change dictionaries.
161
+
162
+ Returns:
163
+ dict[str, list[dict]]: The filtered changes dictionary.
164
+ """
165
+ if is_editor_enabled (mc , project_info ):
166
+ changes = _apply_editor_filters (changes )
167
+ return changes
168
+
169
+
168
170
def get_change_batch (mc , project_dir ) -> Tuple [Optional [Dict [str , List [dict ]]], bool ]:
169
171
"""
170
172
Return the next changes dictionary and flag if there are more changes (to be uploaded in the next upload job)
@@ -176,13 +178,14 @@ def get_change_batch(mc, project_dir) -> Tuple[Optional[Dict[str, List[dict]]],
176
178
return changes_list [0 ], non_empty_length > 1
177
179
178
180
179
- def push_project_async (mc , directory , change_batch = None ) -> Optional [UploadJob ]:
181
+ def push_project_async (mc , directory , changes = None ) -> Optional [UploadJob ]:
180
182
"""
181
183
Starts push in background and returns pending upload job.
182
184
Pushes all project changes unless change_batch is provided.
183
185
When specific change is provided, initial version check is skipped (the pull has just been done).
184
186
185
- :param change_batch: A dictionary of changes that was split to blocking and non-blocking.
187
+ :param changes: The changes to upload are either (1) provided (and already split to blocking and bob-blocking batches)
188
+ or (2) all local changes are retrieved to upload
186
189
Pushing only non-blocking changes results in non-exclusive upload which server allows to be concurrent.
187
190
"""
188
191
@@ -197,7 +200,7 @@ def push_project_async(mc, directory, change_batch=None) -> Optional[UploadJob]:
197
200
mp .log .info (f"--- start push { project_path } " )
198
201
199
202
# if we have specific change to push we don't need version check
200
- if not change_batch :
203
+ if not changes :
201
204
try :
202
205
project_info = mc .project_info (project_path )
203
206
except ClientError as err :
@@ -222,8 +225,8 @@ def push_project_async(mc, directory, change_batch=None) -> Optional[UploadJob]:
222
225
"There is a new version of the project on the server. Please update your local copy."
223
226
+ f"\n \n Local version: { local_version } \n Server version: { server_version } "
224
227
)
228
+ changes = filter_changes (mc , project_info , mp .get_push_changes ())
225
229
226
- changes = change_batch or mp .get_push_changes ()
227
230
mp .log .debug ("push change:\n " + pprint .pformat (changes ))
228
231
229
232
tmp_dir = tempfile .TemporaryDirectory (prefix = "python-api-client-" )
0 commit comments