Skip to content

Commit 16a6dfb

Browse files
authored
Merge pull request #77 from opengisch/fixing_documentation_and_other_improvements
Fixing documentation and adding some improvements
2 parents d8d418b + 77c060a commit 16a6dfb

File tree

2 files changed

+86
-68
lines changed

2 files changed

+86
-68
lines changed

docs/docs/examples.md

Lines changed: 67 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,27 @@ In this example, we'll use the `jq` tool to parse the JSON response and retrieve
5858
=== ":material-bash: Bash"
5959

6060
```bash
61-
qfieldcloud-cli --json login 'ninjamaster' 'secret_password123' | jq .session_token
61+
qfieldcloud-cli --json login 'ninjamaster' 'secret_password123' | jq '.token'
6262
```
6363

6464
=== ":material-powershell: PowerShell"
6565

6666
```powershell
67-
qfieldcloud-cli --json login "ninjamaster" "secret_password123" | jq ".session_token"
67+
(qfieldcloud-cli --json login "ninjamaster" "secret_password123" | ConvertFrom-Json).token
6868
```
6969

7070
This command will output only the session token, which can be stored in an environment variable for future use:
7171

7272
=== ":material-bash: Bash"
7373

7474
```bash
75-
export QFIELDCLOUD_TOKEN=$(qfieldcloud-cli --json login 'ninjamaster' 'secret_password123' | jq -r .session_token)
75+
export QFIELDCLOUD_TOKEN=$(qfieldcloud-cli --json login 'ninjamaster' 'secret_password123' | jq -r '.token')
7676
```
7777

7878
=== ":material-powershell: PowerShell"
7979

8080
```powershell
81-
$env:QFIELDCLOUD_TOKEN = (qfieldcloud-cli --json login "ninjamaster" "secret_password123" | jq ".session_token")
81+
$env:QFIELDCLOUD_TOKEN = (qfieldcloud-cli --json login "ninjamaster" "secret_password123" | ConvertFrom-Json).token
8282
```
8383

8484
### Create a project
@@ -181,6 +181,66 @@ To view all files in a specific project:
181181
qfieldcloud-cli list-files "123e4567-e89b-12d3-a456-426614174000"
182182
```
183183

184+
### Download Files for Backup
185+
186+
Download the project files for backup or just to check what is uploaded. To download all files or filter specific ones (e.g., `.jpg` files):
187+
188+
=== ":material-bash: Bash"
189+
190+
```bash
191+
qfieldcloud-cli download-files '123e4567-e89b-12d3-a456-426614174000' '/home/ninjamaster/backup_folder/DCIM/2024-11-10/' --filter '*.jpg'
192+
```
193+
194+
=== ":material-powershell: PowerShell"
195+
196+
```powershell
197+
qfieldcloud-cli download-files "123e4567-e89b-12d3-a456-426614174000" "C:\Users\ninjamaster\backup_folder\DCIM\2024-11-10\" --filter "*.jpg"
198+
```
199+
200+
If files already exist locally and you want to overwrite them, use the `--force-download` option:
201+
202+
=== ":material-bash: Bash"
203+
204+
```bash
205+
qfieldcloud-cli download-files '123e4567-e89b-12d3-a456-426614174000' '/home/ninjamaster/backup_folder/DCIM/2024-11-10/' --force-download
206+
```
207+
208+
=== ":material-powershell: PowerShell"
209+
210+
```powershell
211+
qfieldcloud-cli download-files "123e4567-e89b-12d3-a456-426614174000" "C:\Users\ninjamaster\backup_folder\DCIM\2024-11-10\" --force-download
212+
```
213+
214+
### Delete Files to Save Space
215+
216+
To free up storage on QFieldCloud, you can delete unnecessary files, such as `.jpg` files:
217+
218+
=== ":material-bash: Bash"
219+
220+
```bash
221+
qfieldcloud-cli delete-files '123e4567-e89b-12d3-a456-426614174000' --filter '*.jpg'
222+
```
223+
224+
=== ":material-powershell: PowerShell"
225+
226+
```powershell
227+
qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" --filter "*.jpg"
228+
```
229+
230+
You can also delete specific files by specifying their exact path:
231+
232+
=== ":material-bash: Bash"
233+
234+
```bash
235+
qfieldcloud-cli delete-files '123e4567-e89b-12d3-a456-426614174000' 'DCIM/tree-202411202334943.jpg'
236+
```
237+
238+
=== ":material-powershell: PowerShell"
239+
240+
```powershell
241+
qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" "DCIM\tree-202411202334943.jpg"
242+
```
243+
184244
### Manage Members and Collaborators
185245

186246
The collaborative nature of QFieldCloud naturally involves other people in the fieldwork.
@@ -375,10 +435,10 @@ Suppose your company packages the project every morning at 8:47 AM.:
375435

376436
This triggers the package job daily at the specified time. For more information about [schtasks](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/schtasks).
377437

438+
### Check Files Used by QField
378439

379-
### Download Files for Backup
380-
381-
Once the package job is complete, download the project files for backup. To download all files or filter specific ones (e.g., `.jpg` files):
440+
Once the package job is complete, you may want to check what files are used by QField.
441+
To download all files or filter specific ones (e.g., `.jpg` files):
382442

383443
=== ":material-bash: Bash"
384444

@@ -404,37 +464,6 @@ If files already exist locally and you want to overwrite them, use the `--force-
404464

405465
```powershell
406466
qfieldcloud-cli package-download "123e4567-e89b-12d3-a456-426614174000" "C:\Users\ninjamaster\backup_folder\DCIM\2024-11-10\" --force-download
407-
```
408-
409-
### Delete Files to Save Space
410-
411-
To free up storage on QFieldCloud, you can delete unnecessary files, such as `.jpg` files:
412-
413-
=== ":material-bash: Bash"
414-
415-
```bash
416-
qfieldcloud-cli delete-files '123e4567-e89b-12d3-a456-426614174000' --filter '*.jpg'
417-
```
418-
419-
=== ":material-powershell: PowerShell"
420-
421-
```powershell
422-
qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" --filter "*.jpg"
423-
```
424-
425-
You can also delete specific files by specifying their exact path:
426-
427-
=== ":material-bash: Bash"
428-
429-
```bash
430-
qfieldcloud-cli delete-files '123e4567-e89b-12d3-a456-426614174000' 'DCIM/tree-202411202334943.jpg'
431-
```
432-
433-
=== ":material-powershell: PowerShell"
434-
435-
```powershell
436-
qfieldcloud-cli delete-files "123e4567-e89b-12d3-a456-426614174000" "DCIM\tree-202411202334943.jpg"
437-
```
438467

439468
### Delete a Project
440469

qfieldcloud_sdk/cli.py

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def cli(
126126
127127
qfieldcloud-cli login user pass
128128
129-
qfieldcloud-cli -u user -p pass -U https://localhost/api/v1/ list-projects
129+
qfieldcloud-cli -u user -p pass -U https://app.qfield.cloud/api/v1/ list-projects
130130
"""
131131
ctx.ensure_object(dict)
132132
ctx.obj["client"] = sdk.Client(url, verify_ssl, token=token)
@@ -143,13 +143,12 @@ def cli(
143143
def login(ctx: Context, username, password) -> None:
144144
"""Login to QFieldCloud."""
145145

146-
log(f"Log in {username}…")
147-
148146
user_data = ctx.obj["client"].login(username, password)
149147

150148
if ctx.obj["format_json"]:
151149
print_json(user_data)
152150
else:
151+
log(f"Log in {username}…")
153152
log(f'Welcome to QFieldCloud, {user_data["username"]}.')
154153
log(
155154
"QFieldCloud has generated a secret token to identify you. "
@@ -167,13 +166,12 @@ def login(ctx: Context, username, password) -> None:
167166
def logout(ctx):
168167
"""Logout and expire the token."""
169168

170-
log("Log out…")
171-
172169
payload = ctx.obj["client"].logout()
173170

174171
if ctx.obj["format_json"]:
175172
print_json(payload)
176173
else:
174+
log("Log out…")
177175
log(payload["detail"])
178176

179177

@@ -211,8 +209,6 @@ def status(ctx: Context):
211209
def list_projects(ctx: Context, include_public: bool, **opts) -> None:
212210
"""List QFieldCloud projects."""
213211

214-
log("Listing projects…")
215-
216212
projects: List[Dict[str, Any]] = ctx.obj["client"].list_projects(
217213
include_public,
218214
sdk.Pagination(**opts),
@@ -221,6 +217,7 @@ def list_projects(ctx: Context, include_public: bool, **opts) -> None:
221217
if ctx.obj["format_json"]:
222218
print_json(projects)
223219
else:
220+
log("Listing projects…")
224221
if projects:
225222
log("Projects the current user has access to:")
226223
log(format_project_table(projects))
@@ -240,13 +237,12 @@ def list_projects(ctx: Context, include_public: bool, **opts) -> None:
240237
def list_files(ctx: Context, project_id, skip_metadata):
241238
"""List QFieldCloud project files."""
242239

243-
log(f'Getting file list for "{project_id}"…')
244-
245240
files = ctx.obj["client"].list_remote_files(project_id, skip_metadata)
246241

247242
if ctx.obj["format_json"]:
248243
print_json(files)
249244
else:
245+
log(f'Getting file list for "{project_id}"…')
250246
if files:
251247
log(f'Files for project "{project_id}":')
252248
for file in files:
@@ -270,15 +266,14 @@ def list_files(ctx: Context, project_id, skip_metadata):
270266
def create_project(ctx: Context, name, owner, description, is_public):
271267
"""Creates a new empty QFieldCloud project."""
272268

273-
log("Creating project {}…".format(f"{owner}/{name}" if owner else name))
274-
275269
project = ctx.obj["client"].create_project(
276270
name, owner, description=description, is_public=is_public
277271
)
278272

279273
if ctx.obj["format_json"]:
280274
print_json(project)
281275
else:
276+
log("Creating project {}…".format(f"{owner}/{name}" if owner else name))
282277
log("Created project:")
283278
log(format_project_table([project]))
284279

@@ -289,14 +284,13 @@ def create_project(ctx: Context, name, owner, description, is_public):
289284
def delete_project(ctx: Context, project_id):
290285
"""Deletes a QFieldCloud project."""
291286

292-
log(f'Deleting project "{project_id}"…')
293-
294287
payload = ctx.obj["client"].delete_project(project_id)
295288

296289
if ctx.obj["format_json"]:
297290
# print_json(payload)
298291
print(payload, payload.content)
299292
else:
293+
log(f'Deleting project "{project_id}"…')
300294
log(f'Deleted project "{project_id}".')
301295

302296

@@ -316,8 +310,6 @@ def delete_project(ctx: Context, project_id):
316310
def upload_files(ctx: Context, project_id, project_path, filter_glob, throw_on_error):
317311
"""Upload files to a QFieldCloud project."""
318312

319-
log(f'Uploading files "{project_id}" from {project_path}…')
320-
321313
files = ctx.obj["client"].upload_files(
322314
project_id,
323315
sdk.FileTransferType.PROJECT,
@@ -330,6 +322,7 @@ def upload_files(ctx: Context, project_id, project_path, filter_glob, throw_on_e
330322
if ctx.obj["format_json"]:
331323
print_json(files)
332324
else:
325+
log(f'Uploading files "{project_id}" from {project_path}…')
333326
if files:
334327
log(f"Upload finished after uploading {len(files)}.")
335328
for file in files:
@@ -361,8 +354,6 @@ def download_files(
361354
):
362355
"""Download QFieldCloud project files."""
363356

364-
log(f'Downloading project "{project_id}" files to {local_dir}…')
365-
366357
files = ctx.obj["client"].download_project(
367358
project_id,
368359
local_dir,
@@ -375,6 +366,7 @@ def download_files(
375366
if ctx.obj["format_json"]:
376367
print_json(files)
377368
else:
369+
log(f'Downloading project "{project_id}" files to {local_dir}…')
378370
if files:
379371
count = 0
380372
for file in files:
@@ -443,12 +435,12 @@ def patch_project(
443435
def delete_files(ctx: Context, project_id, paths, throw_on_error):
444436
"""Delete QFieldCloud project files."""
445437

446-
log(f'Deleting project "{project_id}" files…')
447-
448438
paths_result = ctx.obj["client"].delete_files(project_id, paths, throw_on_error)
449439

450440
if ctx.obj["format_json"]:
451441
print_json(paths_result)
442+
else:
443+
log(f'Deleting project "{project_id}" files…')
452444

453445

454446
@cli.command()
@@ -464,8 +456,6 @@ def delete_files(ctx: Context, project_id, paths, throw_on_error):
464456
def list_jobs(ctx: Context, project_id, job_type: Optional[sdk.JobTypes], **opts):
465457
"""List project jobs."""
466458

467-
log(f'Listing project "{project_id}" jobs…')
468-
469459
jobs: List[Dict] = ctx.obj["client"].list_jobs(
470460
project_id,
471461
job_type,
@@ -475,6 +465,7 @@ def list_jobs(ctx: Context, project_id, job_type: Optional[sdk.JobTypes], **opts
475465
if ctx.obj["format_json"]:
476466
print_json(jobs)
477467
else:
468+
log(f'Listing project "{project_id}" jobs…')
478469
for job in jobs:
479470
log(
480471
f'Job "{job["id"]}" of project "{project_id}" is of type "{job["type"]}" and has status "{job["status"]}".'
@@ -493,13 +484,12 @@ def list_jobs(ctx: Context, project_id, job_type: Optional[sdk.JobTypes], **opts
493484
def job_trigger(ctx: Context, project_id, job_type, force):
494485
"""Triggers a new job."""
495486

496-
log(f'Triggering "{job_type}" job for project "{project_id}"…')
497-
498487
status = ctx.obj["client"].job_trigger(project_id, job_type, force)
499488

500489
if ctx.obj["format_json"]:
501490
print_json(status)
502491
else:
492+
log(f'Triggering "{job_type}" job for project "{project_id}"…')
503493
log(
504494
f'Job of type "{job_type}" triggered for project "{project_id}": {status["id"]}'
505495
)
@@ -511,13 +501,12 @@ def job_trigger(ctx: Context, project_id, job_type, force):
511501
def job_status(ctx: Context, job_id):
512502
"""Get job status."""
513503

514-
log(f'Getting job "{job_id}" status…')
515-
516504
status = ctx.obj["client"].job_status(job_id)
517505

518506
if ctx.obj["format_json"]:
519507
print_json(status)
520508
else:
509+
log(f'Getting job "{job_id}" status…')
521510
log(f'Job status for {job_id}: {status["status"]}')
522511

523512

@@ -527,13 +516,13 @@ def job_status(ctx: Context, job_id):
527516
@click.pass_context
528517
def delta_push(ctx: Context, project_id: str, delta_filename: str) -> None:
529518
"""Push a delta file to a project with PROJECT_ID."""
530-
log(f'Pushing delta file "{delta_filename}" to project "{project_id}"…')
531519

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

534522
if ctx.obj["format_json"]:
535523
print_json(response)
536524
else:
525+
log(f'Pushing delta file "{delta_filename}" to project "{project_id}"…')
537526
log(f'Delta file "{delta_filename}" pushed to project "{project_id}".')
538527

539528

@@ -543,13 +532,12 @@ def delta_push(ctx: Context, project_id: str, delta_filename: str) -> None:
543532
def package_latest(ctx: Context, project_id):
544533
"""Check project packaging status."""
545534

546-
log(f'Getting the latest project "{project_id}" package info…')
547-
548535
status = ctx.obj["client"].package_latest(project_id)
549536

550537
if ctx.obj["format_json"]:
551538
print_json(status)
552539
else:
540+
log(f'Getting the latest project "{project_id}" package info…')
553541
log(f'Packaging status for {project_id}: {status["status"]}')
554542
if status["layers"] is None:
555543
if status["status"] == "failed":
@@ -590,8 +578,6 @@ def package_download(
590578
):
591579
"""Download packaged QFieldCloud project files."""
592580

593-
log(f'Downloading the latest project "{project_id}" package files to {local_dir}…')
594-
595581
files = ctx.obj["client"].package_download(
596582
project_id,
597583
local_dir,
@@ -604,6 +590,9 @@ def package_download(
604590
if ctx.obj["format_json"]:
605591
print_json(files)
606592
else:
593+
log(
594+
f'Downloading the latest project "{project_id}" package files to {local_dir}…'
595+
)
607596
if files:
608597
log(f"Download status of packaged files in project {project_id}:")
609598
for file in files:

0 commit comments

Comments
 (0)