Skip to content

Commit 32ed26a

Browse files
committed
Adding CLI and SDK for push delta files
1 parent 8c7c1c0 commit 32ed26a

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

qfieldcloud_sdk/cli.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,27 @@ def job_status(ctx: Context, job_id):
459459
else:
460460
log(f'Job status for {job_id}: {status["status"]}')
461461

462+
@cli.command(short_help="Push a delta file to a project.")
463+
@click.argument("project_id")
464+
@click.argument("delta_filename", type=click.Path(exists=True))
465+
@click.pass_context
466+
def delta_push(ctx: Context, project_id: str, delta_filename: str) -> None:
467+
"""Push a delta file to a project with PROJECT_ID."""
468+
log(f'Pushing delta file "{delta_filename}" to project "{project_id}"…')
469+
470+
try:
471+
response = ctx.obj["client"].push_delta(project_id, delta_filename)
472+
473+
if ctx.obj["format_json"]:
474+
print_json(response)
475+
else:
476+
log(f'Delta file "{delta_filename}" pushed to project "{project_id}".')
477+
except Exception as e:
478+
log(f"Error pushing delta file: {e}")
479+
if ctx.obj["format_json"]:
480+
print_json({"error": str(e)})
481+
else:
482+
click.echo(f"Error: {e}", err=True)
462483

463484
@cli.command()
464485
@click.argument("project_id")

qfieldcloud_sdk/sdk.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,33 @@ def job_status(self, job_id: str) -> Dict[str, Any]:
617617

618618
return resp.json()
619619

620+
def push_delta(self, project_id: str, delta_filename: str) -> Dict[str, Any]:
621+
"""Push a delta file to a project.
622+
623+
Args:
624+
project_id: Project ID.
625+
delta_filename: Path to the delta JSON file.
626+
627+
Returns:
628+
A dictionary containing the response from the server.
629+
"""
630+
try:
631+
with open(delta_filename, 'r') as delta_file:
632+
files = {'file': delta_file}
633+
resp = self._request(
634+
"POST",
635+
f"deltas/{project_id}/",
636+
files=files,
637+
)
638+
print(f"Response status code: {resp.status_code}")
639+
640+
if resp.content:
641+
return resp.json()
642+
else:
643+
return {"message": "Delta pushed successfully"}
644+
except Exception as e:
645+
raise RuntimeError(f"Failed to push delta: {e}")
646+
620647
def delete_files(
621648
self,
622649
project_id: str,

0 commit comments

Comments
 (0)