Updated for inheritance classes

This commit is contained in:
Dimitris Zlatanidis 2023-01-17 00:47:01 +02:00
parent 8556d0f30c
commit 834901244d
9 changed files with 28 additions and 33 deletions

View file

@ -15,7 +15,7 @@
sbo_repo_path = "/var/lib/slpkg/repository"
# The name of the database. Default name is 'database.slpkg'.
database = "database.slpkg"
database_name = "database.slpkg"
# Slackbuilds.org repository url.
sbo_repo_url = "http://slackbuilds.org/slackbuilds/15.0"

View file

@ -7,15 +7,15 @@ from pathlib import Path
from slpkg.configs import Configs
class Blacklist:
class Blacklist(Configs):
""" Reads and returns the blacklist. """
def __init__(self):
self.configs = Configs
super(Configs, self).__init__()
def get(self) -> list:
""" Reads the blacklist file. """
file = Path(self.configs.etc_path, 'blacklist.toml')
file = Path(self.etc_path, 'blacklist.toml')
if file.is_file():
with open(file, 'rb') as black:
return tomli.load(black)['blacklist']['packages']

View file

@ -10,13 +10,12 @@ from slpkg.configs import Configs
from slpkg.progress_bar import ProgressBar
class CheckUpdates:
class CheckUpdates(Configs):
""" Check for changes in the ChangeLog file. """
def __init__(self):
self.configs = Configs
self.colors = self.configs.colour
self.color = self.colors()
super(Configs, self).__init__()
self.color = self.colour()
self.green = self.color['green']
self.yellow = self.color['yellow']
self.endc = self.color['endc']
@ -26,12 +25,10 @@ class CheckUpdates:
""" Checks the ChangeLogs and returns True or False. """
local_date = 0
local_chg_txt = Path(self.configs.sbo_repo_path,
self.configs.sbo_chglog_txt)
local_chg_txt = Path(self.sbo_repo_path, self.sbo_chglog_txt)
http = urllib3.PoolManager()
repo = http.request(
'GET', f'{self.configs.sbo_repo_url}/{self.configs.sbo_chglog_txt}')
repo = http.request('GET', f'{self.sbo_repo_url}/{self.sbo_chglog_txt}')
if local_chg_txt.is_file():
local_date = int(os.stat(local_chg_txt).st_size)

View file

@ -9,12 +9,12 @@ from slpkg.blacklist import Blacklist
from slpkg.utilities import Utilities
class Check:
class Check(Configs, Utilities):
""" Some checks before proceed. """
def __init__(self):
self.configs = Configs
self.utils = Utilities()
super(Configs, self).__init__()
super(Utilities, self).__init__()
@staticmethod
def exists(slackbuilds: list):
@ -43,9 +43,9 @@ class Check:
found, not_found = [], []
for sbo in slackbuilds:
package = self.utils.is_installed(sbo)
package = self.is_installed(sbo)
if package:
pkg = self.utils.split_installed_pkg(package)[0]
pkg = self.split_installed_pkg(package)[0]
found.append(pkg)
else:
not_found.append(sbo)
@ -73,7 +73,7 @@ class Check:
def database(self):
""" Checking for empty table """
db = Path(self.configs.db_path, self.configs.database)
db = Path(self.db_path, self.database_name)
if not SBoQueries('').sbos() or not db.is_file():
raise SystemExit('\nYou need to update the package lists first.\n'
'Please run slpkg update.\n')

View file

@ -27,7 +27,7 @@ class Md5sum:
checksum = "".join(checksum)
if file_check != checksum:
self.ascii.checksum_error_box(name, checksum, file_check)
self.ascii.draw_checksum_error_box(name, checksum, file_check)
view = ViewMessage(self.flags)
view.question()

View file

@ -45,7 +45,7 @@ class Configs:
log_packages: str = Path('/var', 'log', 'packages')
# Database name
database: str = f'database.{prog_name}'
database_name: str = f'database.{prog_name}'
# SBo repository configs
sbo_repo_url: str = 'http://slackbuilds.org/slackbuilds/15.0'
@ -87,7 +87,7 @@ class Configs:
sbo_repo_path: str = config['sbo_repo_path']
# Database name
database: str = config['database']
database_name: str = config['database_name']
# SBo repository details
sbo_repo_url: str = config['sbo_repo_url']

View file

@ -9,11 +9,11 @@ from slpkg.models.models import SBoTable
from slpkg.models.models import session as Session
class CreateData:
class CreateData(Configs):
""" Reads the SLACKBUILDS.TXT file and inserts them into the database. """
def __init__(self):
self.configs = Configs
super(Configs, self).__init__()
self.session = Session
def insert_sbo_table(self):
@ -30,7 +30,7 @@ class CreateData:
'SLACKBUILD REQUIRES:',
'SLACKBUILD SHORT DESCRIPTION:'
]
path = Path(self.configs.sbo_repo_path, self.configs.sbo_txt)
path = Path(self.sbo_repo_path, self.sbo_txt)
sbo_file = self.read_file(path)
cache = [] # init cache

View file

@ -11,7 +11,7 @@ from sqlalchemy import create_engine, Column, Integer, Text
from slpkg.configs import Configs
DATABASE_URI = os.path.join(f'sqlite:///{Configs.db_path}', Configs.database)
DATABASE_URI = os.path.join(f'sqlite:///{Configs.db_path}', Configs.database_name)
engine = create_engine(DATABASE_URI)

View file

@ -14,7 +14,7 @@ from slpkg.models.models import LogsDependencies
from slpkg.models.models import session as Session
class ViewMessage:
class ViewMessage(Configs):
""" Print some messages before. """
def __init__(self, flags: list):
@ -25,10 +25,8 @@ class ViewMessage:
self.session = Session
self.utils = Utilities()
self.black = Blacklist()
self.dialog = DialogBox()
self.configs = Configs
self.colors = self.configs.colour
self.color = self.colors()
self.dialogbox = DialogBox()
self.color = self.colour()
self.yellow = self.color['yellow']
self.cyan = self.color['cyan']
self.red = self.color['red']
@ -177,7 +175,7 @@ class ViewMessage:
text = f'There are {len(choices)} dependencies:'
code, tags = self.dialog.checklist(text, title, height, width, list_height, choices, dependencies)
code, tags = self.dialogbox.checklist(text, title, height, width, list_height, choices, dependencies)
if not code:
return dependencies
@ -211,7 +209,7 @@ class ViewMessage:
elif option == 'build':
print(f'{self.grey}Total {len(slackbuilds)} packages '
f'will be build in {self.configs.tmp_path} folder.{self.endc}')
f'will be build in {self.tmp_path} folder.{self.endc}')
elif option == 'remove':
print(f'{self.grey}Total {remove} packages '
@ -219,7 +217,7 @@ class ViewMessage:
elif option == 'download':
print(f'{self.grey}{len(slackbuilds)} packages '
f'will be downloaded in {self.configs.download_only} folder.{self.endc}')
f'will be downloaded in {self.download_only} folder.{self.endc}')
def logs_packages(self, dependencies: list):
""" View the logging packages. """