Skip to content

Commit 7aa5530

Browse files
committed
Fixing delete files flag and other improvements
1 parent 105a10d commit 7aa5530

4 files changed

Lines changed: 52 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ build
55
**/qfieldcloud_sdk_python.egg-info
66
.env
77
Pipfile*
8+
docs/site/*

docs/docs/examples.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,21 @@ To free up storage on QFieldCloud, you can delete unnecessary files, such as `.j
227227
qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" --filter "*.jpg"
228228
```
229229

230-
You can also delete specific files by specifying their exact path:
230+
Or if multiple type of files:
231+
232+
=== ":material-bash: Bash"
233+
234+
```bash
235+
qfieldcloud-cli delete-files '123e4567-e89b-12d3-a456-426614174000' --filter '*.jpg' '*.csv'
236+
```
237+
238+
=== ":material-powershell: PowerShell"
239+
240+
```powershell
241+
qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" --filter "*.jpg" '*.csv'
242+
```
243+
244+
You can also delete specific files by specifying their exact paths:
231245

232246
=== ":material-bash: Bash"
233247

@@ -241,6 +255,22 @@ You can also delete specific files by specifying their exact path:
241255
qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" "DCIM\tree-202411202334943.jpg"
242256
```
243257

258+
Or for multiples files:
259+
260+
You can also delete specific files by specifying their exact paths:
261+
262+
=== ":material-bash: Bash"
263+
264+
```bash
265+
qfieldcloud-cli delete-files '123e4567-e89b-12d3-a456-426614174000' 'DCIM/tree-202411202334943.jpg' 'DCIM/tree-202411202331234.jpg'
266+
```
267+
268+
=== ":material-powershell: PowerShell"
269+
270+
```powershell
271+
qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" "DCIM\tree-202411202334943.jpg" "DCIM/tree-202411202331234.jpg"
272+
```
273+
244274
### Manage Members and Collaborators
245275

246276
The collaborative nature of QFieldCloud naturally involves other people in the fieldwork.

qfieldcloud_sdk/cli.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,16 +459,28 @@ def patch_project(
459459

460460
@cli.command()
461461
@click.argument("project_id")
462-
@click.argument("paths", nargs=-1, required=True)
462+
@click.argument("paths", nargs=-1)
463+
@click.option(
464+
"--filter",
465+
multiple=True,
466+
help="Glob pattern to filter files for deletion (e.g., '*.jpg'). Can be provided multiple times.",
467+
)
463468
@click.option(
464469
"--throw-on-error/--no-throw-on-error",
465470
help="If any project file delete operations fails stop, stop deleting the rest. Default: False",
466471
)
467472
@click.pass_context
468-
def delete_files(ctx: Context, project_id, paths, throw_on_error):
473+
def delete_files(ctx: Context, project_id, paths, filter, throw_on_error):
469474
"""Delete QFieldCloud project files."""
470475

471-
paths_result = ctx.obj["client"].delete_files(project_id, paths, throw_on_error)
476+
all_patterns = list(paths) + list(filter)
477+
478+
if not all_patterns:
479+
log("You must provide at least one file path or use the --filter option.")
480+
481+
paths_result = ctx.obj["client"].delete_files(
482+
project_id, all_patterns, throw_on_error
483+
)
472484

473485
if ctx.obj["format_json"]:
474486
print_json(paths_result)

qfieldcloud_sdk/sdk.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -946,20 +946,18 @@ def delete_files(
946946
file["status"] = FileTransferStatus.SUCCESS
947947
except QfcRequestException as err:
948948
resp = err.response
949-
950949
logger.info(
951950
f"{resp.request.method} {resp.url} got HTTP {resp.status_code}"
952951
)
953952

954953
file["status"] = FileTransferStatus.FAILED
955954
file["error"] = err
956-
957955
log(f'File "{file["name"]}" failed to delete:\n{file["error"]}')
958956

959957
if throw_on_error:
960-
continue
961-
else:
962958
raise err
959+
else:
960+
continue
963961
finally:
964962
if callable(finished_cb):
965963
finished_cb(file)
@@ -972,13 +970,15 @@ def delete_files(
972970

973971
if file["status"] == FileTransferStatus.SUCCESS:
974972
files_deleted += 1
975-
elif file["status"] == FileTransferStatus.SUCCESS:
973+
elif file["status"] == FileTransferStatus.FAILED:
976974
files_failed += 1
977975

978976
log(f"{files_deleted} file(s) deleted, {files_failed} file(s) failed to delete")
979977

980978
return glob_results
981979

980+
return glob_results
981+
982982
def delete_file(
983983
self,
984984
project_id: str,

0 commit comments

Comments
 (0)