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" sbo_repo_path = "/var/lib/slpkg/repository"
# The name of the database. Default name is 'database.slpkg'. # The name of the database. Default name is 'database.slpkg'.
database = "database.slpkg" database_name = "database.slpkg"
# Slackbuilds.org repository url. # Slackbuilds.org repository url.
sbo_repo_url = "http://slackbuilds.org/slackbuilds/15.0" sbo_repo_url = "http://slackbuilds.org/slackbuilds/15.0"

View file

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

View file

@ -10,13 +10,12 @@ from slpkg.configs import Configs
from slpkg.progress_bar import ProgressBar from slpkg.progress_bar import ProgressBar
class CheckUpdates: class CheckUpdates(Configs):
""" Check for changes in the ChangeLog file. """ """ Check for changes in the ChangeLog file. """
def __init__(self): def __init__(self):
self.configs = Configs super(Configs, self).__init__()
self.colors = self.configs.colour self.color = self.colour()
self.color = self.colors()
self.green = self.color['green'] self.green = self.color['green']
self.yellow = self.color['yellow'] self.yellow = self.color['yellow']
self.endc = self.color['endc'] self.endc = self.color['endc']
@ -26,12 +25,10 @@ class CheckUpdates:
""" Checks the ChangeLogs and returns True or False. """ """ Checks the ChangeLogs and returns True or False. """
local_date = 0 local_date = 0
local_chg_txt = Path(self.configs.sbo_repo_path, local_chg_txt = Path(self.sbo_repo_path, self.sbo_chglog_txt)
self.configs.sbo_chglog_txt)
http = urllib3.PoolManager() http = urllib3.PoolManager()
repo = http.request( repo = http.request('GET', f'{self.sbo_repo_url}/{self.sbo_chglog_txt}')
'GET', f'{self.configs.sbo_repo_url}/{self.configs.sbo_chglog_txt}')
if local_chg_txt.is_file(): if local_chg_txt.is_file():
local_date = int(os.stat(local_chg_txt).st_size) 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 from slpkg.utilities import Utilities
class Check: class Check(Configs, Utilities):
""" Some checks before proceed. """ """ Some checks before proceed. """
def __init__(self): def __init__(self):
self.configs = Configs super(Configs, self).__init__()
self.utils = Utilities() super(Utilities, self).__init__()
@staticmethod @staticmethod
def exists(slackbuilds: list): def exists(slackbuilds: list):
@ -43,9 +43,9 @@ class Check:
found, not_found = [], [] found, not_found = [], []
for sbo in slackbuilds: for sbo in slackbuilds:
package = self.utils.is_installed(sbo) package = self.is_installed(sbo)
if package: if package:
pkg = self.utils.split_installed_pkg(package)[0] pkg = self.split_installed_pkg(package)[0]
found.append(pkg) found.append(pkg)
else: else:
not_found.append(sbo) not_found.append(sbo)
@ -73,7 +73,7 @@ class Check:
def database(self): def database(self):
""" Checking for empty table """ """ 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(): if not SBoQueries('').sbos() or not db.is_file():
raise SystemExit('\nYou need to update the package lists first.\n' raise SystemExit('\nYou need to update the package lists first.\n'
'Please run slpkg update.\n') 'Please run slpkg update.\n')

View file

@ -27,7 +27,7 @@ class Md5sum:
checksum = "".join(checksum) checksum = "".join(checksum)
if file_check != 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 = ViewMessage(self.flags)
view.question() view.question()

View file

@ -45,7 +45,7 @@ class Configs:
log_packages: str = Path('/var', 'log', 'packages') log_packages: str = Path('/var', 'log', 'packages')
# Database name # Database name
database: str = f'database.{prog_name}' database_name: str = f'database.{prog_name}'
# SBo repository configs # SBo repository configs
sbo_repo_url: str = 'http://slackbuilds.org/slackbuilds/15.0' sbo_repo_url: str = 'http://slackbuilds.org/slackbuilds/15.0'
@ -87,7 +87,7 @@ class Configs:
sbo_repo_path: str = config['sbo_repo_path'] sbo_repo_path: str = config['sbo_repo_path']
# Database name # Database name
database: str = config['database'] database_name: str = config['database_name']
# SBo repository details # SBo repository details
sbo_repo_url: str = config['sbo_repo_url'] 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 from slpkg.models.models import session as Session
class CreateData: class CreateData(Configs):
""" Reads the SLACKBUILDS.TXT file and inserts them into the database. """ """ Reads the SLACKBUILDS.TXT file and inserts them into the database. """
def __init__(self): def __init__(self):
self.configs = Configs super(Configs, self).__init__()
self.session = Session self.session = Session
def insert_sbo_table(self): def insert_sbo_table(self):
@ -30,7 +30,7 @@ class CreateData:
'SLACKBUILD REQUIRES:', 'SLACKBUILD REQUIRES:',
'SLACKBUILD SHORT DESCRIPTION:' '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) sbo_file = self.read_file(path)
cache = [] # init cache cache = [] # init cache

View file

@ -11,7 +11,7 @@ from sqlalchemy import create_engine, Column, Integer, Text
from slpkg.configs import Configs 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) 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 from slpkg.models.models import session as Session
class ViewMessage: class ViewMessage(Configs):
""" Print some messages before. """ """ Print some messages before. """
def __init__(self, flags: list): def __init__(self, flags: list):
@ -25,10 +25,8 @@ class ViewMessage:
self.session = Session self.session = Session
self.utils = Utilities() self.utils = Utilities()
self.black = Blacklist() self.black = Blacklist()
self.dialog = DialogBox() self.dialogbox = DialogBox()
self.configs = Configs self.color = self.colour()
self.colors = self.configs.colour
self.color = self.colors()
self.yellow = self.color['yellow'] self.yellow = self.color['yellow']
self.cyan = self.color['cyan'] self.cyan = self.color['cyan']
self.red = self.color['red'] self.red = self.color['red']
@ -177,7 +175,7 @@ class ViewMessage:
text = f'There are {len(choices)} dependencies:' 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: if not code:
return dependencies return dependencies
@ -211,7 +209,7 @@ class ViewMessage:
elif option == 'build': elif option == 'build':
print(f'{self.grey}Total {len(slackbuilds)} packages ' 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': elif option == 'remove':
print(f'{self.grey}Total {remove} packages ' print(f'{self.grey}Total {remove} packages '
@ -219,7 +217,7 @@ class ViewMessage:
elif option == 'download': elif option == 'download':
print(f'{self.grey}{len(slackbuilds)} packages ' 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): def logs_packages(self, dependencies: list):
""" View the logging packages. """ """ View the logging packages. """