Commit e1c90b1e authored by Andreas Walter's avatar Andreas Walter 🤙
Browse files

SDI-1142 Merge tag '0.0.2' into develop

SDI-1142 Create tag 0.0.2
parents e05303b6 f4dd44e5
......@@ -43,11 +43,47 @@ Out[04]: [{'@uuid':'9b3424d8-e1fb-4943-87d2-078b24464377','id':123456,'name':'ex
### Use the arguments described in the swagger UI in the method call
```bash
$ ipython3
# Python 3.6.+
In[01]: from ServCat import ServCat
In[02]: sc = ServCat(host='https://marine-data.de/servcat/rest/')
# Get a more detailed response
In[05]: sc.get_services(limit=1, view='detail')
Out[05]: [{'@uuid':'4d57fb41-9874-4ed2-94cb-05d9256a3900','id':654321,'name':'WMS','type':'WMS','version':'1.3.0','software':'GeoServer','title':'Some Nice Service Title','license':'CC-BY 4.0','abstract':'WMS','date_time_start':'0000-12-30T00:00:00','date_time_end':'9999-12-31T23:59:59.999','available_crs':['EPSG:3857','EPSG:4326'],'url':'https://wms-host.de/services/example/wms','filter_type':'OGC','minX':-5.0,'maxX':12.0,'minY':50.0,'maxY':61.989474,'keywords':[]'capabilities':'<full GetCapabilites document>','provider':{'@uuid':'55fe5448-79f1-41ed-80d7-98cd9edbf11f','id':1,'name':'Example Provider Name','acronym':'EPN','institute':'Example Institute'},'layers':[{'@uuid':'694041e6-8d33-4cc4-a94b-8f1a693a6d84','id':123456,'name':'example_layer_one','title':'Example Layer One','abstract':'This is the abstract about this beautiful WMS layer.','parent_name':'','available_crs':['EPSG:3857','EPSG:4326'],'source_urls':[],'metadata_urls':[],'legend_url':'https://wms-host.de/services/example/wms?request=GetLegendGraphic&version=1.3.0&format=image/png&layer=example_layer_one','axis_names':[],'available_styles':['default'],'output_formats':[],'data_type':'','processing_level':'','attribute_fields':[],'minX':-5.0,'maxX':12.0,'minY':50.0,'maxY':61.989474,'date_time_start':'0000-12-30T00:00:00','date_time_end':'9999-12-31T23:59:59.999'}]}]
In[03]: sc.get_services(limit=1, view='detail')
Out[03]: [{'@uuid':'4d57fb41-9874-4ed2-94cb-05d9256a3900','id':654321,'name':'WMS','type':'WMS','version':'1.3.0','software':'GeoServer','title':'Some Nice Service Title','license':'CC-BY 4.0','abstract':'WMS','date_time_start':'0000-12-30T00:00:00','date_time_end':'9999-12-31T23:59:59.999','available_crs':['EPSG:3857','EPSG:4326'],'url':'https://wms-host.de/services/example/wms','filter_type':'OGC','minX':-5.0,'maxX':12.0,'minY':50.0,'maxY':61.989474,'keywords':[]'capabilities':'<full GetCapabilites document>','provider':{'@uuid':'55fe5448-79f1-41ed-80d7-98cd9edbf11f','id':1,'name':'Example Provider Name','acronym':'EPN','institute':'Example Institute'},'layers':[{'@uuid':'694041e6-8d33-4cc4-a94b-8f1a693a6d84','id':123456,'name':'example_layer_one','title':'Example Layer One','abstract':'This is the abstract about this beautiful WMS layer.','parent_name':'','available_crs':['EPSG:3857','EPSG:4326'],'source_urls':[],'metadata_urls':[],'legend_url':'https://wms-host.de/services/example/wms?request=GetLegendGraphic&version=1.3.0&format=image/png&layer=example_layer_one','axis_names':[],'available_styles':['default'],'output_formats':[],'data_type':'','processing_level':'','attribute_fields':[],'minX':-5.0,'maxX':12.0,'minY':50.0,'maxY':61.989474,'date_time_start':'0000-12-30T00:00:00','date_time_end':'9999-12-31T23:59:59.999'}]}]
# Search for a service with 'Nice Service' in the title
In[06]: sc.get_services(limit=1, view='detail', search='title==*Nice+Service*')
Out[06]: [{'@uuid':'4d57fb41-9874-4ed2-94cb-05d9256a3900','id':654321,'name':'WMS','type':'WMS','version':'1.3.0','software':'GeoServer','title':'Some Nice Service Title','license':'CC-BY 4.0','abstract':'WMS','date_time_start':'0000-12-30T00:00:00','date_time_end':'9999-12-31T23:59:59.999','available_crs':['EPSG:3857','EPSG:4326'],'url':'https://wms-host.de/services/example/wms','filter_type':'OGC','minX':-5.0,'maxX':12.0,'minY':50.0,'maxY':61.989474,'keywords':[]'capabilities':'<full GetCapabilites document>','provider':{'@uuid':'55fe5448-79f1-41ed-80d7-98cd9edbf11f','id':1,'name':'Example Provider Name','acronym':'EPN','institute':'Example Institute'},'layers':[{'@uuid':'694041e6-8d33-4cc4-a94b-8f1a693a6d84','id':123456,'name':'example_layer_one','title':'Example Layer One','abstract':'This is the abstract about this beautiful WMS layer.','parent_name':'','available_crs':['EPSG:3857','EPSG:4326'],'source_urls':[],'metadata_urls':[],'legend_url':'https://wms-host.de/services/example/wms?request=GetLegendGraphic&version=1.3.0&format=image/png&layer=example_layer_one','axis_names':[],'available_styles':['default'],'output_formats':[],'data_type':'','processing_level':'','attribute_fields':[],'minX':-5.0,'maxX':12.0,'minY':50.0,'maxY':61.989474,'date_time_start':'0000-12-30T00:00:00','date_time_end':'9999-12-31T23:59:59.999'}]}]
In[04]: sc.get_services(limit=1, view='detail', search='title==*Nice+Service*')
Out[04]: [{'@uuid':'4d57fb41-9874-4ed2-94cb-05d9256a3900','id':654321,'name':'WMS','type':'WMS','version':'1.3.0','software':'GeoServer','title':'Some Nice Service Title','license':'CC-BY 4.0','abstract':'WMS','date_time_start':'0000-12-30T00:00:00','date_time_end':'9999-12-31T23:59:59.999','available_crs':['EPSG:3857','EPSG:4326'],'url':'https://wms-host.de/services/example/wms','filter_type':'OGC','minX':-5.0,'maxX':12.0,'minY':50.0,'maxY':61.989474,'keywords':[]'capabilities':'<full GetCapabilites document>','provider':{'@uuid':'55fe5448-79f1-41ed-80d7-98cd9edbf11f','id':1,'name':'Example Provider Name','acronym':'EPN','institute':'Example Institute'},'layers':[{'@uuid':'694041e6-8d33-4cc4-a94b-8f1a693a6d84','id':123456,'name':'example_layer_one','title':'Example Layer One','abstract':'This is the abstract about this beautiful WMS layer.','parent_name':'','available_crs':['EPSG:3857','EPSG:4326'],'source_urls':[],'metadata_urls':[],'legend_url':'https://wms-host.de/services/example/wms?request=GetLegendGraphic&version=1.3.0&format=image/png&layer=example_layer_one','axis_names':[],'available_styles':['default'],'output_formats':[],'data_type':'','processing_level':'','attribute_fields':[],'minX':-5.0,'maxX':12.0,'minY':50.0,'maxY':61.989474,'date_time_start':'0000-12-30T00:00:00','date_time_end':'9999-12-31T23:59:59.999'}]}]
```
### Save and use credentials
```bash
$ ipython3
# Python 3.6.+
# Load module
In[01]: from ServCat import ServCat, Administrator
# Save credentials (A)
In[02]: Administrator.set_credentials(name="My Provider Name")
> Please paste in your API KEY: mySecretProviderPassPhrase==
Out[02]: Saved credentials in 'C:/Users/User/.servcat-MyProvideName'
# Save credentials (B)
In[03]: Administrator.set_credentials(name="My Provider Name", passphrase="mySecretProviderPassPhrase==")
Out[03]: Saved credentials in 'C:/Users/User/.servcat-MyProvideName'
# Get credentials
In[04]: Administrator.get_credentials(name="My Provider Name")
Out[04]: 'mySecretProviderPassPhrase=='
# Use credentials in code
In[05]: service_json = { ... }
In[06]: sc = ServCat(host='https://marine-data.de/servcat/rest/', api_key=Administrator.get_credentials(name="My Provider Name"))
In[07]: sc.add_service(data=service_json)
Out[07]: <Response [200]>
```
\ No newline at end of file
......@@ -4,13 +4,21 @@ CHANGE LOG
--------------------------------------------------------------------------
0.0.2 2021-10-??
--------------------------------------------------------------------------
+ Fix installation problems under linux by adjust setup.py
+ Invent changelog
+ Switch from os to pathlib in set_credentials() and get_gredentials()
Methods in Administration class
+ Change behaviour of --config argument in harvest.py recipe. Now, the
given config can be:
A) a single file name (like "--config config.json") but the file must be
placed in "./recipes/res/") or
B) an absolute path (like "--config C:/Users/User/config.json").
+ Refine setup.py
+ Add 'single-source' version handling
+ Add 'single-source' author(s)
+ Add long description
+ Fix installation problems under linux
+ Add 'single-source' author(s) handling
+ Add long description text
--------------------------------------------------------------------------
0.0.1 2021-08-09
--------------------------------------------------------------------------
+ First Release
\ No newline at end of file
+ First Release
......@@ -783,22 +783,18 @@ class Administrator:
"""
# Get current user name
user_name = getpass.getuser()
# Get current user home directory
# user_home = os.path.expanduser("~")
user_home = Path.home()
# Replace all not fitting characters with '', to get valid file name
provider_name_clean = Administrator._regular_expression.sub(repl='', string=name)
# provider_name_clean = _re.sub(pattern=Administrator._regular_expression,
# repl='',
# string=name)
# Full file path
# file = os.path.normpath(os.path.join(user_home, f'.servcat-{provider_name_clean}'))
file = user_home / f'.servcat-{provider_name_clean}'
# Raise if File not exists
if not file.exists():
# if not os.path.isfile(file):
raise FileNotFoundError(f'No file found at {file.as_posix()}! '
f'You have to run Administrator.set_credentials() first!')
......@@ -819,21 +815,18 @@ class Administrator:
"""
# Get current user name
user_name = getpass.getuser()
# Get current user home directory
# user_home = os.path.expanduser("~")
user_home = Path.home()
# Replace all not fitting characters with '', to get valid file name
provider_name_clean = Administrator._regular_expression.sub(repl='', string=name)
# provider_name_clean = _re.sub(pattern=Administrator._regular_expression,
# repl='',
# string=name)
# Full file path
file = user_home / f'.servcat-{provider_name_clean}'
# file = os.path.normpath(os.path.join(user_home, f'.servcat-{provider_name_clean}'))
# Raise if file already exists
if file.is_file():
# if os.path.isfile(file):
raise FileExistsError(f"File '{file}' already exists!")
# Encode API KEY
......
# Harvesting OGC Web Services (OWS) for ServCat
Note: You need the API KEY for `Provider` 'SDI - Spatial Data Infrastructure' or 'SDI - Spatial Data Infrastructure - TEST' to run this script!
This script is designed to harvest all OGC Web Service (OWS) addresses given by the `--Config` parameter and put them into ServCat.
In the first part, all OWS Addresses from a config (or multiple configs) are harvested and turned into a ServCat Service describing
JSON object, called `ServCat JSON`.
It is possible to add multiple `--Config` parameters to upload multiple JSON config files at once.
# What is it good for?
This script is designed to harvest all OGC Web Service (OWS) addresses given by the `--config` argument(s) and register
the information from the underlying GetCapabilities document into ServCat. In the first part, all OWS Addresses from a
config (or multiple configs) are harvested and turned into a ServCat Service describing JSON object, called `ServCat JSON`.
It is possible to add multiple `--config` parameters to upload multiple JSON config files at once.
## JSON Config
A JSON config file can be created manually and is designed like the following:
```json
[
......@@ -18,9 +17,18 @@ A JSON config file can be created manually and is designed like the following:
}
]
```
For harvesting AWI or HZG ESRI services, you can use the `harvest_ESRI_from_HZG.py`, which is creating the JSON configs for those OWS automatically.
I a more generic description it looks like:
```bash
[
{
"software": [ESRI|GeoServer|THREDDS|rasdaman],
"types": {
[WMS|WFS|WCS]: <version>
},
"url": <URL>
}
]
```
The `ServCat JSON` object will be checked against ServCat in multiple ways:
1. Service and its Layers will be created, if Service entry is NOT existing in ServCat. Its uniqueness is defined by its URL and its Service Type (WMS, WFS, WCS)
2. Service (without it Layers) is updated, if Service is existing
......@@ -29,26 +37,24 @@ The `ServCat JSON` object will be checked against ServCat in multiple ways:
5. Layer(s) (from above Service) are updated, if existing in ServCat, and existing in `ServCat JSON`
## Commands
## Arguments
`-c` or `--config`: Path to config file of Minimal Service Description Objects, e.g. /path/to/services.json.
Multiple occurrences will be united to one list of objects.
`-P` or `--Provider`: Name of service providing institute.
`-H` or `--Host`: Name of the ServCat host to use. Allowed is `preview`or `productive`,
where `preview` is `postgres5.awi.de/servcat_test` and `productive` is `postgres5.awi.de/servcat`
Defaults to `preview`.
`-H` or `--Host`: Name of the ServCat host to use. Allowed is *preview* or *productive*,
where *preview* is `postgres5.awi.de/servcat_test` and *productive* is `postgres5.awi.de/servcat`
Defaults to *preview*.
`-h`or `--help`: Calling help page:
`-h`or `--help`: Calling help page.
## Usage
Let's imagine you have three JSON config files:
```commandline
```bash
$ cat /path/to/services_geoserver.json /path/to/services_esri.json /path/to/services_rasdaman.json
```
```commandline
```json
[
{ "software": "GeoServer",
"url": "https://maps.awi.de/services/common/bathymetry/wms",
......@@ -59,7 +65,7 @@ $ cat /path/to/services_geoserver.json /path/to/services_esri.json /path/to/serv
}
]
```
```commandline
```json
[
{ "software": "ESRI",
......@@ -72,7 +78,7 @@ $ cat /path/to/services_geoserver.json /path/to/services_esri.json /path/to/serv
}
]
```
```commandline
```json
[
{ "software": "rasdaman",
"url": "https://maps.awi.de/services/raster/ows",
......@@ -84,39 +90,7 @@ $ cat /path/to/services_geoserver.json /path/to/services_esri.json /path/to/serv
]
```
To harvest all listed services in all three JSON configs, let's say for the `preview` ServCat instance, run the following command:
```commandline
$ python harvest_OWS_for_servcat.py --Config /path/to/services_geoserver.json --Config /path/to/services_esri.json --Config /path/to/services_rasdaman.json --Host preview
```
## How to run inside SDI
### Configure and Execute ServCat Harvesting
Note: It is mandatory to add `/homelocal/gisadm/` as a Volume: `-v /homelocal/gisadm/:/home/gisadm/`
Note: API KEY must exist! You can get the API KEY by running o2a_spatial/ServCat/AddProvider.py
#### Set ServCat Provider Credentials
* Open a python3 console in a docker container
```commandline
$ docker run --rm -v /homelocal/gisadm/:/home/gisadm/ -it hub.awi.de/sdi/o2a_spatial:latest /bin/bash -c "python3"
```
* import ServCat module
```commandline
>>> from ServCat import ServCat
```
* Set credentials for provider 'SDI - Spatial Data Infrastructure':
```commandline
>>> ServCat.set_credentials(
... provider_name='SDI - Spatial Data Infrastructure',
... api_key='')
Saved credentials in '/home/gisadm/.servcat-SDI-SpatialDataInfrastructure'
```
#### Run script with config and host
```commandline
docker run --rm -v /homelocal/gisadm/:/home/gisadm/ -v /isibhv/:/isibhv/ -it hub.awi.de/sdi/o2a_spatial:latest /bin/bash -c "python3 /Recipes/OWS_Harvesting/harvest_OWS_for_servcat.py --Host preview --Provider 'AWI - Spatial Data Infrastructure #1' --config /Recipes/OWS_Harvesting/res/all_AWI_geoserver_services.json"
To harvest all listed services in all three JSON configs, let's say for the *preview* ServCat instance, run the following command:
```bash
$ python3 --Provider "AWI - Spatial Data Infrastructure #1" --Host preview --config all_AWI_esri_services.json --config all_AWI_geoserver_services.json
```
......@@ -45,6 +45,7 @@ __credits__ = 'Alfred Wegener Institute > Computing and Data Center > Software E
# --------------------------
# Import of Python Modules
# --------------------------
import re
import json
from typing import List, Dict, Union, Callable
from pathlib import Path
......@@ -62,6 +63,7 @@ from ServCat.MetadataHarvester.ESRI.ImageServer import WMSServer as IMSServer
from ServCat.MetadataHarvester.ESRI.MapServer import WMSServer, WFSServer
from ServCat.MetadataHarvester.WCS import WebCoverageService
from ServCat.MetadataHarvester.WFS import WebFeatureService
from harvest_utils import validate_config_paths
# ======================================================================================================================
# Mapping the harvester worker, and its supported version on the incoming service type
......@@ -214,12 +216,8 @@ def merge_minimal_service_objects(config_files: List[str]) -> List[dict]:
}
]
"""
# Turn paths into Path objects!
res = Path(__file__).parent / 'res'
config_paths = (res.joinpath(x.name) if not x.is_absolute() else x for x in (Path(y) for y in config_files))
service_description_objects = []
for path in config_paths:
for path in validate_config_paths(config_files):
if not path.exists():
logger.error(f'File does not exist: {path.as_posix()}')
continue
......@@ -418,20 +416,25 @@ if __name__ == '__main__':
provider_name = kwargs.Provider.strip("'").strip('"')
print(provider_name, SERVCAT_HOST)
# Prepare deleting the ' - preView(er)' extension to support both, with and without it!
preview_regex = re.compile(' - preView\(er\)')
if SERVCAT_HOST == 'productive':
provider_name = preview_regex.sub("", provider_name)
logger.info('ServCat Host: "https://marine-data.de/servcat/rest/"')
servcat = ServCat(host='https://marine-data.de/servcat/rest/',
api_key=Administrator.get_credentials(name=provider_name))
elif SERVCAT_HOST == 'preview':
provider_name = f'{preview_regex.sub("", provider_name)} - preView(er)'
logger.info('ServCat Host: "https://marine-data.de/preview/servcat/rest/"')
servcat = ServCat(host='https://marine-data.de/preview/servcat/rest/',
api_key=Administrator.get_credentials(name=f'{provider_name} - preView(er)'))
api_key=Administrator.get_credentials(name=provider_name))
else:
provider_name = f'{preview_regex.sub("", provider_name)} - preView(er)'
logger.warning(f"| ServCat Host was not set! Fallback to 'preview'")
logger.info('ServCat Host: "https://marine-data.de/servcat/rest/"')
servcat = ServCat(host='https://marine-data.de/preview/servcat/rest/',
api_key=Administrator.get_credentials(name=f'{provider_name} - preView(er)'))
api_key=Administrator.get_credentials(name=provider_name))
# logger.info(welcome_text)
......
# Script for running 'harvest_OWS_for_servcat.py' with different Providers
This script takes (hard coded) the `res/providers.config.json`, where `key`is the provider name, and `values` is a list
of JSON lists (see example below). For each provider it then calls the `harvest_OWS_for_servcat.py` with the provider name, the host and the JSON list as
arguments.
# What is it good for?
This script read-out the `providers.config.json` in the `./recipes/res/` folder, where `key` is the
provider name, and `values` is a list of relative or absolute config JSON files (see example below). For each provider
it then calls the `harvest.py` with the provider name in `--Provider` argument, and the JSON list as multiple `--config` arguments.
The only thing to adjust while calling it is the `--Host` argument. This can be set to *preview* or *productive*.
## Example call of `harvest_multiple.py`
### Default handling
```bash
python3 --Host preview
## Example of `res/providers.config.json`:
# which would lead to the following calls of the harvest.py script
> python3 --Provider "AWI - Spatial Data Infrastructure #1" --Host preview --config all_AWI_esri_services.json --config all_AWI_geoserver_services.json
> python3 --Provider "AWI - Spatial Data Infrastructure #2" --Host preview --config all_AWI_rasdaman_services.json
```
### Advanced handling
With the argument `--multi-config` you can pass over a JSON config from wherever you like.
```bash
python3 --Host preview --multi-config /home/user/providers.config.json
# which would lead to the following calls of the harvest.py script
> python3 --Provider "AWI - Spatial Data Infrastructure #1" --Host preview --config all_AWI_esri_services.json --config all_AWI_geoserver_services.json
> python3 --Provider "AWI - Spatial Data Infrastructure #2" --Host preview --config all_AWI_rasdaman_services.json
```
## Example of `providers.config.json`:
```json
{
"AWI - Spatial Data Infrastructure #1": [
"res/all_AWI_esri_services.json",
"res/all_AWI_geoserver_services.json"
"all_AWI_esri_services.json",
"all_AWI_geoserver_services.json"
],
"AWI - Spatial Data Infrastructure #2": [
"res/all_AWI_rasdaman_services.json"
],
"HZG - Data Coastal Research, HCDC #1": [
"res/all_HZG_esri_services.json",
"res/all_HZG_geoserver_services.json"
"all_AWI_rasdaman_services.json"
]
}
```
......@@ -30,15 +47,4 @@ arguments.
]
```
## Example call of the used script `harvest_OWS_for_servcat.py`:
```commandline
python3 --Provider "AWI - Spatial Data Infrastructure #2" --Host preview --config "res/all_AWI_rasdaman_services.json"
```
Before run this script, you have to make sure that to add the used provider with `o2a_spatial/ServCat/AddProvider.py`!
## Run script with config and host in SDI
```commandline
docker run --rm -v /homelocal/gisadm/:/home/gisadm/ -v /isibhv/:/isibhv/ -it hub.awi.de/sdi/o2a_spatial:latest /bin/bash -c "python3 /Recipes/OWS_Harvesting/harvest_OWS_from_providers.py --Host preview"
```
......@@ -47,6 +47,7 @@ __credits__ = 'Alfred Wegener Institute > Computer and Data Center > Software En
# --------------------------
import os
import json
import platform
from pathlib import Path
from argparse import ArgumentParser, RawTextHelpFormatter
......@@ -54,6 +55,7 @@ from argparse import ArgumentParser, RawTextHelpFormatter
# Import of self-written Modules
# --------------------------
from ServCat.Utils import DotDict
from harvest_utils import validate_config_paths
# ======================================================================================================================
# Simple Logger
......@@ -80,6 +82,10 @@ if __name__ == '__main__':
choices=('productive', 'preview'),
help="Name of the ServCat host to use. Defaults to 'preview'.")
parser.add_argument('--multi-config',
required=False,
help='Path to main config file')
kwargs, nargs = parser.parse_known_args()
# ==================================================================================================================
......@@ -87,7 +93,11 @@ if __name__ == '__main__':
# ==================================================================================================================
home = Path(__file__).parent
script = home / 'harvest.py'
config_file = home / 'res/providers.config.json'
config_file = home / 'res' / 'providers.config.json'
if kwargs.multi_config:
config_files = list(validate_config_paths(paths=(kwargs.multi_config, )))
assert len(config_files) > 0, AttributeError(f'wrong content in argument --multi-config: {kwargs.multi_config}')
config_file = config_files[0]
assert script.exists(), f'Script not found: {script}'
assert config_file.exists(), f'Config not found: {config_file}'
......@@ -105,7 +115,7 @@ if __name__ == '__main__':
for provider_name, service_paths in config.items():
# Concatenate paths to arguments
configs = ' '.join(f'--config {x}' for x in service_paths if Path(x).exists())
configs = ' '.join(f'--config {x.as_posix()}' for x in validate_config_paths(paths=service_paths))
# Header
logger.info('#' * 80)
......@@ -115,4 +125,13 @@ if __name__ == '__main__':
logger.info('#' * 80)
# Execute origin harvesting script
os.system(f'python {script} --Provider "{provider_name}" --Host {host} {configs}')
# Decide which cmd to use
if platform.system() == 'Linux':
os.system(f'python3 {script} --Provider "{provider_name}" --Host {host} {configs}')
elif platform.system() == 'Windows':
os.system(f'python {script} --Provider "{provider_name}" --Host {host} {configs}')
elif platform.system() == 'Darwin':
logger.warning('MacOS is not yet tested! Please contact admin at maps@awi.de')
else:
logger.warning('Your OS is not yet tested! Please contact admin at maps@awi.de')
"""
+-----------------------------------------------------------------------------------------------
| /\ / /
| /__\ /\ / / Alfred Wegener Institute
| / \/ \/ / Helmholtz Center for Polar and Marine Research
+-----------------------------------------------------------------------------------------------
| --- Computing and Data Center | Software Engineering ---
| -- Geo Information Systems & Spatial Data Infrastructure --
+-----------------------------------------------------------------------------------------------
| Copyright 2010-2021 - Alfred Wegener Institute, Helmholtz Centre for Polar and Marine Research
|
| Redistribution and use in source and binary forms, with or without
| modification, are permitted provided that the following conditions are met:
|
| 1. Redistributions of source code must retain the above copyright notice, this
| list of conditions and the following disclaimer.
|
| 2. Redistributions in binary form must reproduce the above copyright notice,
| this list of conditions and the following disclaimer in the documentation
| and/or other materials provided with the distribution.
|
| 3. Neither the name of the copyright holder nor the names of its
| contributors may be used to endorse or promote products derived from
| this software without specific prior written permission.
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+-----------------------------------------------------------------------------------------------
| Created on 20.10.2021
| @author: Andreas.Walter@awi.de
"""
__all__ = ['validate_config_paths']
__author__ = 'Andreas.Walter@awi.de'
__credits__ = 'Alfred Wegener Institute > Computing and Data Center > Software Engineering'
# --------------------------
# Import of Python Modules
# --------------------------
from pathlib import Path
from typing import Iterable, Iterator, Union
# --------------------------
# Import of self-written Modules
# --------------------------
def validate_config_paths(paths: Iterable[Union[str, Path]]) -> Iterable[Path]:
"""
Handling of incoming paths from argument '--config'.
@param paths: List, Set, Tuple, or Iterator of absolute or relative paths. Both, string or Path objects are allowed.
"""
def worker():
res = Path(__file__).parent / 'res'
for path in (Path(x) for x in paths):
if path.is_absolute() and path.exists():
yield path
continue
rel_path = res / path.name
if rel_path.exists():
yield rel_path
return iter(set(worker()))
if __name__ == '__main__':
pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment