Skip to content

Commit 76a485b

Browse files
committed
template config files - config/* files can be auto generate now by running generate_configs.py with templates given in config/templates/*
1 parent 1227c2d commit 76a485b

File tree

5 files changed

+143
-78
lines changed

5 files changed

+143
-78
lines changed

config/instances/testing.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
url: 'http://localhost:5000/wps'
2+
allowedinputpaths:
3+
- './static/'
4+
- 'd:\Maps'
5+
- 'd:\MRR'
6+
default_mimetype: 'text/xml'
7+
#default_mimetype: 'application/json'
8+
#json_indent: -1
9+
json_indent: 2
10+
11+
#root: './static/data/maps'
12+
root: 'd:\Maps'
13+
14+
dtm_color_palette: './static/data/color_files/color_file_1.txt'
15+
16+
dtm_geo: './static/data/maps/srtm1_x35_y32.tif'
17+
#dtm_geo: '@xlink:href=file:./static/data/maps/srtm1_x35_y32.tif'
18+
19+
dtm_utm: 'd:\maps\srtm3\utm\*.tif'
20+
#dtm_utm: './static/data/maps/srtm1_w84u36.tif'
21+
22+
radio_refractivity: 333.0
23+
radio_conductivity: 3.0
24+
radio_permittivity: 33.0
25+
radio_humidity: 33.0

config/process_defaults.yaml

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
say_hello:
2+
name: "default-config"
3+
4+
ls:
5+
dir: '{{ root }}'
6+
pattern: '*.tif'
7+
8+
ras_val:
9+
r: '{{ dtm_geo }}'
10+
11+
crop_color:
12+
r: '{{ dtm_geo }}'
13+
of: 'czml'
14+
# color_palette: '{{ dtm_color_palette }}'
15+
16+
viewshed:
17+
r: '{{ dtm_utm }}'
18+
of: 'czml'
19+
in_crs: '0'
20+
out_crs: '0'
21+
backend: 'talos'
22+
23+
refractivity: {{ radio_refractivity }}
24+
conductivity: {{ radio_conductivity }}
25+
permittivity: {{ radio_permittivity }}
26+
humidity: {{ radio_humidity }}
27+
28+
fill_center: False
29+
profile_extension: True
30+
31+
tester:
32+
r: '{{ dtm_geo }}'
33+
name: 'Tester'
34+
35+
los:
36+
of: 'json'
37+
r: '{{ dtm_utm }}'
38+
in_crs: '0'
39+
out_crs: '0'
40+
backend: 'radio'
41+
42+
refractivity: {{ radio_refractivity }}
43+
conductivity: {{ radio_conductivity }}
44+
permittivity: {{ radio_permittivity }}
45+
humidity: {{ radio_humidity }}
46+
47+
fill_center: False
48+
profile_extension: True

config/pywps.cfg renamed to config/templates/pywps.cfg

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[metadata:main]
2-
identification_title=PyWPS Demo server
3-
identification_abstract=PyWPS testing and development server. Do NOT use this server in production environment. You shall setup PyWPS as WSGI application for production. Please refer documentation for further detials.
4-
identification_keywords=WPS,GRASS,PyWPS, Demo, Dev
2+
identification_title=TaLoS WPS server
3+
identification_abstract=TaLoS WPS server server.
4+
identification_keywords=WPS,GRASS,PyWPS,GDAL,Dev
55
identification_keywords_type=theme
66
identification_fees=None
77
identification_accessconstraints=None
8-
provider_name=PyWPS Developement team
9-
provider_url=http://pywps.org/
10-
contact_name=Your Name
8+
provider_name=TaLoS GIS Development team
9+
provider_url=https://github.com/talos-gis/pywps-flask
10+
contact_name=Idan Miara
1111
contact_position=Developer
1212
contact_address=My Street
1313
contact_city=My City
@@ -17,25 +17,25 @@ contact_country=World, Internet
1717
contact_phone=+00 00 11 22 33
1818
contact_fax=+00 99 88 77 66
1919
contact_email=info@yourdomain.org
20-
contact_url=http://pywps.org
20+
contact_url=https://github.com/talos-gis
2121
contact_hours=8:00-20:00UTC
2222
contact_instructions=Knock on the door
2323
contact_role=pointOfContact
2424

2525
[server]
2626
maxsingleinputsize=1mb
2727
maxrequestsize=3mb
28-
url=http://localhost:5000/wps
28+
url={{ url }}
2929
outputurl=outputs
3030
outputpath=outputs
3131
workdir=workdir
3232
wd_inp_subdir=inputs
3333
wd_out_subdir=outputs
3434
maxprocesses=10
3535
parallelprocesses=-1
36-
allowedinputpaths=./static/;D:\Maps;m:\maps;d:\MRR
37-
;default_mimetype=application/json
38-
;json_indent=-1
36+
allowedinputpaths={% for path in allowedinputpaths %}{{path}};{% endfor %}
37+
default_mimetype={{ default_mimetype }}
38+
json_indent={{ json_indent }}
3939

4040
[processing]
4141
mode=docker

generate_configs.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import sys
2+
3+
import jinja2
4+
import os
5+
from pathlib import Path
6+
import yaml
7+
8+
9+
def generate_configs(parameter_file, output_directory, template_root):
10+
output_directory = Path(output_directory)
11+
template_root = Path(template_root)
12+
parameter_file = Path(parameter_file)
13+
template_files = list(p.relative_to(template_root) for p in template_root.rglob('*.*'))
14+
15+
if os.path.exists(parameter_file):
16+
try:
17+
stream = open(parameter_file, 'r')
18+
parameter_dict = yaml.safe_load(stream)
19+
except Exception as err:
20+
raise Exception(f'Cannot process parameter file {parameter_file}')
21+
else:
22+
raise Exception(f'Parameter file {parameter_file} not found!')
23+
24+
if not os.path.exists(output_directory):
25+
os.mkdir(output_directory)
26+
27+
env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath=template_root))
28+
outputs = []
29+
for template_file in template_files:
30+
template = env.get_template(str(template_file))
31+
result = template.render(parameter_dict)
32+
output_file = output_directory / template_file
33+
outputs.append(output_file)
34+
f = open(output_file, "w")
35+
f.write(result)
36+
f.close()
37+
print(f'configs created: {outputs}')
38+
39+
40+
if __name__ == '__main__':
41+
root = Path(os.path.abspath(__file__)).parent
42+
if len(sys.argv) > 1:
43+
_parameter_file = sys.argv[1]
44+
else:
45+
_parameter_file = root / 'config/instances/testing.yaml'
46+
47+
if len(sys.argv) > 2:
48+
_output_directory = sys.argv[2]
49+
else:
50+
_output_directory = root / 'config'
51+
52+
if len(sys.argv) > 3:
53+
_template_root = sys.argv[3]
54+
else:
55+
_template_root = root / 'config/templates'
56+
57+
generate_configs(parameter_file=_parameter_file,
58+
output_directory=_output_directory,
59+
template_root=_template_root)

0 commit comments

Comments
 (0)