Skip to content

Add a function to delete files individually #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions qfieldcloud_sdk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,26 @@ def delete_files(ctx: Context, project_id, paths, throw_on_error):
log(f'Deleting project "{project_id}" files…')


@cli.command()
@click.argument("project_id")
@click.argument("filename")
@click.option(
"--version-id",
help="Pass to delete a specific file version. Otherwise the file and all it's versions will be deleted.",
)
@click.pass_context
def delete_file(
ctx: Context, project_id: str, filename: str, version_id: Optional[str]
) -> None:
"""Delete QFieldCloud project files."""

log(f'Deleting file "{filename}" in project "{project_id}"…')

_resp = ctx.obj["client"].delete_file(project_id, filename, version_id)

log(f'Successfully deleted file "{filename}" in project "{project_id}"!')


@cli.command()
@click.argument("project_id")
@click.option(
Expand Down
19 changes: 19 additions & 0 deletions qfieldcloud_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,25 @@ def delete_files(

return glob_results

def delete_file(
self,
project_id: str,
filename: str,
version_id: Optional[str],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to suggest the version_id: str | None typing, but it seems that the project is python >= 3.8, so better keep it this way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, 3.9 is dead by the end of the year, then we upgade to a newer target Python version.

) -> requests.Response:
headers = {}

if version_id:
headers["x-file-version"] = version_id

resp = self._request(
"DELETE",
f"files/{project_id}/{filename}",
headers=headers,
)

return resp

def package_latest(self, project_id: str) -> Dict[str, Any]:
"""Check the latest packaging status of a project.
Expand Down