官方 QField云 SDK 和 CLI
qfieldcloud-sdk
是连接到 QField云API 的官方客户端,可以作为python模块,也可以直接从命令行连接。
笔记
qfieldcloud-sdk
要求 Python >=3.6
安装¶
pip install qfieldcloud-sdk
模块用法¶
import requests
from qfieldcloud_sdk import sdk
client = sdk.Client(
url="https://app.qfield.cloud/api/v1/",
username="user1",
password="pass1",
)
try:
projects = client.list_projects()
except requests.exceptions.RequestException:
print("Oops!")
CLI用法¶
官方QField云CLI工具。
用法¶
qfieldcloud-cli [OPTIONS] COMMAND [ARGS]...
示例¶
# logs in user "user" with password "pass"
qfieldcloud-cli login user pass
# gets the projects of user "user" with password "pass" at "https://localhost/api/v1/"
qfieldcloud-cli -u user -p pass -U https://localhost/api/v1/ list-projects
# gets the projects of user authenticated with token `QFIELDCLOUD_TOKEN` at "https://localhost/api/v1/" as JSON
export QFIELDCLOUD_URL=https://localhost/api/v1/
export QFIELDCLOUD_TOKEN=017478ee2464440cb8d3e98080df5e5a
qfieldcloud-cli --json list-projects
过滤¶
有些命令允许您使用 --filter
选项 (例如 download-files
命令) 根据文件名对结果定义过滤。
过滤支持 Unix shell-style 通配符。在 shell-style 通配符中使用的特殊字符包括:
样式 | 含义 |
---|---|
* | 匹配所有内容 |
? | 匹配任意单字符 |
[seq] | 匹配 seq 中的任意字符 |
[!seq] | 匹配 seq 之外的任意字符 |
对于文字匹配,请将 meta-characters 放在方括号中。例如, '[?]'
匹配字符 '?'
。
示例¶
qfieldcloud-cli --filter 'DCIM/*.jpg'
qfieldcloud-cli --filter 'attachments/documentation-??.pdf'
全局选项概述¶
-U, --url TEXT URL to the QFieldCloud API endpoint. If not
passed, gets the value from QFIELDCLOUD_URL
environment variable. Default:
https://app.qfield.cloud/api/v1/
-u, --username TEXT Username or email.
-p, --password TEXT
-t, --token TEXT Session token.
--json / --human Output the result as newline formatted json. Default: False
--verify-ssl / --no-verify-ssl Verify SSL. Default: True
--help Show this message and exit.
可以使用环境变量来代替传递一些常用的全局选项。
QFIELDCLOUD_API
- QField云 API 末端 URLQFIELDCLOUD_USERNAME
- QField云用户名或电子邮件。需要设置QFIELDCLOUD_PASSWORD
。QFIELDCLOUD_PASSWORD
- 密码。 需要设置QFIELDCLOUD_USERNAME
。QFIELDCLOUD_TOKEN
- 可以用来代替传递用户名和密码的令牌。可以通过运行qfieldcloud-cli login
获取。QFIELDCLOUD_VERIFY_SSL
- 当设置为0
时,与传递--no-verify-ssl
具有相同的效果。
命令概述¶
login Login to QFieldCloud.
logout Logout and expire the token.
list-projects List QFieldCloud projects.
list-files List QFieldCloud project files.
create-project Creates a new empty QFieldCloud project.
delete-project Deletes a QFieldCloud project.
upload-files Upload files to a QFieldCloud project.
download-files Download QFieldCloud project files.
delete-files Delete QFieldCloud project files.
list-jobs List project jobs.
job-trigger Triggers a new job.
job-status Get job status.
package-latest Check project packaging status.
package-download Download packaged QFieldCloud project files.
login - 登录¶
登录到QField云。
qfieldcloud-cli login [OPTIONS] USERNAME PASSWORD
logout - 注销¶
从QField云注销。
qfieldcloud-cli logout
list-projects¶
列出QField云工程。
qfieldcloud-cli list-projects [OPTIONS]
Options:
--include-public / --no-public Includes the public project in the list. Default: False
list-files¶
列出QField云工程文件。
qfieldcloud-cli list-files [OPTIONS] PROJECT_ID
create-project¶
创建新的空QField云工程。
qfieldcloud-cli create-project [OPTIONS] NAME
Options:
--owner TEXT Owner of the project. If omitted, the current
user is the owner.
--description TEXT Description of the project.
--is-public / --is-private Mark the project as public.
delete-project¶
删除QField云工程。
qfieldcloud-cli delete-project [OPTIONS] PROJECT_ID
upload-files¶
将文件上传到QField云工程。
qfieldcloud-cli upload-files [OPTIONS] PROJECT_ID PROJECT_PATH
Options:
--filter TEXT Do not upload the whole project, but only
the files which match the glob.
--throw-on-error / --no-throw-on-error
If any project file upload fails stop
uploading the rest. Default: False
download-files¶
下载QField云工程文件。
qfieldcloud-cli download-files [OPTIONS] PROJECT_ID LOCAL_DIR
Options:
--filter TEXT Do not download the whole project, but only
the files which match the glob.
--throw-on-error / --no-throw-on-error
If any project file downloads fails stop
downloading the rest. Default: False
--force-download/--no-force-download
 Download file even if it already exists locally.
Default: False
delete-files¶
删除QField云工程文件。
qfieldcloud-cli delete-files [OPTIONS] PROJECT_ID PATHS...
Options:
--throw-on-error / --no-throw-on-error
If any project file delete operations fails
stop, stop deleting the rest. Default: False
job-list¶
列出工程作业。
qfieldcloud-cli list-jobs [OPTIONS] PROJECT_ID
Options:
--type JOBTYPES Job type. One of package, delta_apply or
process_projectfile.
job-trigger¶
触发新作业。
qfieldcloud-cli job-trigger [OPTIONS] PROJECT_ID JOB_TYPE
Options:
--force / --no-force Should force creating a new job. Default: False
job-status¶
获取作业状态。
qfieldcloud-cli job-status [OPTIONS] JOB_ID
package-latest¶
检查工程打包状态。
qfieldcloud-cli package-latest [OPTIONS] PROJECT_ID
package-download¶
下载已打包的QField云工程文件。
qfieldcloud-cli package-download [OPTIONS] PROJECT_ID LOCAL_DIR
Options:
--filter TEXT Do not download the whole packaged project,
but only the files which match the glob.
--throw-on-error / --no-throw-on-error
If any packaged file downloads fails stop
downloading the rest. Default: False
--force-download/--no-force-download
 Download file even if it already exists locally.
Default: False