mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-29 10:26:12 +01:00
Updated for slackbuild
This commit is contained in:
parent
76e0ee92cd
commit
544f5ec764
1 changed files with 53 additions and 70 deletions
|
@ -50,7 +50,6 @@ class Slackbuilds(Configs):
|
|||
|
||||
self.stderr = None
|
||||
self.stdout = None
|
||||
self.sbos: dict = {}
|
||||
self.install_order: list = []
|
||||
self.dependencies: list = []
|
||||
self.process_message: str = ''
|
||||
|
@ -84,62 +83,57 @@ class Slackbuilds(Configs):
|
|||
|
||||
def execute(self) -> None:
|
||||
""" Starting build or install the slackbuilds. """
|
||||
self.creating_dictionary()
|
||||
self.creating_dependencies_for_build()
|
||||
self.creating_main_for_build()
|
||||
self.view_before_build()
|
||||
self.creating_dependencies_list()
|
||||
self.remove_duplicate_slackbuilds_from_dependencies()
|
||||
self.add_dependencies_slackbuilds_to_install_list()
|
||||
self.clean_the_main_slackbuilds()
|
||||
self.add_main_packages_to_install_list()
|
||||
self.view_slackbuilds_before_build()
|
||||
|
||||
start: float = time.time()
|
||||
self.prepare_slackbuilds_for_build()
|
||||
self.build_and_install()
|
||||
self.build_and_install_the_slackbuilds()
|
||||
elapsed_time: float = time.time() - start
|
||||
|
||||
self.utils.finished_time(elapsed_time)
|
||||
|
||||
def creating_dictionary(self) -> None:
|
||||
def creating_dependencies_list(self) -> None:
|
||||
""" Dictionary with the main slackbuilds and dependencies. """
|
||||
for sbo in self.slackbuilds:
|
||||
if self.option_for_resolve_off:
|
||||
self.sbos[sbo] = []
|
||||
else:
|
||||
self.sbos[sbo] = Requires(self.data, sbo).resolve()
|
||||
if not self.option_for_resolve_off:
|
||||
for sbo in self.slackbuilds:
|
||||
deps: list = Requires(self.data, sbo).resolve()
|
||||
|
||||
def creating_dependencies_for_build(self) -> None:
|
||||
""" List with the dependencies. """
|
||||
for deps in self.sbos.values():
|
||||
for dep in deps:
|
||||
for dep in deps:
|
||||
# Skip installed package when the option --skip-installed is applied.
|
||||
if self.option_for_skip_installed and self.utils.is_package_installed(dep):
|
||||
continue
|
||||
|
||||
# Skip installed package when the option --skip-installed is applied.
|
||||
if self.option_for_skip_installed and self.utils.is_package_installed(dep):
|
||||
continue
|
||||
self.dependencies.append(dep)
|
||||
|
||||
self.dependencies.append(dep)
|
||||
|
||||
# Remove duplicate packages and keeps the order.
|
||||
dependencies = list(OrderedDict.fromkeys(self.dependencies))
|
||||
|
||||
if dependencies:
|
||||
self.dependencies: list = self.choose_dependencies(dependencies)
|
||||
|
||||
# Clean up the main packages if they were selected for dependencies.
|
||||
for dep in self.dependencies:
|
||||
if dep in self.slackbuilds:
|
||||
self.slackbuilds.remove(dep)
|
||||
def remove_duplicate_slackbuilds_from_dependencies(self):
|
||||
if self.dependencies:
|
||||
# Remove duplicate packages and keeps the order.
|
||||
dependencies = list(OrderedDict.fromkeys(self.dependencies))
|
||||
self.dependencies: list = self.choose_dependencies_for_build_or_install(dependencies)
|
||||
|
||||
def add_dependencies_slackbuilds_to_install_list(self) -> None:
|
||||
self.install_order.extend(self.dependencies)
|
||||
|
||||
def creating_main_for_build(self) -> None:
|
||||
""" List with the main slackbuilds. """
|
||||
[self.install_order.append(main) for main in self.sbos.keys() if main not in self.install_order]
|
||||
def clean_the_main_slackbuilds(self) -> None:
|
||||
""" Clean up the main packages if they were selected for dependencies. """
|
||||
for dep in self.dependencies:
|
||||
if dep in self.slackbuilds:
|
||||
self.slackbuilds.remove(dep)
|
||||
|
||||
def view_before_build(self) -> None:
|
||||
def add_main_packages_to_install_list(self) -> None:
|
||||
self.install_order.extend(self.slackbuilds)
|
||||
|
||||
def view_slackbuilds_before_build(self) -> None:
|
||||
""" View slackbuilds before proceed. """
|
||||
if not self.mode == 'build':
|
||||
self.view_message.install_upgrade_packages(self.slackbuilds, self.dependencies, self.mode)
|
||||
else:
|
||||
if self.mode == 'build':
|
||||
self.view_message.build_packages(self.slackbuilds, self.dependencies)
|
||||
|
||||
del self.dependencies # no more needed
|
||||
else:
|
||||
self.view_message.install_upgrade_packages(self.slackbuilds, self.dependencies, self.mode)
|
||||
|
||||
self.view_message.question()
|
||||
|
||||
|
@ -192,9 +186,9 @@ class Slackbuilds(Configs):
|
|||
down_urls.download()
|
||||
print()
|
||||
|
||||
self.checksum_downloads()
|
||||
self.checksum_downloaded_sources()
|
||||
|
||||
def checksum_downloads(self) -> None:
|
||||
def checksum_downloaded_sources(self) -> None:
|
||||
""" Checking the correct checksums. """
|
||||
for sbo in self.install_order:
|
||||
path = Path(self.build_path, sbo)
|
||||
|
@ -210,34 +204,29 @@ class Slackbuilds(Configs):
|
|||
md5sum = Md5sum(self.flags)
|
||||
md5sum.check(path, source, checksum)
|
||||
|
||||
def build_and_install(self) -> None:
|
||||
def build_and_install_the_slackbuilds(self) -> None:
|
||||
""" Build the slackbuilds and install. """
|
||||
for sbo in self.install_order:
|
||||
|
||||
if self.continue_build_or_install(sbo):
|
||||
|
||||
self.patch_sbo_tag(sbo)
|
||||
|
||||
self.patch_slackbuild_tag(sbo)
|
||||
self.build_the_script(self.build_path, sbo)
|
||||
|
||||
if self.mode in ['install', 'upgrade']:
|
||||
|
||||
pkg: str = self.package_for_install(sbo)
|
||||
self.install_package(pkg)
|
||||
self.install_package(sbo)
|
||||
|
||||
if not self.option_for_resolve_off:
|
||||
self.logs_deps.logging(sbo)
|
||||
else:
|
||||
package: str = self.utils.is_package_installed(sbo)
|
||||
version: str = self.utils.split_binary_pkg(package)[1]
|
||||
self.view_message.view_skipping_packages(sbo, version)
|
||||
installed_package: str = self.utils.is_package_installed(sbo)
|
||||
installed_version: str = self.utils.split_binary_pkg(installed_package)[1]
|
||||
self.view_message.view_skipping_packages(sbo, installed_version)
|
||||
|
||||
def patch_sbo_tag(self, sbo: str) -> None:
|
||||
def patch_slackbuild_tag(self, sbo: str) -> None:
|
||||
""" Patching SBo TAG from the configuration file. """
|
||||
sbo_script: Path = Path(self.build_path, sbo, f'{sbo}.SlackBuild')
|
||||
|
||||
if sbo_script.is_file() and self.repo_tag:
|
||||
|
||||
lines: list = self.utils.read_file(sbo_script)
|
||||
|
||||
with open(sbo_script, 'w') as script:
|
||||
|
@ -246,9 +235,9 @@ class Slackbuilds(Configs):
|
|||
line: str = f'TAG=${{TAG:-{self.repo_tag}}}\n'
|
||||
script.write(line)
|
||||
|
||||
def install_package(self, package: str) -> None:
|
||||
def install_package(self, pkg: str) -> None:
|
||||
""" Install the packages that before created in the tmp directory. """
|
||||
pkg: str = self.utils.split_binary_pkg(package)[0]
|
||||
package: str = self.find_package_for_install(pkg)
|
||||
|
||||
execute: str = self.installpkg
|
||||
if self.option_for_reinstall and self.utils.is_package_installed(pkg):
|
||||
|
@ -258,44 +247,40 @@ class Slackbuilds(Configs):
|
|||
self.process_message: str = f"package '{pkg}' to install"
|
||||
|
||||
if self.mode == 'upgrade':
|
||||
self.process_message: str = f"package '{pkg}' to upgrade"
|
||||
message: str = f'{self.cyan}Upgrade{self.endc}'
|
||||
self.process_message: str = f"package '{pkg}' to upgrade"
|
||||
|
||||
command: str = f'{execute} {self.tmp_path}/{package}'
|
||||
|
||||
self.multi_process(command, package, message)
|
||||
|
||||
def package_for_install(self, name: str) -> str:
|
||||
def find_package_for_install(self, name: str) -> str:
|
||||
""" Returns the package for install. """
|
||||
package: str = ''
|
||||
version: str = self.data[name][2]
|
||||
pattern: str = f'{name}-{version}*{self.repo_tag}*'
|
||||
|
||||
packages: list = [file.name for file in self.tmp_path.glob(pattern)]
|
||||
|
||||
try:
|
||||
package: str = max(packages)
|
||||
return max(packages)
|
||||
except ValueError:
|
||||
logger = logging.getLogger(LoggingConfig.date)
|
||||
logger.exception(f'{self.__class__.__name__}: '
|
||||
f'{self.__class__.package_for_install.__name__}')
|
||||
f'{self.__class__.find_package_for_install.__name__}')
|
||||
self.errors.raise_error_message(f"Package '{name}' not found for install", exit_status=20)
|
||||
|
||||
return package
|
||||
|
||||
def build_the_script(self, path: Path, name: str) -> None:
|
||||
""" Run the .SlackBuild script. """
|
||||
folder: str = f'{Path(path, name)}/'
|
||||
execute: str = f'{folder}./{name}.SlackBuild'
|
||||
|
||||
if self.option_for_jobs:
|
||||
self.set_makeflags()
|
||||
|
||||
# Change to root privileges
|
||||
os.chown(folder, 0, 0)
|
||||
for file in os.listdir(folder):
|
||||
os.chown(f'{folder}{file}', 0, 0)
|
||||
|
||||
if self.option_for_jobs:
|
||||
self.set_makeflags()
|
||||
|
||||
name: str = f'{name}.SlackBuild'
|
||||
message: str = f'{self.red}Build{self.endc}'
|
||||
self.process_message: str = f"package '{name}' to build"
|
||||
|
@ -308,7 +293,6 @@ class Slackbuilds(Configs):
|
|||
os.environ['MAKEFLAGS'] = f'-j {cpu_count()}'
|
||||
|
||||
def multi_process(self, command: str, filename: str, message: str) -> None:
|
||||
""" Starting multiprocessing install/upgrade process. """
|
||||
if self.silent_mode and not self.option_for_no_silent:
|
||||
|
||||
done: str = f' {self.byellow} Done{self.endc}'
|
||||
|
@ -342,8 +326,7 @@ class Slackbuilds(Configs):
|
|||
else:
|
||||
self.utils.process(command, self.stderr, self.stdout)
|
||||
|
||||
def choose_dependencies(self, dependencies: list) -> list:
|
||||
""" Choose packages for install. """
|
||||
def choose_dependencies_for_build_or_install(self, dependencies: list) -> list:
|
||||
height: int = 10
|
||||
width: int = 70
|
||||
list_height: int = 0
|
||||
|
|
Loading…
Reference in a new issue