Commit 08401e16 authored by Felix Delattre's avatar Felix Delattre
Browse files

Added argument handler for building_id file

parent 7067f170
Pipeline #21795 passed with stage
in 1 minute and 24 seconds
...@@ -21,6 +21,7 @@ from argparse import ArgumentParser ...@@ -21,6 +21,7 @@ from argparse import ArgumentParser
from .argument_base import ArgumentBase from .argument_base import ArgumentBase
from .arguments.building_id import ArgumentBuildingId from .arguments.building_id import ArgumentBuildingId
from .arguments.building_ids_file import ArgumentBuildingIdsFile
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -35,6 +36,7 @@ class ArgumentFactory: ...@@ -35,6 +36,7 @@ class ArgumentFactory:
self.arguments = {} self.arguments = {}
self.add_argument(ArgumentBuildingId()) self.add_argument(ArgumentBuildingId())
self.add_argument(ArgumentBuildingIdsFile())
def add_to_parser(self, parser: ArgumentParser): def add_to_parser(self, parser: ArgumentParser):
......
...@@ -30,6 +30,7 @@ class ArgumentBuildingId(ArgumentBase): ...@@ -30,6 +30,7 @@ class ArgumentBuildingId(ArgumentBase):
async def execute(self, message_bus, argument, value): async def execute(self, message_bus, argument, value):
logger.info(f"Dispatching `{argument}` with `{value}` on `{self.rabotnik_message}`.") logger.info(
"Dispatching `%s` with `%s` on `%s`.", argument, value, self.rabotnik_message
)
await message_bus.send(message=self.rabotnik_message, payload={argument: value}) await message_bus.send(message=self.rabotnik_message, payload={argument: value})
#!/usr/bin/env python3
# Copyright (C) 2020-2021:
# Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero 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 Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import logging
from ..argument_base import ArgumentBase
logger = logging.getLogger(__name__)
class ArgumentBuildingIdsFile(ArgumentBase):
def __init__(self):
self.argument = "--building-ids-file"
self.rabotnik_message = "building"
self.help_text = "File with many `building_id` in every new line"
async def execute(self, message_bus, argument, filename):
with open(filename) as f:
data = f.read()
for line in data:
value = line.strip()
logger.info(
"Dispatching `%s` with `%s` on `%s`.", argument, value, self.rabotnik_message
)
await message_bus.send(message=self.rabotnik_message, payload={argument: value})
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