Skip to content
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

Adding CLI and SDK for push delta files #65

Merged
merged 6 commits into from
Oct 2, 2024
Merged
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
16 changes: 16 additions & 0 deletions qfieldcloud_sdk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,22 @@ def job_status(ctx: Context, job_id):
log(f'Job status for {job_id}: {status["status"]}')


@cli.command(short_help="Push a delta file to a project.")
@click.argument("project_id")
@click.argument("delta_filename", type=click.Path(exists=True))
@click.pass_context
def delta_push(ctx: Context, project_id: str, delta_filename: str) -> None:
"""Push a delta file to a project with PROJECT_ID."""
log(f'Pushing delta file "{delta_filename}" to project "{project_id}"…')

response = ctx.obj["client"].push_delta(project_id, delta_filename)

if ctx.obj["format_json"]:
print_json(response)
else:
log(f'Delta file "{delta_filename}" pushed to project "{project_id}".')


@cli.command()
@click.argument("project_id")
@click.pass_context
Expand Down
34 changes: 34 additions & 0 deletions qfieldcloud_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ def is_empty(self) -> bool:
return self.limit is None and self.offset is None


class DeltaPushResponse(TypedDict):
"""Represents the structure of the response for pushing a delta file.

Attributes:
status: The status of the response.
message: A message providing additional information about the response.
details: Additional details about the delta push operation.
"""

status: str
message: Optional[str]
details: Optional[Dict[str, Any]]


class Client:
"""The core component of the QFieldCloud SDK, providing methods for interacting with the QFieldCloud platform.

Expand Down Expand Up @@ -617,6 +631,26 @@ def job_status(self, job_id: str) -> Dict[str, Any]:

return resp.json()

def push_delta(self, project_id: str, delta_filename: str) -> DeltaPushResponse:
"""Push a delta file to a project.

Args:
project_id: Project ID.
delta_filename: Path to the delta JSON file.

Returns:
A DeltaPushResponse containing the response from the server.
"""
with open(delta_filename, "r") as delta_file:
files = {"file": delta_file}
response = self._request(
"POST",
f"deltas/{project_id}/",
files=files,
)

return cast(DeltaPushResponse, response)

def delete_files(
self,
project_id: str,
Expand Down