12
12
from .common import UPLOAD_CHUNK_SIZE , InvalidProject , ClientError
13
13
from .utils import (
14
14
generate_checksum ,
15
- move_file ,
15
+ is_versioned_file ,
16
16
int_version ,
17
- find ,
18
17
do_sqlite_checkpoint ,
19
18
unique_path_name ,
20
19
conflicted_copy_file_name ,
@@ -138,8 +137,7 @@ def fpath_cache(self, file, version=None):
138
137
139
138
def project_full_name (self ) -> str :
140
139
"""Returns fully qualified project name: <workspace>/<name>"""
141
- if self ._metadata is None :
142
- self ._read_metadata ()
140
+ self ._read_metadata ()
143
141
if self .is_old_metadata :
144
142
return self ._metadata ["name" ]
145
143
else :
@@ -164,8 +162,7 @@ def project_id(self) -> str:
164
162
only happen with projects downloaded with old client, before February 2023,
165
163
see https://github.com/MerginMaps/mergin-py-client/pull/154
166
164
"""
167
- if self ._metadata is None :
168
- self ._read_metadata ()
165
+ self ._read_metadata ()
169
166
170
167
# "id" or "project_id" may not exist in projects downloaded with old client version
171
168
if self .is_old_metadata :
@@ -182,8 +179,7 @@ def workspace_id(self) -> int:
182
179
"""Returns ID of the workspace where the project belongs"""
183
180
# unfortunately we currently do not have information about workspace ID
184
181
# in project's metadata...
185
- if self ._metadata is None :
186
- self ._read_metadata ()
182
+ self ._read_metadata ()
187
183
188
184
# "workspace_id" does not exist in projects downloaded with old client version
189
185
if self .is_old_metadata :
@@ -195,14 +191,12 @@ def workspace_id(self) -> int:
195
191
196
192
def version (self ) -> str :
197
193
"""Returns project version (e.g. "v123")"""
198
- if self ._metadata is None :
199
- self ._read_metadata ()
194
+ self ._read_metadata ()
200
195
return self ._metadata ["version" ]
201
196
202
197
def files (self ) -> list :
203
198
"""Returns project's list of files (each file being a dictionary)"""
204
- if self ._metadata is None :
205
- self ._read_metadata ()
199
+ self ._read_metadata ()
206
200
return self ._metadata ["files" ]
207
201
208
202
@property
@@ -213,12 +207,13 @@ def metadata(self) -> dict:
213
207
from warnings import warn
214
208
215
209
warn ("MerginProject.metadata getter should not be used anymore" , DeprecationWarning )
216
- if self ._metadata is None :
217
- self ._read_metadata ()
210
+ self ._read_metadata ()
218
211
return self ._metadata
219
212
220
- def _read_metadata (self ):
213
+ def _read_metadata (self ) -> None :
221
214
"""Loads the project's metadata from JSON"""
215
+ if self ._metadata is not None :
216
+ return
222
217
if not os .path .exists (self .fpath_meta ("mergin.json" )):
223
218
raise InvalidProject ("Project metadata has not been created yet" )
224
219
with open (self .fpath_meta ("mergin.json" ), "r" ) as file :
@@ -254,9 +249,7 @@ def is_versioned_file(self, file):
254
249
:returns: if file is compatible with geodiff lib
255
250
:rtype: bool
256
251
"""
257
- diff_extensions = [".gpkg" , ".sqlite" ]
258
- f_extension = os .path .splitext (file )[1 ]
259
- return f_extension in diff_extensions
252
+ return is_versioned_file (file )
260
253
261
254
def is_gpkg_open (self , path ):
262
255
"""
0 commit comments