diff --git a/.gitignore b/.gitignore index 2328913..abe9154 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ build **/qfieldcloud_sdk_python.egg-info .env Pipfile* +docs/site/* .venv diff --git a/docs/docs/examples.md b/docs/docs/examples.md index 071e83b..6de6e75 100644 --- a/docs/docs/examples.md +++ b/docs/docs/examples.md @@ -227,7 +227,21 @@ To free up storage on QFieldCloud, you can delete unnecessary files, such as `.j qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" --filter "*.jpg" ``` -You can also delete specific files by specifying their exact path: +Or if multiple type of files: + +=== ":material-bash: Bash" + + ```bash + qfieldcloud-cli delete-files '123e4567-e89b-12d3-a456-426614174000' --filter '*.jpg' '*.csv' + ``` + +=== ":material-powershell: PowerShell" + + ```powershell + qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" --filter "*.jpg" "*.csv" + ``` + +You can also delete specific files by specifying their exact paths: === ":material-bash: Bash" @@ -241,6 +255,22 @@ You can also delete specific files by specifying their exact path: qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" "DCIM\tree-202411202334943.jpg" ``` +Or for multiples files: + +You can also delete specific files by specifying their exact paths: + +=== ":material-bash: Bash" + + ```bash + qfieldcloud-cli delete-files '123e4567-e89b-12d3-a456-426614174000' 'DCIM/tree-202411202334943.jpg' 'DCIM/tree-202411202331234.jpg' + ``` + +=== ":material-powershell: PowerShell" + + ```powershell + qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" "DCIM\tree-202411202334943.jpg" "DCIM/tree-202411202331234.jpg" + ``` + ### Manage Members and Collaborators The collaborative nature of QFieldCloud naturally involves other people in the fieldwork. diff --git a/qfieldcloud_sdk/cli.py b/qfieldcloud_sdk/cli.py index 19feda8..55958ec 100755 --- a/qfieldcloud_sdk/cli.py +++ b/qfieldcloud_sdk/cli.py @@ -510,16 +510,30 @@ def patch_project( @cli.command() @click.argument("project_id") -@click.argument("paths", nargs=-1, required=True) +@click.argument("paths", nargs=-1) +@click.option( + "--filter", + "filter_glob", + multiple=True, + help="Glob pattern to filter files for deletion (e.g., '*.jpg'). Can be provided multiple times.", +) @click.option( "--throw-on-error/--no-throw-on-error", - help="If any project file delete operations fails stop, stop deleting the rest. Default: False", + help="If any project file delete operations fails, stop deleting the rest. Default: False", ) @click.pass_context -def delete_files(ctx: Context, project_id, paths, throw_on_error): +def delete_files(ctx: Context, project_id, paths, filter_glob, throw_on_error): """Delete QFieldCloud project files.""" - paths_result = ctx.obj["client"].delete_files(project_id, paths, throw_on_error) + all_patterns = list(paths) + list(filter_glob) + + if not all_patterns: + log("You must provide at least one file path or use the --filter option.") + return + + paths_result = ctx.obj["client"].delete_files( + project_id, all_patterns, throw_on_error + ) if ctx.obj["format_json"]: print_json(paths_result) diff --git a/qfieldcloud_sdk/sdk.py b/qfieldcloud_sdk/sdk.py index 9b10eef..23f7c52 100644 --- a/qfieldcloud_sdk/sdk.py +++ b/qfieldcloud_sdk/sdk.py @@ -1018,20 +1018,18 @@ def delete_files( file["status"] = FileTransferStatus.SUCCESS except QfcRequestException as err: resp = err.response - logger.info( f"{resp.request.method} {resp.url} got HTTP {resp.status_code}" ) file["status"] = FileTransferStatus.FAILED file["error"] = err - log(f'File "{file["name"]}" failed to delete:\n{file["error"]}') if throw_on_error: - continue - else: raise err + else: + continue finally: if callable(finished_cb): finished_cb(file) @@ -1044,7 +1042,7 @@ def delete_files( if file["status"] == FileTransferStatus.SUCCESS: files_deleted += 1 - elif file["status"] == FileTransferStatus.SUCCESS: + elif file["status"] == FileTransferStatus.FAILED: files_failed += 1 log(f"{files_deleted} file(s) deleted, {files_failed} file(s) failed to delete")