Updated for repo info

This commit is contained in:
Dimitris Zlatanidis 2023-03-30 09:06:14 +03:00
parent 51e488ea7f
commit dd1ac1bf70
7 changed files with 102 additions and 27 deletions

View file

@ -24,6 +24,14 @@ class BinQueries(Configs):
if self.name in self.black.packages():
self.name: str = ''
def count_packages(self):
""" Counts the number of the packages. """
count = self.session.query(
BinariesTable.id).where(
BinariesTable.repo == self.repo).count()
return count
def all_package_names_by_repo(self) -> list:
""" Returns all the names of the binaries packages. """
pkgs: tuple = self.session.query(

View file

@ -7,7 +7,8 @@ from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
from slpkg.models.models import session as Session
from slpkg.models.models import SBoTable, PonceTable, BinariesTable
from slpkg.models.models import (SBoTable, PonceTable,
BinariesTable, LastRepoUpdated)
class InstallData(Configs):
@ -24,6 +25,14 @@ class InstallData(Configs):
self.byellow: str = f'{self.bold}{self.yellow}'
self.endc: str = self.color['endc']
def last_updated(self, repo_file: Path) -> str:
""" Reads the first date of the changelog file."""
lines: list = self.utils.read_file(repo_file)
days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
for line in lines:
if line.startswith(days):
return line.replace('\n', '')
def install_sbos_data(self) -> None:
""" Install the data for SBo repository. """
sbo_tags = [
@ -39,10 +48,13 @@ class InstallData(Configs):
'SLACKBUILD SHORT DESCRIPTION:'
]
sbo_table = SBoTable
path = Path(self.repos.sbo_repo_path, self.repos.sbo_repo_slackbuilds)
sbo_name: str = self.repos.sbo_repo_name
path: Path = Path(self.repos.sbo_repo_path, self.repos.sbo_repo_slackbuilds)
path_changelog: Path = Path(self.repos.sbo_repo_path, self.repos.sbo_repo_changelog)
if self.repos.ponce_repo:
sbo_table = PonceTable
sbo_name: str = self.repos.ponce_repo_name
path = Path(self.repos.ponce_repo_path, self.repos.ponce_repo_slackbuilds)
slackbuilds_txt: list = self.utils.read_file(path)
@ -68,6 +80,10 @@ class InstallData(Configs):
cache: list = [] # reset cache after 11 lines
last_updated: str = self.last_updated(path_changelog)
date: str = LastRepoUpdated(repo=sbo_name, date=last_updated)
self.session.add(date)
print(f'{self.byellow}Done{self.endc}')
self.session.commit()
@ -85,6 +101,7 @@ class InstallData(Configs):
]
path_packages: Path = Path(self.repos.alien_repo_path, self.repos.alien_repo_packages)
path_checksums: Path = Path(self.repos.alien_repo_path, self.repos.alien_repo_checksums)
path_changelog: Path = Path(self.repos.alien_repo_path, self.repos.alien_repo_changelog)
packages_txt: list = self.utils.read_file(path_packages)
checksums_md5: list = self.utils.read_file(path_checksums)
@ -154,6 +171,10 @@ class InstallData(Configs):
cache: list = [] # reset cache
last_updated: str = self.last_updated(path_changelog)
date: str = LastRepoUpdated(repo=self.repos.alien_repo_name, date=last_updated)
self.session.add(date)
print(f'{self.byellow}Done{self.endc}')
self.session.commit()
@ -171,6 +192,7 @@ class InstallData(Configs):
]
path_packages: Path = Path(self.repos.gnome_repo_path, self.repos.gnome_repo_packages)
path_checksums: Path = Path(self.repos.gnome_repo_path, self.repos.gnome_repo_checksums)
path_changelog: Path = Path(self.repos.gnome_repo_path, self.repos.gnome_repo_changelog)
packages_txt: list = self.utils.read_file(path_packages)
checksums_md5: list = self.utils.read_file(path_checksums)
@ -239,6 +261,10 @@ class InstallData(Configs):
cache: list = [] # reset cache
last_updated: str = self.last_updated(path_changelog)
date: str = LastRepoUpdated(repo=self.repos.gnome_repo_name, date=last_updated)
self.session.add(date)
print(f'{self.byellow}Done{self.endc}')
self.session.commit()
@ -256,6 +282,7 @@ class InstallData(Configs):
]
path_packages: Path = Path(self.repos.conraid_repo_path, self.repos.conraid_repo_packages)
path_checksums: Path = Path(self.repos.conraid_repo_path, self.repos.conraid_repo_checksums)
path_changelog: Path = Path(self.repos.conraid_repo_path, self.repos.conraid_repo_changelog)
checksums_md5: list = self.utils.read_file(path_checksums)
packages_txt: list = self.utils.read_file(path_packages)
@ -325,6 +352,10 @@ class InstallData(Configs):
cache: list = [] # reset cache
last_updated: str = self.last_updated(path_changelog)
date: str = LastRepoUpdated(repo=self.repos.conraid_repo_name, date=last_updated)
self.session.add(date)
print(f'{self.byellow}Done{self.endc}')
self.session.commit()
@ -342,6 +373,7 @@ class InstallData(Configs):
]
path_packages: Path = Path(self.repos.slackonly_repo_path, self.repos.slackonly_repo_packages)
path_checksums: Path = Path(self.repos.slackonly_repo_path, self.repos.slackonly_repo_checksums)
path_changelog: Path = Path(self.repos.slackonly_repo_path, self.repos.slackonly_repo_changelog)
packages_txt: list = self.utils.read_file(path_packages)
checksums_md5: list = self.utils.read_file(path_checksums)
@ -411,6 +443,10 @@ class InstallData(Configs):
cache: list = [] # reset cache
last_updated: str = self.last_updated(path_changelog)
date: str = LastRepoUpdated(repo=self.repos.slackonly_repo_name, date=last_updated)
self.session.add(date)
print(f'{self.byellow}Done{self.endc}')
self.session.commit()

View file

@ -783,10 +783,10 @@ def main():
'-t': argparse.tracking
}
try:
arguments[args[0]]()
except (KeyError, IndexError):
usage.help_short(1)
# try:
arguments[args[0]]()
# except (KeyError, IndexError):
usage.help_short(1)
if __name__ == '__main__':

View file

@ -90,4 +90,15 @@ class LogsDependencies(Base):
requires: str = Column(Text)
@dataclass
class LastRepoUpdated(Base):
""" The table that saves the last updated date. """
__tablename__ = 'lastupdated'
id: int = Column(Integer, primary_key=True)
repo: str = Column(Text)
date: str = Column(Text)
Base.metadata.create_all(engine)

View file

@ -2,13 +2,14 @@
# -*- coding: utf-8 -*-
import shutil
from pathlib import Path
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.sbos.queries import SBoQueries
from slpkg.repositories import Repositories
from slpkg.binaries.queries import BinQueries
from slpkg.models.models import LastRepoUpdated
from slpkg.models.models import session as Session
class RepoInfo(Configs):
@ -20,6 +21,7 @@ class RepoInfo(Configs):
self.repos = Repositories()
self.color = self.colour()
self.columns, self.rows = shutil.get_terminal_size()
self.session = Session
self.bold: str = self.color['bold']
self.green: str = self.color['green']
@ -32,13 +34,14 @@ class RepoInfo(Configs):
def info(self):
""" Prints information about repositories. """
total_packages: int = 0
enabled: int = 0
print('Repositories Information:')
print('=' * self.columns)
print(f"{'Name:':<18}{'Status:':<15}{'Last Updated:':<35}{'Packages:':>12}")
print('=' * self.columns)
total_packages: int = 0
enabled: int = 0
for repo, value in self.repos.repos_dict.items():
count: int = 0
status: str = 'Disabled'
@ -48,15 +51,20 @@ class RepoInfo(Configs):
status: str = 'Enabled'
color: str = self.green
last: str = self.last_update(Path(value[1], value[2]))
last: str = self.session.query(
LastRepoUpdated.date).where(
LastRepoUpdated.repo == repo).first()
if last is None:
last: tuple = ('',)
packages: dict = {
self.repos.sbo_repo_name: len(SBoQueries('').sbos()),
self.repos.ponce_repo_name: len(SBoQueries('').sbos()),
self.repos.alien_repo_name: len(BinQueries('', repo).all_package_names_by_repo()),
self.repos.gnome_repo_name: len(BinQueries('', repo).all_package_names_by_repo()),
self.repos.conraid_repo_name: len(BinQueries('', repo).all_package_names_by_repo()),
self.repos.slackonly_repo_name: len(BinQueries('', repo).all_package_names_by_repo())
self.repos.sbo_repo_name: SBoQueries('').count_packages(),
self.repos.ponce_repo_name: SBoQueries('').count_packages(),
self.repos.alien_repo_name: BinQueries('', repo).count_packages(),
self.repos.gnome_repo_name: BinQueries('', repo).count_packages(),
self.repos.conraid_repo_name: BinQueries('', repo).count_packages(),
self.repos.slackonly_repo_name: BinQueries('', repo).count_packages()
}
if value[0]:
@ -64,16 +72,8 @@ class RepoInfo(Configs):
total_packages += count
print(f"{self.cyan}{repo:<18}{self.endc}{color}{status:<15}{self.endc}{last:<35}"
print(f"{self.cyan}{repo:<18}{self.endc}{color}{status:<15}{self.endc}{last[0]:<35}"
f"{self.yellow}{count:>12}{self.endc}")
print('=' * self.columns)
print(f"{self.grey}Total of {enabled} repositories are enabled with {total_packages} packages available.")
def last_update(self, repo_file: Path) -> str:
""" Reads the first date of the changelog file."""
lines: list = self.utils.read_file(repo_file)
days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
for line in lines:
if line.startswith(days):
return line.replace('\n', '')

View file

@ -29,6 +29,13 @@ class SBoQueries(Configs):
if self.repos.ponce_repo:
self.sbo_table = PonceTable
def count_packages(self):
""" Counts the number of the packages. """
count = self.session.query(
self.sbo_table.id).count()
return count
def repo_name(self):
""" Returns the repo name by the table. """
table = inspect(self.sbo_table)

View file

@ -15,7 +15,8 @@ from slpkg.repositories import Repositories
from slpkg.check_updates import CheckUpdates
from slpkg.models.models import session as Session
from slpkg.models.models import (Base, engine, SBoTable,
PonceTable, BinariesTable)
PonceTable, BinariesTable,
LastRepoUpdated)
class UpdateRepository(Configs):
@ -87,6 +88,7 @@ class UpdateRepository(Configs):
print()
self.delete_binaries_data(self.repos.alien_repo_name)
self.delete_last_updated(self.repos.alien_repo_name)
self.data.install_alien_data()
print()
else:
@ -112,6 +114,7 @@ class UpdateRepository(Configs):
print()
self.delete_binaries_data(self.repos.gnome_repo_name)
self.delete_last_updated(self.repos.gnome_repo_name)
self.data.install_gnome_data()
print()
else:
@ -138,6 +141,7 @@ class UpdateRepository(Configs):
print()
self.delete_binaries_data(self.repos.conraid_repo_name)
self.delete_last_updated(self.repos.conraid_repo_name)
self.data.install_conraid_data()
print()
else:
@ -164,6 +168,7 @@ class UpdateRepository(Configs):
print()
self.delete_binaries_data(self.repos.slackonly_repo_name)
self.delete_last_updated(self.repos.slackonly_repo_name)
self.data.install_slackonly_data()
print()
else:
@ -192,6 +197,7 @@ class UpdateRepository(Configs):
os.chdir(self.repos.ponce_repo_path)
gen_command: str = f'./gen_sbo_txt.sh > {self.repos.ponce_repo_slackbuilds}'
self.utils.process(gen_command)
self.delete_last_updated(self.repos.ponce_repo_name)
print('\n')
else:
@ -205,6 +211,7 @@ class UpdateRepository(Configs):
lftp_command: str = (f'lftp {self.lftp_mirror_options} {self.repos.sbo_repo_mirror} '
f'{self.repos.sbo_repo_path}')
self.utils.process(lftp_command)
self.delete_last_updated(self.repos.sbo_repo_name)
self.delete_sbo_data()
self.data.install_sbos_data()
@ -277,6 +284,11 @@ class UpdateRepository(Configs):
self.session.query(BinariesTable).where(BinariesTable.repo == repo).delete()
self.session.commit()
def delete_last_updated(self, repo) -> None:
""" Deletes the last updated date. """
self.session.query(LastRepoUpdated).where(LastRepoUpdated.repo == repo).delete()
self.session.commit()
def drop_the_tables(self):
""" Drop all the tables from the database. """
print(f'\n{self.prog_name}: {self.bred}WARNING{self.endc}: All the data from the database will be deleted!')
@ -285,7 +297,8 @@ class UpdateRepository(Configs):
tables: list = [
PonceTable.__table__,
SBoTable.__table__,
BinariesTable.__table__
BinariesTable.__table__,
LastRepoUpdated.__table__
]
Base.metadata.drop_all(bind=engine, tables=tables)