Skip to content

Commit 72968ed

Browse files
authored
Merge pull request #30 from opengisch/windows
Add Windows compatibility
2 parents 5b5f4c7 + a857595 commit 72968ed

File tree

2 files changed

+58
-26
lines changed

2 files changed

+58
-26
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
package_dir={"": "src"},
3232
packages=setuptools.find_packages(where="src"),
3333
python_requires=">=3.6",
34-
scripts=["src/bin/qfieldcloud-cli"],
34+
entry_points={"console_scripts": ["qfieldcloud-cli = qfieldcloud_sdk.cli:cli"]},
3535
)

src/bin/qfieldcloud-cli renamed to src/qfieldcloud_sdk/cli.py

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import collections
44
import json
5-
from enum import Enum
5+
import platform
66
import sys
7+
from enum import Enum
78

89
import click
910

@@ -20,9 +21,11 @@ class OutputFormat(Enum):
2021
def print_json(data):
2122
print(json.dumps(data, sort_keys=True, indent=2))
2223

24+
2325
def log(*msgs):
2426
print(*msgs, file=sys.stderr)
2527

28+
2629
class OrderedGroup(click.Group):
2730
def __init__(self, name=None, commands=None, **attrs):
2831
super(OrderedGroup, self).__init__(name, commands, **attrs)
@@ -85,26 +88,26 @@ def cli(
8588
):
8689
"""The official QFieldCloud CLI tool. Allows interaction with the QFieldCloud server API.
8790
88-
Environment:
91+
Environment:
8992
90-
Environment variables can be used instead of passing some common global options.
93+
Environment variables can be used instead of passing some common global options.
9194
92-
QFIELDCLOUD_API - QFieldCloud API endpoint URL
95+
QFIELDCLOUD_API - QFieldCloud API endpoint URL
9396
94-
QFIELDCLOUD_USERNAME - QFieldCloud username or email. Requires `QFIELDCLOUD_PASSWORD` to be set.
97+
QFIELDCLOUD_USERNAME - QFieldCloud username or email. Requires `QFIELDCLOUD_PASSWORD` to be set.
9598
96-
QFIELDCLOUD_PASSWORD - Password. Requires `QFIELDCLOUD_USERNAME` to be set.
99+
QFIELDCLOUD_PASSWORD - Password. Requires `QFIELDCLOUD_USERNAME` to be set.
97100
98-
QFIELDCLOUD_TOKEN - Token that can be used instead of passing username and password. It can be obtained by running `qfieldcloud-cli login`.
101+
QFIELDCLOUD_TOKEN - Token that can be used instead of passing username and password. It can be obtained by running `qfieldcloud-cli login`.
99102
100-
QFIELDCLOUD_VERIFY_SSL - When set to `0` has the same effect as passing `--no-verify-ssl`.
103+
QFIELDCLOUD_VERIFY_SSL - When set to `0` has the same effect as passing `--no-verify-ssl`.
101104
102105
103-
Examples:
106+
Examples:
104107
105-
qfieldcloud-cli login user pass
108+
qfieldcloud-cli login user pass
106109
107-
qfieldcloud-cli -u user -p pass -U https://localhost/api/v1/ list-projects
110+
qfieldcloud-cli -u user -p pass -U https://localhost/api/v1/ list-projects
108111
"""
109112
ctx.ensure_object(dict)
110113
ctx.obj["client"] = sdk.Client(url, verify_ssl, token=token)
@@ -134,15 +137,18 @@ def login(ctx, username, password) -> None:
134137
"Put the token in your in the environment using the following code, "
135138
"so you do not need to write your username and password again:"
136139
)
137-
log(f'export QFIELDCLOUD_TOKEN="{user_data["token"]}"')
140+
if platform.system() == "Windows":
141+
log(f'set QFIELDCLOUD_TOKEN={user_data["token"]}')
142+
else:
143+
log(f'export QFIELDCLOUD_TOKEN="{user_data["token"]}"')
138144

139145

140146
@cli.command()
141147
@click.pass_context
142148
def logout(ctx):
143149
"""Logout and expire the token."""
144150

145-
log(f'Log out…')
151+
log("Log out…")
146152

147153
payload = ctx.obj["client"].logout()
148154

@@ -202,7 +208,11 @@ def list_files(ctx, project_id):
202208

203209
@cli.command()
204210
@click.argument("name")
205-
@click.option("--owner", "owner", help="Owner of the project. If omitted, the current user is the owner.")
211+
@click.option(
212+
"--owner",
213+
"owner",
214+
help="Owner of the project. If omitted, the current user is the owner.",
215+
)
206216
@click.option("--description", "description", help="Description of the project.")
207217
@click.option(
208218
"--is-public/--is-private", "is_public", help="Mark the project as public."
@@ -298,13 +308,20 @@ def upload_files(ctx, project_id, project_path, filter_glob, throw_on_error):
298308
help="Download file even if it already exists locally. Default: False",
299309
)
300310
@click.pass_context
301-
def download_files(ctx, project_id, local_dir, filter_glob, throw_on_error, force_download):
311+
def download_files(
312+
ctx, project_id, local_dir, filter_glob, throw_on_error, force_download
313+
):
302314
"""Download QFieldCloud project files."""
303315

304316
log(f'Downloading project "{project_id}" files to {local_dir}…')
305317

306318
files = ctx.obj["client"].download_project(
307-
project_id, local_dir, filter_glob, throw_on_error, show_progress=True, force_download=force_download,
319+
project_id,
320+
local_dir,
321+
filter_glob,
322+
throw_on_error,
323+
show_progress=True,
324+
force_download=force_download,
308325
)
309326

310327
if ctx.obj["format_json"]:
@@ -321,9 +338,7 @@ def download_files(ctx, project_id, local_dir, filter_glob, throw_on_error, forc
321338
log(f"Downloaded {count} file(s).")
322339
else:
323340
if filter_glob:
324-
log(
325-
f"No files to download for project {project_id} at {filter_glob}"
326-
)
341+
log(f"No files to download for project {project_id} at {filter_glob}")
327342
else:
328343
log(f"No files to download for project {project_id}")
329344

@@ -346,9 +361,15 @@ def delete_files(ctx, project_id, paths, throw_on_error):
346361
if ctx.obj["format_json"]:
347362
print_json(paths_result)
348363

364+
349365
@cli.command()
350366
@click.argument("project_id")
351-
@click.option("--type", "job_type", type=sdk.JobTypes, help="Job type. One of package, delta_apply or process_projectfile.")
367+
@click.option(
368+
"--type",
369+
"job_type",
370+
type=sdk.JobTypes,
371+
help="Job type. One of package, delta_apply or process_projectfile.",
372+
)
352373
@click.pass_context
353374
def list_jobs(ctx, project_id, job_type):
354375
"""List project jobs."""
@@ -361,7 +382,9 @@ def list_jobs(ctx, project_id, job_type):
361382
print_json(jobs)
362383
else:
363384
for job in jobs:
364-
log(f'Job "{job["id"]}" of project "{project_id}" is of type "{job["type"]}" and has status "{job["status"]}".')
385+
log(
386+
f'Job "{job["id"]}" of project "{project_id}" is of type "{job["type"]}" and has status "{job["status"]}".'
387+
)
365388

366389

367390
@cli.command()
@@ -383,7 +406,9 @@ def job_trigger(ctx, project_id, job_type, force):
383406
if ctx.obj["format_json"]:
384407
print_json(status)
385408
else:
386-
log(f'Job of type "{job_type}" triggered for project "{project_id}": {status["id"]}')
409+
log(
410+
f'Job of type "{job_type}" triggered for project "{project_id}": {status["id"]}'
411+
)
387412

388413

389414
@cli.command()
@@ -417,7 +442,7 @@ def package_latest(ctx, project_id):
417442
else:
418443
log(f'Packaging status for {project_id}: {status["status"]}')
419444
if status["layers"] is None:
420-
if status["status"] == 'failed':
445+
if status["status"] == "failed":
421446
log("Packaging have never been triggered on this project. Please run:")
422447
log(f"qfieldcloud-cli job-trigger {project_id} package")
423448
return
@@ -450,13 +475,20 @@ def package_latest(ctx, project_id):
450475
help="Download file even if it already exists locally. Default: False",
451476
)
452477
@click.pass_context
453-
def package_download(ctx, project_id, local_dir, filter_glob, throw_on_error, force_download):
478+
def package_download(
479+
ctx, project_id, local_dir, filter_glob, throw_on_error, force_download
480+
):
454481
"""Download packaged QFieldCloud project files."""
455482

456483
log(f'Downloading the latest project "{project_id}" package files to {local_dir}…')
457484

458485
files = ctx.obj["client"].package_download(
459-
project_id, local_dir, filter_glob, throw_on_error, show_progress=True, force_download=force_download,
486+
project_id,
487+
local_dir,
488+
filter_glob,
489+
throw_on_error,
490+
show_progress=True,
491+
force_download=force_download,
460492
)
461493

462494
if ctx.obj["format_json"]:

0 commit comments

Comments
 (0)