Skip to content

Commit 7c1aef3

Browse files
committed
Initial commit
0 parents  commit 7c1aef3

12 files changed

Lines changed: 669 additions & 0 deletions

File tree

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
ignore = E501, F401, W503
3+
max-line-length = 120
4+
max-complexity = 30
5+
exclude = **/.git/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Continuous integration
2+
on: push
3+
jobs:
4+
code_check:
5+
name: Code check
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout repo
9+
uses: actions/checkout@v2
10+
- name: Setup Python
11+
uses: actions/setup-python@v1
12+
with:
13+
python-version: 3.8
14+
- name: Install pipenv
15+
run: pip install pipenv
16+
- name: Check code formatting
17+
run: |
18+
pipenv install pre_commit
19+
pipenv run python -m pre_commit run --all-files
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI
2+
3+
on: push
4+
5+
jobs:
6+
build-n-publish:
7+
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
8+
runs-on: ubuntu-20.04
9+
steps:
10+
- uses: actions/checkout@master
11+
- name: Set up Python 3.9
12+
uses: actions/setup-python@v1
13+
with:
14+
python-version: 3.9
15+
- name: Set version number
16+
if: startsWith(github.ref, 'refs/tags')
17+
run: >-
18+
sed -i "s/= dev/= ${GITHUB_REF/refs\/tags\/v}/" setup.cfg
19+
- name: Install pypa/build
20+
run: >-
21+
python -m
22+
pip install
23+
build
24+
--user
25+
- name: Build a binary wheel and a source tarball
26+
run: >-
27+
python -m
28+
build
29+
--sdist
30+
--wheel
31+
--outdir dist/
32+
.
33+
- name: Publish distribution 📦 to PyPI
34+
if: startsWith(github.ref, 'refs/tags')
35+
uses: pypa/gh-action-pypi-publish@master
36+
with:
37+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
**/__pycache__
3+
**/qfieldcloud_sdk.egg-info

.pre-commit-config.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
repos:
2+
# Fix end of files
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v3.2.0
5+
hooks:
6+
- id: trailing-whitespace
7+
- id: end-of-file-fixer
8+
- id: mixed-line-ending
9+
args:
10+
- '--fix=lf'
11+
12+
# Remove unused imports/variables
13+
- repo: https://github.com/myint/autoflake
14+
rev: v1.4
15+
hooks:
16+
- id: autoflake
17+
args:
18+
- "--in-place"
19+
- "--remove-all-unused-imports"
20+
- "--remove-unused-variables"
21+
22+
# Sort imports
23+
- repo: https://github.com/pycqa/isort
24+
rev: "5.7.0"
25+
hooks:
26+
- id: isort
27+
args: ["--profile", "black"]
28+
29+
# Black formatting
30+
- repo: https://github.com/psf/black
31+
rev: 20.8b1
32+
hooks:
33+
- id: black
34+
35+
# Lint files
36+
- repo: https://gitlab.com/pycqa/flake8
37+
rev: "3.9.0"
38+
hooks:
39+
- id: flake8

LICENCE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2021 OPENGIS.ch
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# The official QFieldCloud SDK and CLI
2+
3+
`qfieldcloud-sdk` is the official client to connect to QFieldCloud API either as a python module, or directly from the command line.
4+
5+
## Install
6+
7+
`pip install qfieldcloud-sdk`
8+
9+
## Module usage
10+
11+
```
12+
import qfieldcloud_sdk
13+
import requests
14+
15+
client = qfieldcloud_sdk.Client(
16+
url="https://app.qfield.cloud/api/v1/",
17+
username="user1",
18+
password="pass1",
19+
)
20+
21+
try:
22+
projects = client.projects()
23+
except requests.HttpRequest:
24+
print("Oops!")
25+
```
26+
27+
## CLI usage
28+
29+
The official QFieldCloud CLI tool.
30+
31+
### Usage
32+
33+
```
34+
qfieldcloud-cli [OPTIONS] COMMAND [ARGS]...
35+
```
36+
37+
### Examples
38+
39+
```
40+
# logs in user "user" with password "pass"
41+
qfieldcloud-cli login user pass
42+
43+
# gets the projects of user "user" with password "pass" at "https://localhost/api/v1/"
44+
qfieldcloud-cli -u user -p pass -U https://localhost/api/v1/ list-projects
45+
46+
# gets the projects of user authenticated with token `QFIELDCLOUD_TOKEN` at "https://localhost/api/v1/" as JSON
47+
export QFIELDCLOUD_URL=https://localhost/api/v1/
48+
export QFIELDCLOUD_TOKEN=017478ee2464440cb8d3e98080df5e5a
49+
qfieldcloud-cli --json list-projects
50+
```
51+
52+
### Global options overview
53+
54+
```
55+
-U, --url TEXT URL to the QFieldCloud API endpoint. If not passed,
56+
gets the value from QFIELDCLOUD_URL environment
57+
variable. Default: https://app.qfield.cloud/api/v1/
58+
59+
-u, --username TEXT Username or email.
60+
-p, --password TEXT
61+
-t, --token TEXT Session token.
62+
--json / --human Output the result as newline formatted json.
63+
--help Show this message and exit.
64+
```
65+
66+
Environment variables can be used instead of passing some common global options.
67+
68+
- `QFIELDCLOUD_API` - QFieldCloud API endpoint URL
69+
- `QFIELDCLOUD_USERNAME` - QFieldCloud username or email. Need `QFIELDCLOUD_PASSWORD` to be set.
70+
- `QFIELDCLOUD_PASSWORD` - Password. Needs `QFIELDCLOUD_USERNAME` to be set.
71+
- `QFIELDCLOUD_TOKEN` - Token that can be used instead of passing username and password. It can be obtained by running `qfieldcloud-cli login`.
72+
73+
### Commands overview
74+
75+
```
76+
download-files Download QFieldCloud project files
77+
list-files List QFieldCloud project files
78+
list-projects List QFieldCloud projects
79+
login Login into QFieldCloud
80+
```
81+
82+
#### login
83+
84+
Login to QFieldCloud.
85+
86+
```
87+
qfieldcloud-cli login [OPTIONS] USERNAME PASSWORD
88+
```
89+
90+
#### list-projects
91+
92+
List QFieldCloud projects.
93+
94+
```
95+
qfieldcloud-cli list-projects [OPTIONS]
96+
97+
Options:
98+
--include-public / --no-public Includes the public project in the list.
99+
```
100+
101+
#### list-files
102+
103+
List QFieldCloud project files.
104+
105+
```
106+
qfieldcloud-cli list-files [OPTIONS] PROJECT_ID
107+
```
108+
109+
#### download-files
110+
111+
Download QFieldCloud project files.
112+
113+
```
114+
qfieldcloud-cli download-files [OPTIONS] PROJECT_ID LOCAL_DIR
115+
116+
Options:
117+
--subdir TEXT Do not download the whole project, but only
118+
the subdirectory passed.
119+
120+
--exit-on-error / --no-exit-on-error
121+
If any project file download fails stop
122+
downloading the rest.
123+
```
124+
125+
## Development
126+
127+
Contributions are more than welcome!
128+
129+
### Code style
130+
Code style done with [precommit](https://pre-commit.com/).
131+
132+
```
133+
pip install pre-commit
134+
# install pre-commit hook
135+
pre-commit install
136+
```
137+
138+
### Cloning the project
139+
140+
One time action to clone and setup:
141+
142+
```
143+
git clone https://github.com/opengisch/qfieldcloud-sdk-python
144+
cd qfieldcloud-sdk-python
145+
# install dev dependencies
146+
python3 -m pip install --upgrade build pre-commit
147+
pre-commit install
148+
```
149+
150+
To run CLI interface for development purposes execute:
151+
152+
```
153+
python src/bin/qfieldcloud-cli
154+
```
155+
156+
### Building the package
157+
158+
Run:
159+
160+
```
161+
python3 -m build
162+
```
163+
164+
Then install on your system:
165+
166+
```
167+
pip install dist/qfieldcloud_sdk-dev-py3-none-any.whl --force-reinstall
168+
```
169+
170+
Voila!

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build-system]
2+
requires = [
3+
"setuptools>=42"
4+
]
5+
build-backend = "setuptools.build_meta"

setup.cfg

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[metadata]
2+
name = qfieldcloud-sdk
3+
version = dev
4+
author = Ivan Ivanov
5+
author_email = ivan@opengis.ch
6+
description = The official QFieldCloud SDK and CLI.
7+
long_description = file: README.md
8+
long_description_content_type = text/markdown
9+
url = https://github.com/opengisch/qfieldcloud-sdk-python
10+
project_urls =
11+
Bug Tracker = https://github.com/opengisch/qfieldcloud-sdk-python/issues
12+
classifiers =
13+
Programming Language :: Python :: 3
14+
License :: OSI Approved :: MIT License
15+
Operating System :: OS Independent
16+
17+
[options]
18+
package_dir =
19+
= src
20+
packages = find:
21+
python_requires = >=3.6
22+
install_requires =
23+
click
24+
requests
25+
26+
scripts = src/bin/qfieldcloud-cli
27+
28+
[options.packages.find]
29+
where = src

0 commit comments

Comments
 (0)