From 442df6c5ce9896259a23d88aee7bb39d53653cc5 Mon Sep 17 00:00:00 2001 From: to-bar <46519524+to-bar@users.noreply.github.com> Date: Fri, 3 Jun 2022 13:22:55 +0000 Subject: [PATCH] Use constants instead of string literals --- .../src/mode/debian_family_mode.py | 12 ++++++------ .../src/mode/red_hat_family_mode.py | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ansible/playbooks/roles/repository/files/download-requirements/src/mode/debian_family_mode.py b/ansible/playbooks/roles/repository/files/download-requirements/src/mode/debian_family_mode.py index 7ee8af4290..207149e715 100644 --- a/ansible/playbooks/roles/repository/files/download-requirements/src/mode/debian_family_mode.py +++ b/ansible/playbooks/roles/repository/files/download-requirements/src/mode/debian_family_mode.py @@ -11,23 +11,23 @@ class DebianFamilyMode(BaseMode): """ Used by distros based of Debian GNU/Linux """ + APT_REPOS_DIR = Path('/etc/apt/sources.list.d') def __init__(self, config: Config): super().__init__(config) self.__create_repo_paths() self.__installed_packages: List[str] = [] - self.__repos_config_dir: Path = Path('/etc/apt/sources.list.d') def __create_repo_paths(self): - for repo in self._repositories.keys(): - self._repositories[repo]['path'] = Path('/etc/apt/sources.list.d') / f'{repo}.list' + for repo_id, repo_item in self._repositories.items(): + repo_item['path'] = self.APT_REPOS_DIR / f'{repo_id}.list' def _create_backup_repositories(self): if not self._cfg.repos_backup_file.exists(): logging.debug('Creating backup for system repositories...') self._tools.tar.pack(self._cfg.repos_backup_file, targets=[Path('/etc/apt/sources.list'), - Path('/etc/apt/sources.list.d')], + self.APT_REPOS_DIR], verbose=True, preserve=True, absolute_names=True, @@ -128,8 +128,8 @@ def _download_crane_binary(self, url: str, dest: Path): self._tools.wget.download(url, dest) def _remove_repository_files(self): - logging.debug(f'Removing files from {self.__repos_config_dir}...') - for repo_file in self.__repos_config_dir.iterdir(): + logging.debug(f'Removing files from {self.APT_REPOS_DIR}...') + for repo_file in self.APT_REPOS_DIR.iterdir(): logging.debug(f'- {repo_file.name}') repo_file.unlink() logging.debug('Done removing files.') diff --git a/ansible/playbooks/roles/repository/files/download-requirements/src/mode/red_hat_family_mode.py b/ansible/playbooks/roles/repository/files/download-requirements/src/mode/red_hat_family_mode.py index f30ed775bb..f2e11b041a 100644 --- a/ansible/playbooks/roles/repository/files/download-requirements/src/mode/red_hat_family_mode.py +++ b/ansible/playbooks/roles/repository/files/download-requirements/src/mode/red_hat_family_mode.py @@ -14,22 +14,22 @@ class RedHatFamilyMode(BaseMode): """ Used by distros based of RedHat GNU/Linux """ + DNF_REPOS_DIR = Path('/etc/yum.repos.d') def __init__(self, config: Config): super().__init__(config) self.__all_queried_packages: Set[str] = set() self.__archs: List[str] = [config.os_arch.value, 'noarch'] self.__base_packages: List[str] = ['curl', 'python3-dnf-plugins-core', 'wget', 'tar'] - self.__dnf_cache_path: Path = Path('/var/cache/dnf') + self.__dnf_cache_dir: Path = Path('/var/cache/dnf') self.__installed_packages: List[str] = [] - self.__repos_config_dir: Path = Path('/etc/yum.repos.d') try: dnf_config = configparser.ConfigParser() with Path('/etc/dnf/dnf.conf').open() as dnf_config_file: dnf_config.read(dnf_config_file) - self.__dnf_cache_path = Path(dnf_config['main']['cachedir']) + self.__dnf_cache_dir = Path(dnf_config['main']['cachedir']) except FileNotFoundError: logging.debug('RedHatFamilyMode.__init__(): dnf config file not found') except configparser.Error as e: @@ -115,7 +115,7 @@ def _add_third_party_repositories(self): def __remove_dnf_cache_for_custom_repos(self): # clean metadata for upgrades (when the same package can be downloaded from changed repo) - cache_paths: List[str] = list(self.__dnf_cache_path.iterdir()) + cache_paths: List[str] = list(self.__dnf_cache_dir.iterdir()) id_names = [ '2ndquadrant', @@ -133,7 +133,7 @@ def __remove_dnf_cache_for_custom_repos(self): if matched_cache_paths: matched_cache_paths.sort() - logging.debug(f'Removing DNF cache files from {self.__dnf_cache_path}...') + logging.debug(f'Removing DNF cache files from {self.__dnf_cache_dir}...') for path in matched_cache_paths: logging.debug(f'- {path.name}') @@ -228,8 +228,8 @@ def _download_crane_binary(self, url: str, dest: Path): self._tools.wget.download(url, dest, additional_params=False) def _remove_repository_files(self): - logging.debug(f'Removing files from {self.__repos_config_dir}...') - for repo_file in self.__repos_config_dir.iterdir(): + logging.debug(f'Removing files from {self.DNF_REPOS_DIR}...') + for repo_file in self.DNF_REPOS_DIR.iterdir(): logging.debug(f'- {repo_file.name}') repo_file.unlink() logging.debug('Done removing files.')