argument_factory.py 1.8 KB
Newer Older
Felix Delattre's avatar
Felix Delattre committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/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 argparse import ArgumentParser

from .argument_base import ArgumentBase
from .arguments.building_id import ArgumentBuildingId
24
from .arguments.building_ids_file import ArgumentBuildingIdsFile
Felix Delattre's avatar
Felix Delattre committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38

logger = logging.getLogger(__name__)


class ArgumentFactory:
    def __init__(self):
        """Create and import argument classes based on a given selector.

        Args:
            selector (str): The name to find the associated argument handler
        """

        self.arguments = {}
        self.add_argument(ArgumentBuildingId())
39
        self.add_argument(ArgumentBuildingIdsFile())
Felix Delattre's avatar
Felix Delattre committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53

    def add_to_parser(self, parser: ArgumentParser):

        group = parser.add_argument_group("rabotnik arguments").add_mutually_exclusive_group(
            required=True
        )

        for argument_object in self.arguments.values():
            argument_object.add_argument_to_parser(group)

    def add_argument(self, argument_object: ArgumentBase):

        argument = argument_object.get_formatted_argument()
        self.arguments[argument] = argument_object