Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ build
**/qfieldcloud_sdk_python.egg-info
.env
Pipfile*
docs/site/*
.venv
32 changes: 31 additions & 1 deletion docs/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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.
Expand Down
22 changes: 18 additions & 4 deletions qfieldcloud_sdk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions qfieldcloud_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down