From: Michael Tremer Date: Thu, 9 Dec 2021 13:29:10 +0000 (+0000) Subject: packages: Use Pakfire callbacks to show progress X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=355feda66b2f41b009873e01eed97b10227a0d01;p=people%2Fms%2Fbricklayer.git packages: Use Pakfire callbacks to show progress Signed-off-by: Michael Tremer --- diff --git a/src/python/__init__.py b/src/python/__init__.py index 7a7e32d..96658ee 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -237,12 +237,12 @@ class Bricklayer(object): return output - def setup_pakfire(self): + def setup_pakfire(self, **kwargs): """ Calls Pakfire and has it load its configuration """ return pakfire.Pakfire(self.root, arch=self.arch, - conf="/etc/pakfire/distros/ipfire3.conf") + conf="/etc/pakfire/distros/ipfire3.conf", **kwargs) def _select_bootloaders(self): """ diff --git a/src/python/step.py b/src/python/step.py index ed0ecc4..7612f32 100644 --- a/src/python/step.py +++ b/src/python/step.py @@ -70,54 +70,41 @@ class Step(object): # Set up Pakfire with self.tui.progress( - _("Setting Up Pakfire"), - _("Pakfire is being set up..."), - ): - p = self.bricklayer.setup_pakfire() - - with p as p: - # Resolve package dependencies - with self.tui.progress( - _("Resolving Dependencies"), - _("Resolving package dependencies..."), - ): - try: - transaction = p.install(packages) - - # Abort on any dependencies problems - except pakfire.errors.DependencyError as e: - problems = e.args[0] - - # Format problem descriptions - text = [] - for problem in problems: - lines = [ - "* %s" % problem - ] - for solution in problem.solutions: - lines.append(" --> %s" % solution) - - text.append("\n".join(lines)) - - self.tui.error( - _("Dependency Problem"), - _( - "A problem has occured during resolving package dependencies:\n\n%s", - "Problems have occured during resolving package dependencies:\n\n%s", - len(problems), - ) % "\n\n".join(text), - width=78, - ) - - # Log the transaction - log.info("%s" % transaction.dump()) - - # Run the transaction - with self.tui.progress( - _("Installing Packages"), - _("Installing packages..."), - ): - transaction.run() + _("Installing Packages"), + _("Installing packages..."), + max_value=100, + ) as t: + # Create a new Pakfire instance + p = self.bricklayer.setup_pakfire(**t.callbacks) + + try: + # Install packages + p.install(packages) + + # Abort on any dependencies problems + except pakfire.errors.DependencyError as e: + problems = e.args[0] + + # Format problem descriptions + text = [] + for problem in problems: + lines = [ + "* %s" % problem + ] + for solution in problem.solutions: + lines.append(" --> %s" % solution) + + text.append("\n".join(lines)) + + self.tui.error( + _("Dependency Problem"), + _( + "A problem has occured during resolving package dependencies:\n\n%s", + "Problems have occured during resolving package dependencies:\n\n%s", + len(problems), + ) % "\n\n".join(text), + width=78, + ) class InteractiveStep(Step):