Skip to content

Commit

Permalink
Use constants instead of string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
to-bar committed Jun 3, 2022
1 parent f2198c9 commit 442df6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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',
Expand All @@ -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}')
Expand Down Expand Up @@ -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.')
Expand Down

0 comments on commit 442df6c

Please sign in to comment.