Fixed ignore comments for list.pkgs files

This commit is contained in:
Dimitris Zlatanidis 2023-03-07 20:33:12 +02:00
parent 8955f01aed
commit 2129f15540
4 changed files with 33 additions and 16 deletions

View file

@ -1,4 +1,7 @@
4.5.6 - 02/03/2023
4.5.6 - 07/03/2023
Added:
- Ignore comments for list.pkgs files (Thanks to rizitis)
Updated:
- Ponce repository
- slpkg.toml file for ponce repository

View file

@ -16,19 +16,26 @@ class Check(Configs, Utilities):
super(Configs, self).__init__()
super(Utilities, self).__init__()
@staticmethod
def exists(slackbuilds: list) -> None:
self.black = Blacklist()
def exists(self, slackbuilds: list) -> list:
""" Checking if the slackbuild exists in the repository. """
not_packages: list = []
for sbo in slackbuilds:
if not SBoQueries(sbo).slackbuild():
if sbo in self.black.packages():
slackbuilds.remove(sbo)
elif not SBoQueries(sbo).slackbuild():
not_packages.append(sbo)
if not_packages:
raise SystemExit(f'\nPackages \'{", ".join(not_packages)}\' '
'does not exists.\n')
return slackbuilds
@staticmethod
def unsupported(slackbuilds: list) -> None:
""" Checking for unsupported slackbuilds. """
@ -59,9 +66,8 @@ class Check(Configs, Utilities):
def blacklist(self, slackbuilds: list) -> None:
""" Checking if the packages are blacklisted. """
packages: list = []
black = Blacklist()
for package in black.packages():
for package in self.black.packages():
if package in slackbuilds:
packages.append(package)

View file

@ -314,7 +314,7 @@ class Argparse(Configs):
""" Checks if the arg is filelist.pkgs. """
if self.args[1].endswith(self.file_list_suffix):
file = Path(self.args[1])
packages: list = self.utils.read_packages_from_file(file)
packages: list = list(self.utils.read_packages_from_file(file))
else:
packages: list = list(set(self.args[1:]))
@ -419,7 +419,6 @@ class Argparse(Configs):
def check_updates(self) -> None:
if len(self.args) == 1:
self.check.database()
check = CheckUpdates()
check.updates()
raise SystemExit()
@ -467,7 +466,7 @@ class Argparse(Configs):
packages: list = self.choose_packages(packages, command)
self.check.database()
self.check.exists(packages)
packages: list = self.check.exists(packages)
self.check.unsupported(packages)
build = Slackbuilds(packages, self.flags, self.file_pattern, mode=command)
@ -486,7 +485,7 @@ class Argparse(Configs):
packages: list = self.choose_packages(packages, command)
self.check.database()
self.check.exists(packages)
packages: list = self.check.exists(packages)
self.check.unsupported(packages)
install = Slackbuilds(packages, self.flags, self.file_pattern, mode=command)
@ -505,7 +504,7 @@ class Argparse(Configs):
packages: list = self.choose_packages(packages, command)
self.check.database()
self.check.exists(packages)
packages: list = self.check.exists(packages)
download = Download(self.directory, self.flags)
download.packages(packages)
raise SystemExit()
@ -557,7 +556,7 @@ class Argparse(Configs):
packages: list = self.choose_packages(packages, command)
self.check.database()
self.check.exists(packages)
packages: list = self.check.exists(packages)
view = ViewPackage(self.flags)
view.package(packages)
@ -592,7 +591,7 @@ class Argparse(Configs):
packages: list = self.choose_packages(packages, command)
self.check.database()
self.check.exists(packages)
packages: list = self.check.exists(packages)
dependees = Dependees(packages, self.flags)
dependees.slackbuilds()
@ -610,7 +609,7 @@ class Argparse(Configs):
packages: list = self.choose_packages(packages, command)
self.check.database()
self.check.exists(packages)
packages: list = self.check.exists(packages)
tracking = Tracking(self.flags)
tracking.packages(packages)

View file

@ -116,7 +116,16 @@ class Utilities:
def read_packages_from_file(file) -> list:
""" Reads packages from file and split these to list. """
try:
with open(file, 'r', encoding='utf-8') as packages:
return packages.read().splitlines()
with open(file, 'r', encoding='utf-8') as pkgs:
packages = pkgs.read().splitlines()
for package in packages:
if package and not package.startswith('#'):
if '#' in package:
package = package.split('#')[0].strip()
yield package
except FileNotFoundError as err:
raise SystemExit(f'Error: {err}')