From 90d4da7434ecbbb8545dd6e677951d8ce2c83a5d Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Fri, 31 Mar 2023 20:55:40 +0300 Subject: [PATCH] Added salixos_extra repo --- configs/repositories.toml | 9 ++++ slpkg/check_updates.py | 7 +++ slpkg/install_data.py | 100 +++++++++++++++++++++++++++++++++++++ slpkg/repo_info.py | 1 + slpkg/repositories.py | 19 +++++++ slpkg/update_repository.py | 33 ++++++++++++ slpkg/utilities.py | 2 +- 7 files changed, 170 insertions(+), 1 deletion(-) diff --git a/configs/repositories.toml b/configs/repositories.toml index f9eb037f..7fe3fd5f 100644 --- a/configs/repositories.toml +++ b/configs/repositories.toml @@ -100,6 +100,15 @@ SALIXOS_REPO_CHECKSUMS = "CHECKSUMS.md5" SALIXOS_REPO_CHANGELOG = "ChangeLog.txt" + # Repository for slackware 15.0 stable. + SALIXOS_EXTRA_REPO_NAME = "salixos_extra" + SALIXOS_EXTRA_REPO = false + SALIXOS_EXTRA_REPO_MIRROR = "https://download.salixos.org/x86_64/slackware-15.0/extra/" + SALIXOS_EXTRA_REPO_CHANGELOG_MIRROR = 'https://download.salixos.org/x86_64/slackware-15.0/' + SALIXOS_EXTRA_REPO_PACKAGES = "PACKAGES.TXT" + SALIXOS_EXTRA_REPO_CHECKSUMS = "CHECKSUMS.md5" + SALIXOS_EXTRA_REPO_CHANGELOG = "ChangeLog.txt" + # Repository for slackware -current. SLACKEL_REPO_NAME = "slackel" SLACKEL_REPO = false diff --git a/slpkg/check_updates.py b/slpkg/check_updates.py index 68e004d6..4d78b22c 100644 --- a/slpkg/check_updates.py +++ b/slpkg/check_updates.py @@ -81,6 +81,13 @@ class CheckUpdates(Configs): self.repo_chg_txt: str = f'{self.repos.salixos_repo_mirror}{self.repos.salixos_repo_changelog}' compare[self.repos.salixos_repo_name] = self.compare_dates() + if self.repos.salixos_extra_repo and self.repo == self.repos.salixos_extra_repo_name or self.repo == '*': + self.local_chg_txt: Path = Path(self.repos.salixos_extra_repo_path, + self.repos.salixos_extra_repo_changelog) + self.repo_chg_txt: str = (f'{self.repos.salixos_extra_repo_changelog_mirror}' + f'{self.repos.salixos_extra_repo_changelog}') + compare[self.repos.salixos_extra_repo_name] = self.compare_dates() + if self.repos.slackel_repo and self.repo == self.repos.slackel_repo_name or self.repo == '*': self.local_chg_txt: Path = Path(self.repos.slackel_repo_path, self.repos.slackel_repo_changelog) self.repo_chg_txt: str = f'{self.repos.slackel_repo_mirror}{self.repos.slackel_repo_changelog}' diff --git a/slpkg/install_data.py b/slpkg/install_data.py index 7eff12a1..fc75528d 100644 --- a/slpkg/install_data.py +++ b/slpkg/install_data.py @@ -801,6 +801,106 @@ class InstallData(Configs): self.session.commit() + def install_salixos_extra_data(self) -> None: + """ Install the data for salixos_extra repository. """ + checksums_dict: dict = {} + pkg_tag = [ + 'PACKAGE NAME:', + 'PACKAGE LOCATION:', + 'PACKAGE SIZE (compressed):', + 'PACKAGE SIZE (uncompressed):', + 'PACKAGE REQUIRED:', + 'PACKAGE DESCRIPTION:' + ] + path_packages: Path = Path(self.repos.salixos_extra_repo_path, self.repos.salixos_extra_repo_packages) + path_checksums: Path = Path(self.repos.salixos_extra_repo_path, self.repos.salixos_extra_repo_checksums) + path_changelog: Path = Path(self.repos.salixos_extra_repo_path, + self.repos.salixos_extra_repo_changelog) + packages_txt: list = self.utils.read_file(path_packages) + checksums_md5: list = self.utils.read_file(path_checksums) + + for line in checksums_md5: + line = line.strip() + + if line.endswith(('.txz', '.tgz')): + file: str = line.split('./')[1].split('/')[-1].strip() + checksum: str = line.split('./')[0].strip() + checksums_dict[file] = checksum + + cache: list = [] # init cache + + print('Creating the database... ', end='', flush=True) + + for line in packages_txt: + + if line.startswith(pkg_tag[0]): + package_name = line.replace(pkg_tag[0], '').strip() + split_package: list = self.utils.split_binary_pkg(package_name) + cache.append(split_package[0]) # package name + cache.append(split_package[1]) # package version + cache.append(package_name) + cache.append(self.repos.salixos_extra_repo_mirror) + try: + cache.append(checksums_dict[package_name]) + except KeyError: + cache.append('error checksum') + + if line.startswith(pkg_tag[1]): + package_location = line.replace(pkg_tag[1], '').strip() + cache.append(package_location[1:]) # Do not install (.) dot + + if line.startswith(pkg_tag[2]): + package_size_comp = line.replace(pkg_tag[2], '').strip() + cache.append(f'{package_size_comp}B') + + if line.startswith(pkg_tag[3]): + package_size_uncomp = line.replace(pkg_tag[3], '').strip() + cache.append(f'{package_size_uncomp}B') + + if line.startswith(pkg_tag[4]): + deps: list = [] + required = line.replace(pkg_tag[4], '').strip() + + for req in required.split(','): + dep = req.split('|') + if len(dep) > 1: + deps.append(dep[1]) + else: + deps += dep + + cache.append(' '.join(deps)) + + if line.startswith(pkg_tag[5]): + package_description = line.replace(pkg_tag[5], '').strip() + cache.append(package_description) + + if len(cache) == 10: + data: str = BinariesTable( + repo=self.repos.salixos_extra_repo_name, + name=cache[0], + version=cache[1], + package=cache[2], + mirror=cache[3], + checksum=cache[4], + location=cache[5], + size_comp=cache[6], + size_uncomp=cache[7], + required=cache[8], + description=cache[9] + ) + + self.session.add(data) + + cache: list = [] # reset cache + + last_updated: str = self.last_updated(path_changelog) + date: str = LastRepoUpdated(repo=self.repos.salixos_extra_repo_name, date=last_updated) + self.session.add(date) + + print(f'{self.byellow}Done{self.endc}') + + self.session.commit() + def install_slackel_data(self) -> None: """ Install the data for slackel repository. """ checksums_dict: dict = {} diff --git a/slpkg/repo_info.py b/slpkg/repo_info.py index 2736ac47..89539806 100644 --- a/slpkg/repo_info.py +++ b/slpkg/repo_info.py @@ -69,6 +69,7 @@ class RepoInfo(Configs): self.repos.slackonly_repo_name: BinQueries('', repo).count_packages(), self.repos.ponce_bin_repo_name: BinQueries('', repo).count_packages(), self.repos.salixos_repo_name: BinQueries('', repo).count_packages(), + self.repos.salixos_extra_repo_name: BinQueries('', repo).count_packages(), self.repos.slackel_repo_name: BinQueries('', repo).count_packages() } diff --git a/slpkg/repositories.py b/slpkg/repositories.py index 4e86fb7a..90feb5f2 100644 --- a/slpkg/repositories.py +++ b/slpkg/repositories.py @@ -107,6 +107,15 @@ class Repositories: salixos_repo_packages: str = 'PACKAGES.TXT' salixos_repo_checksums: str = 'CHECKSUMS.md5' salixos_repo_changelog: str = 'ChangeLog.txt' + + salixos_extra_repo_name: str = 'salixos_extra' + salixos_extra_repo: bool = False + salixos_extra_repo_path: Path = Path(config.lib_path, 'repositories', salixos_extra_repo_name) + salixos_extra_repo_mirror: str = 'https://download.salixos.org/x86_64/slackware-15.0/extra/' + salixos_extra_repo_changelog_mirror: str = 'https://download.salixos.org/x86_64/slackware-15.0/' + salixos_extra_repo_packages: str = 'PACKAGES.TXT' + salixos_extra_repo_checksums: str = 'CHECKSUMS.md5' + salixos_extra_repo_changelog: str = 'ChangeLog.txt' slackel_repo_name: str = 'slackel' slackel_repo: bool = False @@ -200,6 +209,14 @@ class Repositories: salixos_repo_checksums: str = repos['SALIXOS_REPO_CHECKSUMS'] salixos_repo_changelog: str = repos['SALIXOS_REPO_CHANGELOG'] + salixos_extra_repo_name: str = repos['SALIXOS_EXTRA_REPO_NAME'] + salixos_extra_repo: bool = repos['SALIXOS_EXTRA_REPO'] + salixos_extra_repo_mirror: str = repos['SALIXOS_EXTRA_REPO_MIRROR'] + salixos_extra_repo_changelog_mirror: str = repos['SALIXOS_EXTRA_REPO_CHANGELOG_MIRROR'] + salixos_extra_repo_packages: str = repos['SALIXOS_EXTRA_REPO_PACKAGES'] + salixos_extra_repo_checksums: str = repos['SALIXOS_EXTRA_REPO_CHECKSUMS'] + salixos_extra_repo_changelog: str = repos['SALIXOS_EXTRA_REPO_CHANGELOG'] + slackel_repo_name: str = repos['SLACKEL_REPO_NAME'] slackel_repo: bool = repos['SLACKEL_REPO'] slackel_repo_mirror: str = repos['SLACKEL_REPO_MIRROR'] @@ -224,6 +241,7 @@ class Repositories: slackonly_repo_name: slackonly_repo, ponce_bin_repo_name: ponce_bin_repo, salixos_repo_name: salixos_repo, + salixos_extra_repo_name: salixos_extra_repo, slackel_repo_name: slackel_repo } @@ -249,5 +267,6 @@ class Repositories: slackonly_repo_name: [slackonly_repo, slackonly_repo_path, slackonly_repo_changelog], ponce_bin_repo_name: [ponce_bin_repo, ponce_bin_repo_path, ponce_bin_repo_changelog], salixos_repo_name: [salixos_repo, salixos_repo_path, salixos_repo_changelog], + salixos_extra_repo_name: [salixos_extra_repo_name, salixos_extra_repo_path, salixos_extra_repo_changelog], slackel_repo_name: [slackel_repo, slackel_repo_path, slackel_repo_changelog] } diff --git a/slpkg/update_repository.py b/slpkg/update_repository.py index 32c98ac8..eacfcebb 100644 --- a/slpkg/update_repository.py +++ b/slpkg/update_repository.py @@ -78,6 +78,9 @@ class UpdateRepository(Configs): if self.repo == self.repos.salixos_repo_name or self.repo == '*': self.salixos_repository() + if self.repo == self.repos.salixos_extra_repo_name or self.repo == '*': + self.salixos_extra_repository() + if self.repo == self.repos.slackel_repo_name or self.repo == '*': self.slackel_repository() else: @@ -297,6 +300,36 @@ class UpdateRepository(Configs): else: self.not_enabled_message(self.repos.salixos_repo_name) + def salixos_extra_repository(self): + if self.repos.salixos_extra_repo: + urls: list = [] + print('Updating the packages list...\n') + print(f"Downloading the '{self.green}{self.repos.salixos_extra_repo_name}{self.endc}' " + f"repository, please wait...\n") + self.make_dirs(self.repos.salixos_extra_repo_name) + + urls.append(f'{self.repos.salixos_extra_repo_mirror}{self.repos.salixos_extra_repo_packages}') + urls.append(f'{self.repos.salixos_extra_repo_changelog_mirror}{self.repos.salixos_extra_repo_changelog}') + urls.append(f'{self.repos.salixos_extra_repo_mirror}{self.repos.salixos_extra_repo_checksums}') + + self.utils.remove_file_if_exists(self.repos.salixos_extra_repo_path, + self.repos.salixos_extra_repo_packages) + self.utils.remove_file_if_exists(self.repos.salixos_extra_repo_path, + self.repos.salixos_extra_repo_changelog) + self.utils.remove_file_if_exists(self.repos.salixos_extra_repo_path, + self.repos.salixos_extra_repo_checksums) + + down = Downloader(self.repos.salixos_extra_repo_path, urls, self.flags) + down.download() + print() + + self.delete_binaries_data(self.repos.salixos_extra_repo_name) + self.delete_last_updated(self.repos.salixos_extra_repo_name) + self.data.install_salixos_extra_data() + print() + else: + self.not_enabled_message(self.repos.salixos_extra_repo_name) + def slackel_repository(self): if self.repos.slackel_repo: urls: list = [] diff --git a/slpkg/utilities.py b/slpkg/utilities.py index a793b246..9392370a 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -148,7 +148,7 @@ class Utilities: @staticmethod def read_file(file: Union[str, Path]) -> list: """ Reads the text file. """ - with open(file, 'r', encoding='utf-8') as f: + with open(file, 'r', encoding='utf-8', errors='replace') as f: return f.readlines() @staticmethod