Updated for split options

This commit is contained in:
Dimitris Zlatanidis 2023-05-05 21:19:18 +03:00
parent 3608e62ca5
commit d86c997eeb

View file

@ -280,7 +280,9 @@ class Argparse(Configs):
self.invalid_options()
self.check_for_repositories()
if self.utils.is_binary_repo(self.repository):
self.is_binary: bool = self.utils.is_binary_repo(self.repository)
if self.is_binary:
self.data: dict = BinQueries(self.repository).repository_data()
else:
self.data: dict = SBoQueries(self.repository).repository_data()
@ -302,7 +304,6 @@ class Argparse(Configs):
except_options: list = [
'-s', 'search',
]
if self.repository == '*' and not self.utils.is_option(except_options, self.args):
self.usage.help_minimal(f"{self.prog_name}: invalid repository '{self.repository}'")
@ -374,43 +375,36 @@ class Argparse(Configs):
def split_options_from_args(self) -> None:
""" Split options from arguments.
slpkg -f package --file-pattern='*'
slpkg -d package --directory=/path/to/download
Splits the option ['--file-pattern'] and ['*']
Splits the option ['--directory'] and ['/path/to/download/']
"""
for arg in self.args:
if arg.startswith(self.flag_directory):
self.directory: str = arg.split('=')[1]
self.args[self.args.index(arg)] = self.flag_directory
if arg.startswith(self.flag_short_directory) and len(self.args) > 3:
try:
self.args.remove(arg)
self.args.append(self.flag_directory)
try:
if arg.startswith(self.flag_short_directory):
self.directory: str = self.args[self.args.index(arg) + 1]
except IndexError:
logger = logging.getLogger(LoggingConfig.date)
logger.exception(f'{self.__class__.__name__}: '
f'{self.__class__.split_options_from_args.__name__}')
self.directory: Path = self.tmp_slpkg
else:
self.args.remove(self.directory)
self.args.remove(arg)
self.args.append(self.flag_short_directory)
except IndexError:
self.directory: Path = self.tmp_slpkg
if arg.startswith(self.flag_repository):
self.repository: str = arg.split('=')[1]
self.args[self.args.index(arg)] = self.flag_repository
self.args.remove(arg)
self.args.append(self.flag_repository)
if arg.startswith(self.flag_short_repository) and len(self.args) > 2:
try:
try:
if arg.startswith(self.flag_short_repository):
self.repository: str = self.args[self.args.index(arg) + 1]
except IndexError:
logger = logging.getLogger(LoggingConfig.date)
logger.exception(f'{self.__class__.__name__}: '
f'{self.__class__.split_options_from_args.__name__}')
self.repository = ''
else:
self.args.remove(self.repository)
if self.repository in self.options:
self.repository: str = ''
self.args.remove(arg)
self.args.append(self.flag_short_repository)
except IndexError:
self.repository = ''
def move_options(self) -> None:
""" Move options to the flags and removes from the arguments. """
@ -464,7 +458,7 @@ class Argparse(Configs):
inst_pkg: str = self.utils.is_package_installed(package)
split_inst_pkg: list = self.utils.split_binary_pkg(inst_pkg)
if self.utils.is_binary_repo(self.repository):
if self.is_binary:
repo_ver: str = self.data[package][0]
bin_pkg: str = self.data[package][1]
repo_build_tag: str = self.utils.split_binary_pkg(bin_pkg[:-4])[3]
@ -481,7 +475,7 @@ class Argparse(Configs):
for package in repo_packages:
if pkg in package or pkg == '*':
if self.utils.is_binary_repo(self.repository):
if self.is_binary:
repo_ver: str = self.data[package][0]
else:
repo_ver: str = self.data[package][2]
@ -540,7 +534,7 @@ class Argparse(Configs):
print('\nEverything is up-to-date!\n')
raise SystemExit()
if self.utils.is_binary_repo(self.repository):
if self.is_binary:
install = Packages(self.repository, self.data, packages, self.flags, mode=command)
install.execute()
else:
@ -620,7 +614,7 @@ class Argparse(Configs):
if self.utils.is_option(self.flag_searches, self.flags):
packages: list = self.choose_packages(packages, command)
if self.utils.is_binary_repo(self.repository):
if self.is_binary:
self.check.exists_in_the_database(packages)
install = Packages(self.repository, self.data, packages, self.flags, mode=command)
@ -699,7 +693,7 @@ class Argparse(Configs):
view = ViewPackage(self.flags)
if self.utils.is_binary_repo(self.repository):
if self.is_binary:
view.package(self.data, packages, self.repository)
else:
view.slackbuild(self.data, packages)