Skip to content

Commit

Permalink
add usage of gsconfig lib
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmi151 committed Jun 20, 2024
1 parent b344872 commit 0a9a2ed
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

This repository contains many tips/scripts/librairies in order to simplify administration/automation of geOrchestra plateform.

If you have any ideas to develop/which you could create a new issue here : https://github.com/georchestra/geo-utils/issues


23 changes: 23 additions & 0 deletions gs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# Geoserver STUFF

## scripting
Using this librairie : https://pypi.org/project/gsconfig/

But there is only few functionality

```commandline
# create datastore from csv
python3 create_datastore_from_csv.py
# publish layer from existing datastore and existing data in database
python3 create_layers_from_csv.py
```

## usefull commands


To change all urls store in the datadir :

`sed -e "s#mel.integration.apps.gs-fr-prod.camptocamp.com#data.lillemetropole.fr#g" -i $(grep mel.integration.apps * -r -l)`
40 changes: 40 additions & 0 deletions gs/create_datastore_from_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from geoserver.catalog import Catalog
import csv

cat = Catalog("https://georchestra-127-0-1-1.traefik.me/geoserver/rest", "admin", "password")


with open('list_datastore.csv', newline='') as csvfile:

spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')

for row in spamreader:
schema = row[0]

print(schema)
print(', '.join(row))


url = "https://georchestra-127-0-1-1.traefik.me/geoserver/" + schema +"/"
print(url)
try:
cat.create_workspace(name=schema, uri=url)
except:
print("Probably already exist")
pass

try:
ds = cat.create_datastore(name=name_suffix, workspace=schema)
ds.connection_parameters.update(
host="localhost",
port="5432",
database="gis",
user="postgres",
password="",
dbtype="postgis", schema=schema)
cat.save(ds)


except:
print("Error creating the datastore")
pass
27 changes: 27 additions & 0 deletions gs/create_layers_from_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from geoserver.catalog import Catalog
import csv

cat = Catalog("https://georchestra-127-0-1-1.traefik.me/geoserver/rest", "admin", "admin")


with open('list_layers.csv', newline='') as csvfile:

spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')

for row in spamreader:
# url,schema,table_name,gs_store
url = row[0]
schema = row[1]
table_name = row[2]
gs_store = row[3]

print(url, schema, table_name, gs_store)
try:
workspace = cat.get_workspace(name=schema)
# print(workspace)
datastore = cat.get_store(name=gs_store, workspace=workspace)
# print(datastore)
cat.publish_featuretype(name=table_name, store=datastore, native_crs='EPSG:4326', srs='EPSG:4326')
except:
print("already exist or not exist in DB")
pass
4 changes: 4 additions & 0 deletions gs/list_datastore.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Schemas ,owner schema, admin_db,descriptions
test,test,admin,
test2,test,admin,
test3,test,admin,
2 changes: 2 additions & 0 deletions gs/list_layers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
url,test,test,test
url2,test,test2,test

0 comments on commit 0a9a2ed

Please sign in to comment.