Skip to content

Commit 53b3604

Browse files
committed
Add docs and rename exit_on_error to throw_on_error
1 parent 52b11f7 commit 53b3604

3 files changed

Lines changed: 79 additions & 31 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ qfieldcloud-cli upload-files [OPTIONS] PROJECT_ID PROJECT_PATH
158158
Options:
159159
--filter TEXT Do not upload the whole project, but only
160160
the files which match the glob.
161-
--exit-on-error / --no-exit-on-error
161+
--throw-on-error / --no-throw-on-error
162162
If any project file upload fails stop
163163
uploading the rest. Default: False
164164
```
@@ -173,7 +173,7 @@ qfieldcloud-cli download-files [OPTIONS] PROJECT_ID LOCAL_DIR
173173
Options:
174174
--filter TEXT Do not download the whole project, but only
175175
the files which match the glob.
176-
--exit-on-error / --no-exit-on-error
176+
--throw-on-error / --no-throw-on-error
177177
If any project file downloads fails stop
178178
downloading the rest. Default: False
179179
```
@@ -186,7 +186,7 @@ Delete QFieldCloud project files.
186186
qfieldcloud-cli delete-files [OPTIONS] PROJECT_ID PATHS...
187187
188188
Options:
189-
--exit-on-error / --no-exit-on-error
189+
--throw-on-error / --no-throw-on-error
190190
If any project file delete operations fails
191191
stop, stop deleting the rest. Default: False
192192
```
@@ -240,7 +240,7 @@ qfieldcloud-cli package-download [OPTIONS] PROJECT_ID LOCAL_DIR
240240
Options:
241241
--filter TEXT Do not download the whole packaged project,
242242
but only the files which match the glob.
243-
--exit-on-error / --no-exit-on-error
243+
--throw-on-error / --no-throw-on-error
244244
If any packaged file downloads fails stop
245245
downloading the rest. Default: False
246246
```

src/bin/qfieldcloud-cli

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ def delete_project(ctx, project_id):
236236
help="Do not upload the whole project, but only the files which match the glob.",
237237
)
238238
@click.option(
239-
"--exit-on-error/--no-exit-on-error",
239+
"--throw-on-error/--no-throw-on-error",
240240
help="If any project file upload fails stop uploading the rest. Default: False",
241241
)
242242
@click.pass_context
243-
def upload_files(ctx, project_id, project_path, filter_glob, exit_on_error):
243+
def upload_files(ctx, project_id, project_path, filter_glob, throw_on_error):
244244
"""Upload files to a QFieldCloud project."""
245245

246246
log(f'Uploading files "{project_id}" from {project_path}…')
@@ -250,7 +250,7 @@ def upload_files(ctx, project_id, project_path, filter_glob, exit_on_error):
250250
sdk.FileTransferType.PROJECT,
251251
project_path,
252252
filter_glob=filter_glob,
253-
exit_on_error=exit_on_error,
253+
throw_on_error=throw_on_error,
254254
show_progress=True,
255255
)
256256

@@ -275,17 +275,17 @@ def upload_files(ctx, project_id, project_path, filter_glob, exit_on_error):
275275
help="Do not download the whole project, but only the files which match the glob.",
276276
)
277277
@click.option(
278-
"--exit-on-error/--no-exit-on-error",
278+
"--throw-on-error/--no-throw-on-error",
279279
help="If any project file downloads fails stop downloading the rest. Default: False",
280280
)
281281
@click.pass_context
282-
def download_files(ctx, project_id, local_dir, filter_glob, exit_on_error):
282+
def download_files(ctx, project_id, local_dir, filter_glob, throw_on_error):
283283
"""Download QFieldCloud project files."""
284284

285285
log(f'Downloading project "{project_id}" files to {local_dir}…')
286286

287287
files = ctx.obj["client"].download_project(
288-
project_id, local_dir, filter_glob, exit_on_error, show_progress=True
288+
project_id, local_dir, filter_glob, throw_on_error, show_progress=True
289289
)
290290

291291
if ctx.obj["format_json"]:
@@ -313,16 +313,16 @@ def download_files(ctx, project_id, local_dir, filter_glob, exit_on_error):
313313
@click.argument("project_id")
314314
@click.argument("paths", nargs=-1, required=True)
315315
@click.option(
316-
"--exit-on-error/--no-exit-on-error",
316+
"--throw-on-error/--no-throw-on-error",
317317
help="If any project file delete operations fails stop, stop deleting the rest. Default: False",
318318
)
319319
@click.pass_context
320-
def delete_files(ctx, project_id, paths, exit_on_error):
320+
def delete_files(ctx, project_id, paths, throw_on_error):
321321
"""Delete QFieldCloud project files."""
322322

323323
log(f'Deleting project "{project_id}" files…')
324324

325-
paths_result = ctx.obj["client"].delete_files(project_id, paths, exit_on_error)
325+
paths_result = ctx.obj["client"].delete_files(project_id, paths, throw_on_error)
326326

327327
if ctx.obj["format_json"]:
328328
print_json(paths_result)
@@ -422,17 +422,17 @@ def package_latest(ctx, project_id):
422422
help="Do not download the whole packaged project, but only the files which match the glob.",
423423
)
424424
@click.option(
425-
"--exit-on-error/--no-exit-on-error",
425+
"--throw-on-error/--no-throw-on-error",
426426
help="If any packaged file downloads fails stop downloading the rest. Default: False",
427427
)
428428
@click.pass_context
429-
def package_download(ctx, project_id, local_dir, filter_glob, exit_on_error):
429+
def package_download(ctx, project_id, local_dir, filter_glob, throw_on_error):
430430
"""Download packaged QFieldCloud project files."""
431431

432432
log(f'Downloading the latest project "{project_id}" package files to {local_dir}…')
433433

434434
files = ctx.obj["client"].package_download(
435-
project_id, local_dir, filter_glob, exit_on_error, show_progress=True
435+
project_id, local_dir, filter_glob, throw_on_error, show_progress=True
436436
)
437437

438438
if ctx.obj["format_json"]:

src/qfieldcloud_sdk/sdk.py

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def upload_files(
176176
upload_type: FileTransferType,
177177
project_path: str,
178178
filter_glob: str,
179-
exit_on_error: bool = False,
179+
throw_on_error: bool = False,
180180
show_progress: bool = False,
181181
job_id: str = "",
182182
) -> List[Dict]:
@@ -206,7 +206,7 @@ def upload_files(
206206
file["status"] = UploadStatus.FAILED
207207
file["error"] = err
208208

209-
if exit_on_error:
209+
if throw_on_error:
210210
raise err
211211
else:
212212
continue
@@ -262,7 +262,7 @@ def download_project(
262262
project_id: str,
263263
local_dir: str,
264264
filter_glob: str = None,
265-
exit_on_error: bool = False,
265+
throw_on_error: bool = False,
266266
show_progress: bool = False,
267267
) -> List[Dict]:
268268
"""Download the specified project files into the destination dir.
@@ -281,7 +281,7 @@ def download_project(
281281
FileTransferType.PROJECT,
282282
local_dir,
283283
filter_glob,
284-
exit_on_error,
284+
throw_on_error,
285285
show_progress,
286286
)
287287

@@ -327,9 +327,23 @@ def delete_files(
327327
self,
328328
project_id: str,
329329
glob_patterns: List[str],
330-
continue_on_error: bool = False,
330+
throw_on_error: bool = False,
331331
finished_cb: Callable = None,
332332
) -> Dict[str, Dict[str, Any]]:
333+
"""Delete project files.
334+
335+
Args:
336+
project_id (str): Project id
337+
glob_patterns (List[str]): Delete only files matching one the glob patterns.
338+
throw_on_error (bool, optional): Throw if delete error occurres. Defaults to False.
339+
finished_cb (Callable, optional): Deprecated. Defaults to None.
340+
341+
Raises:
342+
QFieldCloudException: if throw_on_error is True, throw an error if a download request fails.
343+
344+
Returns:
345+
Dict[str, Dict[str, Any]]: Deleted files by glob pattern.
346+
"""
333347
project_files = self.list_files(project_id)
334348
glob_results = {}
335349
self._log(f"Project '{project_id}' has {len(project_files)} file(s).")
@@ -375,7 +389,7 @@ def delete_files(
375389
f'File "{file["name"]}" failed to delete:\n{file["error"]}'
376390
)
377391

378-
if continue_on_error:
392+
if throw_on_error:
379393
continue
380394
else:
381395
raise err
@@ -411,7 +425,7 @@ def package_download(
411425
project_id: str,
412426
local_dir: str,
413427
filter_glob: str = None,
414-
exit_on_error: bool = False,
428+
throw_on_error: bool = False,
415429
show_progress: bool = False,
416430
) -> List[Dict]:
417431
"""Download the specified project packaged files into the destination dir.
@@ -436,7 +450,7 @@ def package_download(
436450
FileTransferType.PACKAGE,
437451
local_dir,
438452
filter_glob,
439-
exit_on_error,
453+
throw_on_error,
440454
show_progress,
441455
)
442456

@@ -447,9 +461,26 @@ def download_files(
447461
download_type: FileTransferType,
448462
local_dir: str,
449463
filter_glob: str = None,
450-
exit_on_error: bool = False,
464+
throw_on_error: bool = False,
451465
show_progress: bool = False,
452466
) -> List[Dict]:
467+
"""Download project files.
468+
469+
Args:
470+
files (List[Dict]): A list of file dicts, specifying which files to download.
471+
project_id (str): Project id
472+
download_type (FileTransferType): File transfer type which specifies what should be the download url.
473+
local_dir (str): Local destination directory
474+
filter_glob (str, optional): Download only files matching the glob pattern. If None download all. Defaults to None.
475+
throw_on_error (bool, optional): Throw if download error occurres. Defaults to False.
476+
show_progress (bool, optional): Show progress bar in the console. Defaults to False.
477+
478+
Raises:
479+
QFieldCloudException: if throw_on_error is True, throw an error if a download request fails.
480+
481+
Returns:
482+
List[Dict]: A list of file dicts.
483+
"""
453484
if not filter_glob:
454485
filter_glob = "*"
455486

@@ -482,7 +513,7 @@ def download_files(
482513
file["status"] = DownloadStatus.FAILED
483514
file["error"] = err
484515

485-
if exit_on_error:
516+
if throw_on_error:
486517
raise err
487518
else:
488519
continue
@@ -497,6 +528,21 @@ def download_file(
497528
remote_filename: Path,
498529
show_progress: bool,
499530
) -> requests.Response:
531+
"""Download a single project file.
532+
533+
Args:
534+
project_id (str): Project id
535+
download_type (FileTransferType): File transfer type which specifies what should be the download URL
536+
local_filename (Path): Local filename
537+
remote_filename (Path): Remote filename
538+
show_progress (bool): Show progressbar in the console
539+
540+
Raises:
541+
NotImplementedError: Raised if unknown `download_type` is passed
542+
543+
Returns:
544+
requests.Response: the response object
545+
"""
500546
if download_type == FileTransferType.PROJECT:
501547
url = f"files/{project_id}/{remote_filename}"
502548
elif download_type == FileTransferType.PACKAGE:
@@ -532,18 +578,20 @@ def download_file(
532578

533579
return resp
534580

535-
def get_files_list(
536-
self, project_path: str, filter_glob: str
537-
) -> List[Dict[str, Any]]:
581+
def get_files_list(self, root_path: str, filter_glob: str) -> List[Dict[str, Any]]:
582+
"""
583+
Returns a list of dicts with information about local files. Usually used before uploading files.
584+
NOTE: files and dirs starting with leading zero in the root directory will be ignored.
585+
"""
538586
if not filter_glob:
539587
filter_glob = "*"
540588

541589
files: List[Dict[str, Any]] = []
542-
for path in Path(project_path).rglob(filter_glob):
590+
for path in Path(root_path).rglob(filter_glob):
543591
if not path.is_file():
544592
continue
545593

546-
if str(path.relative_to(project_path)).startswith(".qfieldsync"):
594+
if str(path.relative_to(root_path)).startswith("."):
547595
continue
548596

549597
files.append(

0 commit comments

Comments
 (0)