Changeset View
Changeset View
Standalone View
Standalone View
swh/core/config.py
# Copyright (C) 2015 The Software Heritage developers | # Copyright (C) 2015 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import configparser | import configparser | ||||
import logging | import logging | ||||
import os | import os | ||||
import yaml | import yaml | ||||
from itertools import chain | from itertools import chain | ||||
from copy import deepcopy | from copy import deepcopy | ||||
from typing import Any, Dict, Optional, Tuple | |||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
SWH_CONFIG_DIRECTORIES = [ | SWH_CONFIG_DIRECTORIES = [ | ||||
'~/.config/swh', | '~/.config/swh', | ||||
'~/.swh', | '~/.swh', | ||||
'/etc/softwareheritage', | '/etc/softwareheritage', | ||||
▲ Show 20 Lines • Show All 285 Lines • ▼ Show 20 Lines | The class should override the class attributes: | ||||
- CONFIG_BASE_FILENAME (the filename of the configuration to be used) | - CONFIG_BASE_FILENAME (the filename of the configuration to be used) | ||||
This class defines one classmethod, parse_config_file, which | This class defines one classmethod, parse_config_file, which | ||||
parses a configuration file using the default config as set in the | parses a configuration file using the default config as set in the | ||||
class attribute. | class attribute. | ||||
""" | """ | ||||
DEFAULT_CONFIG = {} | DEFAULT_CONFIG = {} # type: Dict[str, Tuple[str, Any]] | ||||
CONFIG_BASE_FILENAME = '' | CONFIG_BASE_FILENAME = '' # type: Optional[str] | ||||
@classmethod | @classmethod | ||||
def parse_config_file(cls, base_filename=None, config_filename=None, | def parse_config_file(cls, base_filename=None, config_filename=None, | ||||
additional_configs=None, global_config=True): | additional_configs=None, global_config=True): | ||||
"""Parse the configuration file associated to the current class. | """Parse the configuration file associated to the current class. | ||||
By default, parse_config_file will load the configuration | By default, parse_config_file will load the configuration | ||||
cls.CONFIG_BASE_FILENAME from one of the Software Heritage | cls.CONFIG_BASE_FILENAME from one of the Software Heritage | ||||
Show All 37 Lines |