diff --git a/docs/src/DEVELOPERS.md b/docs/src/DEVELOPERS.md index f6a0a2e..ce9a73b 100644 --- a/docs/src/DEVELOPERS.md +++ b/docs/src/DEVELOPERS.md @@ -3,12 +3,12 @@ ## Documentation ```` console -mdbook build docs +$ mdbook build docs ```` ## Unit tests -ensure you have a valid `~/.pg_service.conf` +Ensure you have a valid `qsa_test` section in `~/.pg_service.conf`: ```` conf [qsa_test] @@ -19,26 +19,28 @@ user=myusername password= ```` -run the tests with: +Run the tests with: ```` console -createdb qsa_test -cd qsa-api -pytest -sv tests +$ createdb qsa_test +$ cd qsa-api +$ pytest -sv tests ```` ## Integration tests ```` console -cd sandbox -docker-compose up -d -cd ../qsa-api -QSA_GEOTIFF="/landsat_4326.tif" QSA_GPKG="/data.gpkg" QSA_HOST=127.0.01 QSA_PORT=5000 pytest -sv tests +$ cd sandbox +$ docker-compose up -d +$ cd ../qsa-api +$ QSA_GEOTIFF="/landsat_4326.tif" QSA_GPKG="/data.gpkg" QSA_HOST=127.0.01 QSA_PORT=5000 pytest -sv tests ```` -Ensure your changes are correctly formatted with `pre-commit` (see [installation](https://pre-commit.com/#installation)) +## Quality tests + +Ensure your changes are correctly formatted with `pre-commit` (see [installation](https://pre-commit.com/#installation)): ```` console # activate in repository -pre-commit install +$ pre-commit install ```` diff --git a/docs/src/qsa-api/configuration.md b/docs/src/qsa-api/configuration.md index 5c56081..590055e 100644 --- a/docs/src/qsa-api/configuration.md +++ b/docs/src/qsa-api/configuration.md @@ -28,9 +28,9 @@ well as QGIS QML styles. The PostgreSQL support relies on a `service` defined in a [PostgreSQL connection service file](https://www.postgresql.org/docs/current/libpq-pgservice.html). -For example with `QSA_QGISSERVER_PROJECTS_PSQL_SERVICE=qsa_projects`: -Ensure you have a valid `~/.pg_service.conf` +For example with `QSA_QGISSERVER_PROJECTS_PSQL_SERVICE=qsa_projects`, a proper +`qsa_projects` section is needed in `~/.pg_service.conf`: ```` conf [qsa_projects] diff --git a/docs/src/qsa-api/endpoints/README.md b/docs/src/qsa-api/endpoints/README.md index 7db1192..ab90b19 100644 --- a/docs/src/qsa-api/endpoints/README.md +++ b/docs/src/qsa-api/endpoints/README.md @@ -13,7 +13,7 @@ When PostgreSQL support is enabled, a query string parameter `schema` may be used to specify the schema in which the QGIS project is stored in the database (`public` is used by default). -```` shell +```` console # call a specific endpoint using projects stored in PostgreSQL schema named `myschema` -curl "http://localhost/api/xxx/yyy?schema=myschema" +$ curl "http://localhost/api/xxx/yyy?schema=myschema" ```` diff --git a/docs/src/qsa-api/endpoints/processing.md b/docs/src/qsa-api/endpoints/processing.md index 41c7790..2552c96 100644 --- a/docs/src/qsa-api/endpoints/processing.md +++ b/docs/src/qsa-api/endpoints/processing.md @@ -10,7 +10,7 @@ rasters or get histogram for raster layers. Examples: -``` shell +``` console # create a new layer based on a QGIS expression $ curl "http://localhost/api/projects/" \ -X POST \ diff --git a/docs/src/qsa-api/endpoints/projects.md b/docs/src/qsa-api/endpoints/projects.md index 07ca6a6..5d36edc 100644 --- a/docs/src/qsa-api/endpoints/projects.md +++ b/docs/src/qsa-api/endpoints/projects.md @@ -18,9 +18,9 @@ A QSA project is defined by: Examples: -``` shell +``` console # create a project and store the QGIS project in PostgreSQL within `my_schema` -curl "http://localhost/api/projects/" \ +$ curl "http://localhost/api/projects/" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -30,7 +30,7 @@ curl "http://localhost/api/projects/" \ }' # get metadata about the project stored in PostgreSQL -curl "http://localhost/api/projects/my_project?schema=my_schema" +$ curl "http://localhost/api/projects/my_project?schema=my_schema" ``` ## Layer @@ -69,9 +69,9 @@ A layer can be added to a project thanks to the next parameters: Example: -```` shell +```` console # Add a FlatGeobuf vector layer stored on S3 bucket in project `my_project` -curl "http://localhost/api/projects/my_project/layers" \ +$ curl "http://localhost/api/projects/my_project/layers" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -108,9 +108,9 @@ For vector layers, a style can be defined with the parameters listed below: Example: -```` shell +```` console # Add a style for point geometry vector layers -curl "http://localhost:5000/api/projects/my_project/styles" \ +$ curl "http://localhost:5000/api/projects/my_project/styles" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -146,9 +146,9 @@ For raster layers, a style can be defined with the parameters listed below: Example: -```` shell +```` console # Add a style for multiband raster -curl "http://localhost:5000/api/projects/my_project/styles" \ +$ curl "http://localhost:5000/api/projects/my_project/styles" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -186,7 +186,7 @@ curl "http://localhost:5000/api/projects/my_project/styles" \ Example: -```` shell +```` console $ curl "http://localhost:5000/api/projects/my_project/cache" { "valid":true, diff --git a/docs/src/qsa-api/endpoints/symbology.md b/docs/src/qsa-api/endpoints/symbology.md index 4e8ee3c..2b9746e 100644 --- a/docs/src/qsa-api/endpoints/symbology.md +++ b/docs/src/qsa-api/endpoints/symbology.md @@ -23,14 +23,9 @@ version. Examples: -```` shell +```` console # Return single symbol properties for polygon layers -curl "http://localhost:5000/api/symbology/vector/polygon/single_symbol/fill/properties" | jq -```` - -returns - -```` json +$ curl "http://localhost:5000/api/symbology/vector/polygon/single_symbol/fill/properties" | jq { "border_width_map_unit_scale": "3x:0,0,0,0,0,0", "color": "0,0,255,255", @@ -48,12 +43,7 @@ returns ```` console # Return multi band gray properties for raster layers -curl "http://localhost:5000/api/symbology/raster/multibandcolor/properties" | jq -```` - -returns - -```` json +$ curl "http://localhost:5000/api/symbology/raster/multibandcolor/properties" | jq { "blue": { "band": 3, diff --git a/docs/src/qsa-api/installation.md b/docs/src/qsa-api/installation.md index 6137c7f..9a70209 100644 --- a/docs/src/qsa-api/installation.md +++ b/docs/src/qsa-api/installation.md @@ -2,21 +2,20 @@ ## From sources -```` shell -cd qsa-api -virtualenv --system-site-packages venv # system aware for pyqgis -. venv/bin/activate -# now in (venv) -pip install poetry -poetry install +```` console +$ cd qsa-api +$ virtualenv --system-site-packages venv # system aware for pyqgis +$ . venv/bin/activate +(venv)$ pip install poetry +(venv)$ poetry install ```` ## Docker image A prebuilt image can be found on `ghcr.io/pblottiere/qsa`: -```` shell -docker pull ghcr.io/pblottiere/qsa:1.1.0 +```` console +$ docker pull ghcr.io/pblottiere/qsa:1.1.0 ```` Otherwise the image can manually be built using: diff --git a/docs/src/qsa-cli/installation.md b/docs/src/qsa-cli/installation.md index 556cb37..93b65f6 100644 --- a/docs/src/qsa-cli/installation.md +++ b/docs/src/qsa-cli/installation.md @@ -3,12 +3,11 @@ From sources: ```` console -cd qsa-cli -virtualenv venv -. venv/bin/activate -# now in (venv) -pip install poetry -poetry install +$ cd qsa-cli +$ virtualenv venv +$ . venv/bin/activate +(venv)$ pip install poetry +(venv)$ poetry install ```` Binary distributions: diff --git a/docs/src/sandbox/README.md b/docs/src/sandbox/README.md index 1e5d7d3..3543931 100644 --- a/docs/src/sandbox/README.md +++ b/docs/src/sandbox/README.md @@ -5,9 +5,9 @@ QSA tools with PostgreSQL support enabled. First, a QSA REST API server is set up with 4 QGIS Server instances: -```` shell -cd sandbox -docker-compose up --scale qgisserver=4 -d +```` console +$ cd sandbox +$ docker-compose up --scale qgisserver=4 -d $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d2eaf6bdfae4 pblottiere/qsa "gunicorn -b 0.0.0.0…" 2 hours ago Up 10 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp sandbox-qsa-1 diff --git a/docs/src/sandbox/inspect.md b/docs/src/sandbox/inspect.md index 5561a07..279473e 100644 --- a/docs/src/sandbox/inspect.md +++ b/docs/src/sandbox/inspect.md @@ -7,7 +7,7 @@ To list these instances with `qsa-cli`: -```` shell +```` console $ QSA_SERVER_URL=http://localhost:5000 qsa ps INSTANCE ID IP STATUS ------------- ---------- ----------------------- @@ -19,13 +19,8 @@ c0047e66 172.20.0.6 Binded 1096 seconds ago Or with the API: -```` shell -curl http://localhost:5000/api/instances/ | jq -```` - -returns - -```` json +```` console +$ curl http://localhost:5000/api/instances/ | jq { "servers": [ { @@ -56,13 +51,8 @@ returns To get some metadata about a specific QGIS Server instance with `qsa-cli`: -```` shell -qsa inspect 4464d3c5 -```` - -returns - -```` json +```` console +$ qsa inspect 4464d3c5 { "cache": { "projects": [] @@ -112,26 +102,16 @@ Or with the API `curl http://localhost:5000/api/instances/4464d3c5`. A bad request to QGIS Server to have something in the log: -```` shell -curl http://172.20.0.4/ogc/ -```` - -returns - -````xml +```` console +$ curl http://172.20.0.4/ogc/ Project file error. For OWS services: please provide a SERVICE and a MAP parameter pointing to a valid QGIS project file ```` Then to fetch the log of the corresponding QGIS Server instance with `qsa-cli`: -```` shell -qsa logs 4464d3c5 -```` - -returns - -```` text +```` console +$ qsa logs 4464d3c5 Server plugin qsa loaded! Server python plugins loaded ******************** New request *************** @@ -163,13 +143,8 @@ Request finished in 3 ms To display stats for all QGIS Server online instances: -```` shell -qsa stats -```` - -returns - -````text +```` console +$ qsa stats INSTANCE ID COUNT TIME SERVICE REQUEST PROJECT ------------- ------- ---------- --------- --------- --------- 4464d3c5 1 diff --git a/docs/src/sandbox/projects.md b/docs/src/sandbox/projects.md index 1542ebf..67e0d08 100644 --- a/docs/src/sandbox/projects.md +++ b/docs/src/sandbox/projects.md @@ -4,15 +4,15 @@ First we create a schema to store QGIS projects: -```` shell +```` console $ psql -h localhost -p 5433 -U qsa qsa -c "create schema my_schema" CREATE SCHEMA ```` Then we create a QSA project: -```` shell -curl "http://localhost:5000/api/projects/" \ +```` console +$ curl "http://localhost:5000/api/projects/" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -25,14 +25,14 @@ curl "http://localhost:5000/api/projects/" \ In this case, a directory has been created on the filesystem with the internal QSA database: -```` shell +```` console $ file projects/qsa/my_schema_my_project/qsa.db SQLite 3.x database ```` And a QGIS project has been created in PostgreSQL: -```` shell +```` console $ psql -h localhost -p 5433 -U qsa qsa -c "select name from my_schema.qgis_projects" name ------------ @@ -43,7 +43,7 @@ $ psql -h localhost -p 5433 -U qsa qsa -c "select name from my_schema.qgis_proje To create another project in `public` schema and list available projects thanks to the QSA API: -```` shell +```` console $ curl "http://localhost:5000/api/projects/" \ -X POST \ -H 'Content-Type: application/json' \ @@ -60,7 +60,7 @@ $ curl "http://localhost:5000/api/projects/?schema=my_schema" To delete a project: -```` shell +```` console $ curl -X DELETE "http://localhost:5000/api/projects/my_project_2" true $ curl "http://localhost:5000/api/projects/" @@ -69,13 +69,8 @@ $ curl "http://localhost:5000/api/projects/" To list project metadata: -```` shell -curl http://localhost:5000/api/projects/my_project?schema=my_schema | jq -```` - -returns - -```` json +```` console +$ curl http://localhost:5000/api/projects/my_project?schema=my_schema | jq { "author": "pblottiere", "creation_datetime": "2024-03-14T20:17:45", diff --git a/docs/src/sandbox/raster/layers.md b/docs/src/sandbox/raster/layers.md index 8a5e330..4642fe6 100644 --- a/docs/src/sandbox/raster/layers.md +++ b/docs/src/sandbox/raster/layers.md @@ -6,8 +6,8 @@ Layer is based on the `landsat_4326.tif` file mounted in the Docker containers. To add a raster layer to a project: -```` shell -curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" \ +```` console +$ curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -19,22 +19,14 @@ curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" \ ## List layers and get metadata -list layers -```` shell +```` console +# list layers $ curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" ["polygons","dem"] -```` - -get metadata - -```` shell -curl "http://localhost:5000/api/projects/my_project/layers/dem?schema=my_schema" -```` - -returns -```` json +# get metadata +$ curl "http://localhost:5000/api/projects/my_project/layers/dem?schema=my_schema" { "bands": 1, "bbox": "18.6662979442000001 45.77670143760000343, 18.70359794419999844 45.81170143760000002", @@ -55,8 +47,8 @@ returns To execute a WMS `GetMap` request with basic parameters: -```` shell -curl "http://localhost:5000/api/projects/my_project/layers/dem/map?schema=my_schema" --output map.png +```` console +$ curl "http://localhost:5000/api/projects/my_project/layers/dem/map?schema=my_schema" --output map.png ```` diff --git a/docs/src/sandbox/raster/processing.md b/docs/src/sandbox/raster/processing.md index e6d6e4f..5880044 100644 --- a/docs/src/sandbox/raster/processing.md +++ b/docs/src/sandbox/raster/processing.md @@ -4,8 +4,8 @@ To get an histogram for a specific raster layer: -```` shell -curl "http://localhost:5000/api/processing/raster/histogram/my_project/dem?schema=my_schema" \ +```` console +$ curl "http://localhost:5000/api/processing/raster/histogram/my_project/dem?schema=my_schema" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ diff --git a/docs/src/sandbox/raster/styles.md b/docs/src/sandbox/raster/styles.md index ea5bf7b..f01810b 100644 --- a/docs/src/sandbox/raster/styles.md +++ b/docs/src/sandbox/raster/styles.md @@ -4,8 +4,8 @@ To add a style for a multiband raster layer: -```` shell -curl "http://localhost:5000/api/projects/my_project/styles?schema=my_schema" \ +```` console +$ curl "http://localhost:5000/api/projects/my_project/styles?schema=my_schema" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -33,7 +33,7 @@ curl "http://localhost:5000/api/projects/my_project/styles?schema=my_schema" \ To list styles for a specific project: -```` shell +```` console $ curl "http://localhost:5000/api/projects/my_project/styles?schema=my_schema" ["my_singlebandgray_style"] ```` @@ -42,8 +42,8 @@ $ curl "http://localhost:5000/api/projects/my_project/styles?schema=my_schema" To apply a specific style to a layer: -```` shell -curl "http://localhost:5000/api/projects/my_project/layers/dem/style?schema=my_schema" \ +```` console +$ curl "http://localhost:5000/api/projects/my_project/layers/dem/style?schema=my_schema" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -54,8 +54,8 @@ curl "http://localhost:5000/api/projects/my_project/layers/dem/style?schema=my_s The layer rendering has changed now: -```` shell -curl "http://localhost:5000/api/projects/my_project/layers/dem/map?schema=my_schema" --output map.png +```` console +$ curl "http://localhost:5000/api/projects/my_project/layers/dem/map?schema=my_schema" --output map.png ```` diff --git a/docs/src/sandbox/vector/layers.md b/docs/src/sandbox/vector/layers.md index 549659e..c8a6c2c 100644 --- a/docs/src/sandbox/vector/layers.md +++ b/docs/src/sandbox/vector/layers.md @@ -6,8 +6,8 @@ Layers are based on the `data.gpkg` file mounted in the Docker containers. To add a polygon layer from a geopackage to a project: -```` shell -curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" \ +```` console +$ curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -20,12 +20,12 @@ curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" \ And a line layer from PostGIS: -```` shell +```` console # copy geopackage table to PostGIS -ogr2ogr -f PostgreSQL "PG:dbname=qsa password=qsa user=qsa port=5433 host=localhost" data.gpkg lines +$ ogr2ogr -f PostgreSQL "PG:dbname=qsa password=qsa user=qsa port=5433 host=localhost" data.gpkg lines # add a line layer based on the PostGIS table -curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" \ +$ curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -38,18 +38,13 @@ curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" \ ## List layers and get metadata -```` shell +```` console $ curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" ["lines","polygons"] ```` -```` shell -curl "http://localhost:5000/api/projects/my_project/layers/lines?schema=my_schema" | jq -```` - -returns - -```` json +```` console +$ curl "http://localhost:5000/api/projects/my_project/layers/lines?schema=my_schema" | jq { "bbox": "-117.62319839219100004 23.20820580488510032, -82.32264950769270229 46.18290982947510059", "crs": "EPSG:4326", @@ -69,16 +64,16 @@ returns To execute a WMS `GetMap` request with basic parameters: -```` shell -curl "http://localhost:5000/api/projects/my_project/layers/polygons/map?schema=my_schema" --output map.png +```` console +$ curl "http://localhost:5000/api/projects/my_project/layers/polygons/map?schema=my_schema" --output map.png ```` ## Delete layers -```` shell -curl -X DELETE "http://localhost:5000/api/projects/my_project/layers/lines?schema=my_schema" +```` console +$ curl -X DELETE "http://localhost:5000/api/projects/my_project/layers/lines?schema=my_schema" $ curl "http://localhost:5000/api/projects/my_project/layers?schema=my_schema" ["polygons"] diff --git a/docs/src/sandbox/vector/styles.md b/docs/src/sandbox/vector/styles.md index 5bb9fd5..d317946 100644 --- a/docs/src/sandbox/vector/styles.md +++ b/docs/src/sandbox/vector/styles.md @@ -4,13 +4,8 @@ To list available properties for the polygon single symbol renderer: -```` shell -curl "http://localhost:5000/api/symbology/vector/polygon/single_symbol/fill/properties" | jq -```` - -returns - -````json +```` console +$ curl "http://localhost:5000/api/symbology/vector/polygon/single_symbol/fill/properties" | jq { "border_width_map_unit_scale": "3x:0,0,0,0,0,0", "color": "0,0,255,255", @@ -28,8 +23,8 @@ returns To add a style for a polygon layer: -```` shell -curl "http://localhost:5000/api/projects/my_project/styles?schema=my_schema" \ +```` console +$ curl "http://localhost:5000/api/projects/my_project/styles?schema=my_schema" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -51,7 +46,7 @@ curl "http://localhost:5000/api/projects/my_project/styles?schema=my_schema" \ To list styles for a specific project: -```` shell +```` console $ curl "http://localhost:5000/api/projects/my_project/styles?schema=my_schema" ["my_fill_style"] ```` @@ -60,8 +55,8 @@ $ curl "http://localhost:5000/api/projects/my_project/styles?schema=my_schema" To apply a specific style to a layer: -```` shell -curl "http://localhost:5000/api/projects/my_project/layers/polygons/style?schema=my_schema" \ +```` console +$ curl "http://localhost:5000/api/projects/my_project/layers/polygons/style?schema=my_schema" \ -X POST \ -H 'Content-Type: application/json' \ -d '{ @@ -72,8 +67,8 @@ curl "http://localhost:5000/api/projects/my_project/layers/polygons/style?schema The layer rendering has changed now: -```` shell -curl "http://localhost:5000/api/projects/my_project/layers/polygons/map?schema=my_schema" --output map.png +```` console +$ curl "http://localhost:5000/api/projects/my_project/layers/polygons/map?schema=my_schema" --output map.png ````