This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1049 from CCI-Tools/forman-xxx-configure_data_sto…
…res_by_given_root Configure data store "local" by given root
- Loading branch information
Showing
5 changed files
with
107 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,26 @@ | ||
# The MIT License (MIT) | ||
# Copyright (c) 2016, 2017 by the ESA CCI Toolbox development team and contributors | ||
# Copyright (c) 2016-2023 by the ESA CCI Toolbox team and contributors | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
# this software and associated documentation files (the "Software"), to deal in | ||
# the Software without restriction, including without limitation the rights to | ||
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
# of the Software, and to permit persons to whom the Software is furnished to do | ||
# so, subject to the following conditions: | ||
# Permission is hereby granted, free of charge, to any person obtaining a | ||
# copy of this software and associated documentation files (the "Software"), | ||
# to deal in the Software without restriction, including without limitation | ||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
# and/or sell copies of the Software, and to permit persons to whom the | ||
# Software is furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
import logging | ||
|
||
from xcube.util.assertions import assert_given | ||
|
||
_LOG = logging.getLogger('cate') | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
# DEALINGS IN THE SOFTWARE. | ||
|
||
|
||
def cate_init(): | ||
# Plugin initializer. | ||
import yaml | ||
import os | ||
from xcube.core.store import DataStoreConfig | ||
from xcube.core.store import get_data_store_params_schema | ||
|
||
from cate.conf import get_data_stores_path | ||
from cate.conf.defaults import STORES_CONF_FILE | ||
from cate.core.common import default_user_agent | ||
from cate.core.ds import DATA_STORE_POOL | ||
|
||
dir_path = os.path.dirname(os.path.abspath(__file__)) | ||
default_stores_file = os.path.join(dir_path, 'data/stores.yml') | ||
|
||
if os.path.exists(STORES_CONF_FILE): | ||
with open(STORES_CONF_FILE, 'r') as fp: | ||
store_configs = yaml.safe_load(fp) | ||
else: | ||
with open(default_stores_file, 'r') as fp: | ||
store_configs = yaml.safe_load(fp) | ||
|
||
for store_name, store_config in store_configs.items(): | ||
store_id = store_config.get('store_id') | ||
assert_given(store_id, name='store_id', exception_type=RuntimeError) | ||
|
||
if store_id == 'file' \ | ||
and 'store_params' in store_config: | ||
root = store_config.get('store_params', {}).get('root') | ||
if root is None: | ||
root = os.environ.get('CATE_LOCAL_DATA_STORE_PATH', | ||
os.path.join(get_data_stores_path(), | ||
store_name)) | ||
else: | ||
root = os.path.abspath(os.path.expanduser(root)) | ||
# Note: even if the root directory doesn't exist yet, | ||
# the xcube "file" data store will create it for us. | ||
store_config['store_params']['root'] = root | ||
|
||
store_params_schema = get_data_store_params_schema(store_id) | ||
if 'user_agent' in store_params_schema.properties: | ||
if 'store_params' not in store_config: | ||
store_config['store_params'] = {} | ||
store_config['store_params']['user_agent'] = default_user_agent() | ||
|
||
store_config = DataStoreConfig.from_dict(store_config) | ||
DATA_STORE_POOL.add_store_config(store_name, store_config) | ||
"""Cate plugin initializer.""" | ||
from .stores import configure_data_stores | ||
configure_data_stores() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# The MIT License (MIT) | ||
# Copyright (c) 2016-2023 by the ESA CCI Toolbox team and contributors | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a | ||
# copy of this software and associated documentation files (the "Software"), | ||
# to deal in the Software without restriction, including without limitation | ||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
# and/or sell copies of the Software, and to permit persons to whom the | ||
# Software is furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
# DEALINGS IN THE SOFTWARE. | ||
|
||
import os | ||
from typing import Optional | ||
|
||
import yaml | ||
|
||
from cate.conf import get_data_stores_path | ||
from cate.conf.defaults import STORES_CONF_FILE | ||
from cate.core.common import default_user_agent | ||
from cate.core.ds import DATA_STORE_POOL | ||
from xcube.core.store import DataStoreConfig | ||
from xcube.core.store import get_data_store_params_schema | ||
from xcube.util.assertions import assert_given | ||
|
||
|
||
def configure_data_stores(local_root_path: Optional[str] = None): | ||
"""Configure Cate's data stores. | ||
:param local_root_path: Optional root path | ||
for the data store named "local". | ||
""" | ||
|
||
if os.path.exists(STORES_CONF_FILE): | ||
with open(STORES_CONF_FILE, 'r') as fp: | ||
store_configs = yaml.safe_load(fp) | ||
else: | ||
dir_path = os.path.dirname(os.path.abspath(__file__)) | ||
default_stores_file = os.path.join(dir_path, 'data/stores.yml') | ||
|
||
with open(default_stores_file, 'r') as fp: | ||
store_configs = yaml.safe_load(fp) | ||
|
||
for store_name, store_config in store_configs.items(): | ||
store_id = store_config.get('store_id') | ||
assert_given(store_id, name='store_id', exception_type=RuntimeError) | ||
|
||
if store_name == 'local': | ||
if local_root_path is not None: | ||
root = local_root_path | ||
else: | ||
root = store_config.get('store_params', {}).get('root') | ||
if root is None: | ||
root = os.environ.get('CATE_LOCAL_DATA_STORE_PATH', | ||
os.path.join(get_data_stores_path(), | ||
store_name)) | ||
root = os.path.abspath(os.path.expanduser(root)) | ||
# Note: even if the root directory doesn't exist yet, | ||
# the xcube "file" data store will create it for us. | ||
store_config['store_params']['root'] = root | ||
|
||
store_params_schema = get_data_store_params_schema(store_id) | ||
if 'user_agent' in store_params_schema.properties: | ||
if 'store_params' not in store_config: | ||
store_config['store_params'] = {} | ||
store_config['store_params']['user_agent'] = default_user_agent() | ||
|
||
store_config = DataStoreConfig.from_dict(store_config) | ||
DATA_STORE_POOL.add_store_config(store_name, store_config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters