-
Notifications
You must be signed in to change notification settings - Fork 19
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 #137 from adybbroe/feature-scisys-receiver-create-…
…publish-topic-from-config-pattern-and-message Create publish topic in scisys-receiver from config-pattern and message
- Loading branch information
Showing
7 changed files
with
189 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2012 - 2021 Pytroll developers | ||
# Copyright (c) 2012 - 2023 Pytroll developers | ||
# | ||
# Author(s): | ||
# | ||
# Martin Raspaud <[email protected]> | ||
# Janne Kotro <[email protected]> | ||
# Panu Lahtinen <[email protected]> | ||
# Adam Dybbroe <Firstname.Lastname at smhi.se> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
|
@@ -52,24 +53,13 @@ def parse_args(): | |
local_ips.remove('127.0.0.1') | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("host", help="GMC host") | ||
parser.add_argument("port", help="Port to listen to", type=int) | ||
parser.add_argument("-c", "--config", | ||
help="YAML config file to use.") | ||
parser.add_argument("-P", "--publish-port", type=int, default=0, | ||
dest="publish_port", help="Publish port") | ||
parser.add_argument("-n", "--nameserver", nargs='+', default=[], | ||
dest="nameservers", | ||
help="Nameserver(s) to connect to") | ||
parser.add_argument("-s", "--station", help="Name of the station", | ||
dest="station", | ||
default="unknown") | ||
parser.add_argument("-x", "--excluded_satellites", nargs='*', | ||
help="List of platform names to exclude", | ||
dest="excluded_satellites", | ||
default=[]) | ||
parser.add_argument("-e", "--environment", | ||
help="Name of the environment (e.g. dev, test, oper)", | ||
dest="environment", | ||
default="dev") | ||
parser.add_argument("-l", "--log", help="File to log to", | ||
dest="log", default=None) | ||
parser.add_argument("-f", "--ftp_prefix", dest="ftp_prefix", | ||
|
@@ -82,11 +72,6 @@ def parse_args(): | |
help="IP of the target server." | ||
"In case of multiple dispatches in GMC." | ||
"Defaults to the local host.") | ||
parser.add_argument("-T", "--topic_postfix", | ||
dest="topic_postfix", | ||
type=str, | ||
help="Publish topic postfix. " | ||
"Prefix will be /format/data_processing_level/") | ||
|
||
return parser.parse_args() | ||
|
||
|
@@ -115,15 +100,16 @@ def main(): | |
"""Run scisys receiver.""" | ||
opts = parse_args() | ||
|
||
no_sats = opts.excluded_satellites | ||
configfile = opts.config | ||
|
||
# no_sats = opts.excluded_satellites | ||
|
||
setup_logging(log_file=opts.log) | ||
|
||
try: | ||
receive_from_zmq(opts.host, opts.port, | ||
opts.station, opts.environment, no_sats, | ||
receive_from_zmq(configfile, | ||
opts.target_server, opts.ftp_prefix, | ||
opts.topic_postfix, publish_port=opts.publish_port, | ||
publish_port=opts.publish_port, | ||
nameservers=opts.nameservers, days=1) | ||
except KeyboardInterrupt: | ||
pass | ||
|
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,13 @@ | ||
# Publish topic | ||
publish_topic_pattern: "/{sensor}/{format}/{data_processing_level}/{platform_name}" | ||
|
||
# GMC Server host | ||
host: my-reception-server-name | ||
# Port to listen to | ||
port: portnumber | ||
|
||
station: nrk | ||
environment: dev | ||
|
||
excluded_satellites: | ||
- fy3d |
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,33 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2023 Pytroll Developers | ||
|
||
# Author(s): | ||
|
||
# Adam Dybbroe <Firstname.Lastname at smhi.se> | ||
|
||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
|
||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Handling the yaml configurations.""" | ||
|
||
import yaml | ||
|
||
|
||
def read_config(config_filepath): | ||
"""Read and extract config information.""" | ||
with open(config_filepath, 'r') as fp_: | ||
config = yaml.safe_load(fp_) | ||
|
||
return 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
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,53 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2023 Adam.Dybbroe | ||
|
||
# Author(s): | ||
|
||
# Adam.Dybbroe <[email protected]> | ||
|
||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
|
||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Fixtures for unittests.""" | ||
|
||
import pytest | ||
|
||
|
||
TEST_YAML_CONFIG_CONTENT_SCISYS_RECEIVER = """ | ||
# Publish topic | ||
publish_topic_pattern: '/{sensor}/{format}/{data_processing_level}/{platform_name}' | ||
# It is possible to here add a static postfix topic if needed: | ||
topic_postfix: "my/cool/postfix/topic" | ||
host: merlin | ||
port: 10600 | ||
station: nrk | ||
environment: dev | ||
excluded_satellites: | ||
- fy3d | ||
""" | ||
|
||
|
||
@pytest.fixture | ||
def fake_yamlconfig_file_for_scisys_receiver(tmp_path): | ||
"""Write fake yaml config file for the SCISYS receiver.""" | ||
file_path = tmp_path / 'test_scisys_receiver_config.yaml' | ||
with open(file_path, 'w') as fpt: | ||
fpt.write(TEST_YAML_CONFIG_CONTENT_SCISYS_RECEIVER) | ||
|
||
yield file_path |
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,40 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2023 Adam.Dybbroe | ||
|
||
# Author(s): | ||
|
||
# Adam.Dybbroe <[email protected]> | ||
|
||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
|
||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Test getting the yaml configurations from file.""" | ||
|
||
from pytroll_collectors.config import read_config | ||
|
||
|
||
def test_get_yaml_configuration(fake_yamlconfig_file_for_scisys_receiver): | ||
"""Test read and get the yaml configuration for the scisys receiver from file.""" | ||
config = read_config(fake_yamlconfig_file_for_scisys_receiver) | ||
|
||
assert config['publish_topic_pattern'] == '/{sensor}/{format}/{data_processing_level}/{platform_name}' | ||
assert config['topic_postfix'] == 'my/cool/postfix/topic' | ||
assert config['host'] == 'merlin' | ||
assert isinstance(config['port'], int) | ||
assert config['port'] == 10600 | ||
assert config['station'] == 'nrk' | ||
assert config['environment'] == 'dev' | ||
assert len(config['excluded_satellites']) == 1 | ||
assert config['excluded_satellites'][0] == 'fy3d' |
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