Skip to content

Commit

Permalink
Squelette du Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pdrillin committed Sep 28, 2020
1 parent 262d445 commit 3bc8a5f
Show file tree
Hide file tree
Showing 36 changed files with 527 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PLUGIN_NAME="pg_metadata"
SCHEMA="pgmetadata"
NETWORK="qgis_plugin_network"
27 changes: 27 additions & 0 deletions .docker/docker-compose-base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '2'

networks:
qgis_plugin_network:

services:
db:
image: kartoza/postgis:10.0-2.4 # Despite the tag, it's a 10.6 version
hostname: db
container_name: postgis
networks:
qgis_plugin_network:
environment:
- POSTGRES_USER=docker
- POSTGRES_PASS=docker
- POSTGRES_DBNAME=gis
# Uncomment to expose the postgis database on the network
# - ALLOW_IP_RANGE= 0.0.0.0/0
volumes:
- ../${PLUGIN_NAME}:/tests_directory/${PLUGIN_NAME}
# Uncomment to use the postgis database from outside the docker network
# ports:
# - "35432:5432"
# Only supported in version 3
# But we need version 2 for extends
#healthcheck:
# test: "exit 0"
22 changes: 22 additions & 0 deletions .docker/docker-compose-qgis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '2'

networks:
qgis_plugin_network:

services:
db:
extends:
file: docker-compose-base.yml
service: db

qgis:
image: qgis/qgis:release-3_4
container_name: qgis
networks:
qgis_plugin_network:
volumes:
# - /tmp/.X11-unix:/tmp/.X11-unix
- ../${PLUGIN_NAME}:/tests_directory/${PLUGIN_NAME}
environment:
# - DISPLAY=unix$DISPLAY
- DISPLAY=:99
5 changes: 5 additions & 0 deletions .docker/exec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
export $(grep -v '^#' .env | xargs)

docker exec -it qgis sh \
-c "cd /tests_directory/${PLUGIN_NAME} && qgis_testrunner.sh qgis_plugin_tools.infrastructure.test_runner.test_package"
12 changes: 12 additions & 0 deletions .docker/install_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
export $(grep -v '^#' .env | xargs)

docker cp pg_service.conf postgis:/etc/postgresql-common/

echo 'Installation from latest version'
docker exec postgis bash -c "psql service=test -c 'DROP SCHEMA IF EXISTS ${SCHEMA} CASCADE;'" > /dev/null
docker exec postgis bash -c "psql service=test -f /tests_directory/${PLUGIN_NAME}/install/sql/00_initialize_database.sql" > /dev/null
for sql_file in `ls -v ../${PLUGIN_NAME}/install/sql/${SCHEMA}/*.sql`; do
echo "${sql_file}"
docker exec postgis bash -c "psql service=test -f /tests_directory/${PLUGIN_NAME}/${sql_file}" > /dev/null;
done;
34 changes: 34 additions & 0 deletions .docker/install_migrate_generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
export $(grep -v '^#' .env | xargs)

if [ -n "$(git status --porcelain -uno)" ];
then
echo "Git working directory is not clean. Aborting."
exit 1
fi

echo "Installing the service file"
docker cp pg_service.conf postgis:/etc/postgresql-common/

echo "Installation from version ${INSTALL_VERSION}"
docker exec postgis bash -c "psql service=test -c 'DROP SCHEMA IF EXISTS ${SCHEMA} CASCADE;'" > /dev/null
docker exec postgis bash -c "psql service=test -f /tests_directory/${PLUGIN_NAME}/test/data/install/sql/00_initialize_database.sql" > /dev/null
for sql_file in `ls -v ../${PLUGIN_NAME}/test/data/install/sql/${SCHEMA}/*.sql`; do
echo "${sql_file}"
docker exec postgis bash -c "psql service=test -f /tests_directory/${PLUGIN_NAME}/${sql_file}" > /dev/null;
done;

echo 'Run migrations'
for migration in `ls -v ../${PLUGIN_NAME}/install/sql/upgrade/*.sql`; do
echo "${migration}"
docker exec postgis bash -c "psql service=test -f /tests_directory/${PLUGIN_NAME}/${migration}" > /dev/null;
done;

echo 'Generate doc'
docker exec postgis bash -c "apt-get install -y rename" > /dev/null
docker exec postgis bash -c "cd /tests_directory/${PLUGIN_NAME}/install/sql/ && ./export_database_structure_to_SQL.sh test ${SCHEMA}"
docker exec postgis bash -c "cd /tests_directory/${PLUGIN_NAME}/install/sql/${SCHEMA} && chmod 777 *.sql"

git diff
[[ -z $(git status --porcelain -uno) ]]
exit $?
6 changes: 6 additions & 0 deletions .docker/pg_service.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[test]
host=db
port=5432
user=docker
password=docker
dbname=gis
18 changes: 18 additions & 0 deletions .docker/postgis_connexions.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[PostgreSQL]
connections\selected=test
connections\test\allowGeometrylessTables=false
connections\test\authcfg=
connections\test\database=gis
connections\test\dontResolveType=false
connections\test\estimatedMetadata=false
connections\test\geometryColumnsOnly=false
connections\test\host=db
connections\test\password=docker
connections\test\port=5432
connections\test\projectsInDatabase=false
connections\test\publicOnly=false
connections\test\savePassword=true
connections\test\saveUsername=true
connections\test\service=
connections\test\sslmode=SslDisable
connections\test\username=docker
21 changes: 21 additions & 0 deletions .docker/processing_doc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
export $(grep -v '^#' .env | xargs)

#xhost +

docker run -d \
--name qgis-testing-environment \
-v $(pwd)/../${PLUGIN_NAME}:/tests_directory/${PLUGIN_NAME} \
-v $(pwd)/../docs/processing:/processing \
-e DISPLAY=:99 \
qgis/qgis:release-3_10

sleep 10

echo "Setting up"
docker exec -it qgis-testing-environment sh -c "qgis_setup.sh ${PLUGIN_NAME}"
docker exec -it qgis-testing-environment sh \
-c "qgis_testrunner.sh ${PLUGIN_NAME}.qgis_plugin_tools.infrastructure.doc_processing.generate_processing_doc"

docker kill qgis-testing-environment
docker rm qgis-testing-environment
15 changes: 15 additions & 0 deletions .docker/reformat_sql_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
export $(grep -v '^#' .env | xargs)

if [ -n "$(git status --porcelain -uno)" ];
then
echo "Git working directory is not clean. Aborting."
exit 1
fi

docker exec postgis bash -c "apt-get install -y rename" > /dev/null

echo 'Generating SQL files'
docker exec postgis bash -c "cd /tests_directory/${PLUGIN_NAME}/install/sql/ && ./export_database_structure_to_SQL.sh test ${SCHEMA}"

docker exec postgis bash -c "cd /tests_directory/${PLUGIN_NAME}/install/sql/${SCHEMA} && chmod 777 *.sql"
16 changes: 16 additions & 0 deletions .docker/schemaspy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
export $(grep -v '^#' .env | xargs)

chmod 777 -R "${PWD}"/../docs/database
docker run \
-v "${PWD}/../docs/database:/output" \
--network=docker_${NETWORK} \
etrimaille/schemaspy-pg:latest \
-t pgsql-mat \
-dp /drivers \
-host db \
-db gis \
-u docker \
-p docker \
-port 5432 \
-s ${SCHEMA}
22 changes: 22 additions & 0 deletions .docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
export $(grep -v '^#' .env | xargs)

WITH_QGIS=${1:-noqgis}

if [ "$WITH_QGIS" = with-qgis ]; then
FILE="docker-compose-qgis.yml"
else
FILE="docker-compose-base.yml"
fi

docker-compose -f ${FILE} up -d --force-recreate --remove-orphans
echo "Wait 10 seconds"
sleep 10
if [ "$WITH_QGIS" = with-qgis ]; then
echo "Installation of the plugin ${PLUGIN_NAME}"
docker exec -it qgis sh -c "qgis_setup.sh ${PLUGIN_NAME}"
echo "Setup the database link from QGIS"
docker cp postgis_connexions.ini qgis:/tmp
docker exec qgis bash -c "cat /tmp/postgis_connexions.ini >> /root/.local/share/QGIS/QGIS3/profiles/default/QGIS/QGIS3.ini"
fi
echo "Containers are running"
5 changes: 5 additions & 0 deletions .docker/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

echo 'Stopping/killing containers'
docker-compose -f docker-compose-qgis.yml kill
docker-compose -f docker-compose-qgis.yml rm -f
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__pycache__/
*.pyc
.DS_Store
.idea/
pg_metadata.*.zip
plugins.xml
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "pg_metadata/qgis_plugin_tools"]
path = pg_metadata/qgis_plugin_tools
url = https://github.com/3liz/qgis_plugin_tools.git
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## CHANGELOG

### 0.1.0 - 25/09/2020
* Squellete plugin
48 changes: 48 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
start_tests:
@echo 'Start docker-compose'
@cd .docker && ./start.sh with-qgis

run_tests:
@echo 'Running tests, containers must be running'
@cd .docker && ./exec.sh

stop_tests:
@echo 'Stopping/killing containers'
@cd .docker && ./stop.sh

tests: start_tests run_tests stop_tests flake8

test_migration:
@echo 'Testing migrations'
@cd .docker && ./start.sh
@cd .docker && ./install_migrate_generate.sh
@cd .docker && ./stop.sh

schemaspy:
@echo 'Generating schemaspy documentation'
@cd .docker && ./start.sh
rm -rf docs/
mkdir docs/
@cd .docker && ./install_db.sh
@cd .docker && ./schemaspy.sh
@cd .docker && ./stop.sh

reformat_sql:
@echo 'Reformat SQL'
@cd .docker && ./start.sh
@cd .docker && ./install_db.sh
@cd .docker && ./reformat_sql_install.sh
@cd .docker && ./stop.sh

flake8:
@echo 'Running flake8'
@docker run --rm -w /plugin -v $(shell pwd):/plugin etrimaille/flake8:3.8.2

github-pages:
@docker run --rm -w /plugin -v $(shell pwd):/plugin 3liz/pymarkdown:latest docs/README.md docs/index.html
@docker run --rm -w /plugin -v $(shell pwd):/plugin 3liz/pymarkdown:latest docs/processing/README.md docs/processing/index.html
@docker run --rm -w /plugin -v $(shell pwd):/plugin 3liz/pymarkdown:latest docs/user_guide/README.md docs/user_guide/index.html

processing-doc:
cd .docker && ./processing_doc.sh
@docker run --rm -w /plugin -v $(shell pwd):/plugin 3liz/pymarkdown:latest docs/processing/README.md docs/processing/index.html
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
## Gestion des metadata via PostgreSQL

8 changes: 8 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
Title: Plugin metadata
Favicon: icon.png
...

* [User guide](./user_guide/)
* [Algorithms descriptions](./processing/)
* [Database](./database/)
Binary file added docs/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<title>Plugin metadata</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/styles/github.min.css" rel="stylesheet"/>
<link href="https://docs.3liz.org/remarkable.css" rel="stylesheet"/>
<link href="icon.png" rel="icon" type="image/png" >
</head>
<body>
<header class="header-container" style="">
<h1>Plugin metadata</h1>
</header>
<article>
<p><a href="../">Up</a></p>
<ul>
<li><a href="./user_guide/">User guide</a></li>
<li><a href="./processing/">Algorithms descriptions</a></li>
<li><a href="./database/">Database</a></li>
</ul>
</article>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/highlight.min.js">
</script>
<script>
hljs.initHighlightingOnLoad();
</script>
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript">
</script>
<script type="text/javascript">
MathJax.Hub.Config({"showProcessingMessages" : false,"messageStyle" : "none","tex2jax": { inlineMath: [ [ "$", "$" ] ] }});
</script>
</body>
</html>
8 changes: 8 additions & 0 deletions docs/processing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
Title: Plugin metadata
Favicon: ../icon.png
...

[TOC]

# Plugin metadata
34 changes: 34 additions & 0 deletions docs/processing/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<title>Plugin metadata</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/styles/github.min.css" rel="stylesheet"/>
<link href="https://docs.3liz.org/remarkable.css" rel="stylesheet"/>
<link href="../icon.png" rel="icon" type="image/png" >
</head>
<body>
<header class="header-container" style="">
<h1>Plugin metadata</h1>
</header>
<article>
<p><a href="../">Up</a></p>
<div class="toc"><span class="toctitle">Table of content</span><ul>
<li><a href="#plugin-metadata">Plugin metadata</a></li>
</ul>
</div>
<h1 id="plugin-metadata">Plugin metadata</h1>
</article>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.1/highlight.min.js">
</script>
<script>
hljs.initHighlightingOnLoad();
</script>
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript">
</script>
<script type="text/javascript">
MathJax.Hub.Config({"showProcessingMessages" : false,"messageStyle" : "none","tex2jax": { inlineMath: [ [ "$", "$" ] ] }});
</script>
</body>
</html>
9 changes: 9 additions & 0 deletions docs/user_guide/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
Title: Plugin metadata
Favicon: ../icon.png
...

[TOC]


# Guide d'utilisateur pour le plugin metadata
Loading

0 comments on commit 3bc8a5f

Please sign in to comment.