[libvirt] [jenkins-ci PATCH v4 3/5] lcitool: avoid intermediate list of packages

Daniel P. Berrangé posted 5 patches 6 years, 11 months ago
There is a newer version of this series
[libvirt] [jenkins-ci PATCH v4 3/5] lcitool: avoid intermediate list of packages
Posted by Daniel P. Berrangé 6 years, 11 months ago
We can purge any packages which expand to None straight away, and
simply convert to a set to get rid of duplicates.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 guests/lcitool | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index 5c2b785..2af6878 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -548,8 +548,7 @@ class Application:
                     )
                 )
 
-        temp = {}
-
+        pkgs = {}
         keys = ["default", package_format, os_name, os_full]
         # We need to add the base project manually here: the standard
         # machinery hides it because it's an implementation detail
@@ -557,21 +556,15 @@ class Application:
             for package in self._projects.get_packages(project):
                 for key in keys:
                     if key in mappings[package]:
-                        temp[package] = mappings[package][key]
+                        pkgs[package] = mappings[package][key]
 
-        pkgs = []
-        for item in temp:
-            pkgname = temp[item]
-            if pkgname is None:
-                continue
-            if pkgname in pkgs:
-                continue
-            pkgs.append(pkgname)
+                if pkgs[package] is None:
+                    del pkgs[package]
 
         print("FROM {}".format(facts["docker_base"]))
 
         varmap = {}
-        varmap["pkgs"] = " \\\n            ".join(sorted(pkgs))
+        varmap["pkgs"] = " \\\n            ".join(sorted(set(pkgs.values())))
         if package_format == "deb":
             sys.stdout.write(textwrap.dedent("""
                 RUN export DEBIAN_FRONTEND=noninteractive && \\
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [jenkins-ci PATCH v4 3/5] lcitool: avoid intermediate list of packages
Posted by Andrea Bolognani 6 years, 11 months ago
On Thu, 2019-02-21 at 16:33 +0000, Daniel P. Berrangé wrote:
> We can purge any packages which expand to None straight away, and
> simply convert to a set to get rid of duplicates.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  guests/lcitool | 17 +++++------------
>  1 file changed, 5 insertions(+), 12 deletions(-)

This doesn't work:

  $ ./lcitool dockerfile libvirt-centos-7 libvirt
  Traceback (most recent call last):
    File "./lcitool", line 601, in <module>
      Application().run()
    File "./lcitool", line 596, in run
      args.func(args)
    File "./lcitool", line 560, in _action_dockerfile
      if pkgs[package] is None:
  KeyError: 'apparmor'

That's because...

> @@ -557,21 +556,15 @@ class Application:
>              for package in self._projects.get_packages(project):
>                  for key in keys:
>                      if key in mappings[package]:
> -                        temp[package] = mappings[package][key]
> +                        pkgs[package] = mappings[package][key]

... the hunk

  if package not in pkgs:
      continue

from the following patch should have been included right about here.

It would be nice if the Ansible part would be converted to a similar
logic, which should be possible using the appropriate Jinja2 filters,
but that can wait until later.

If you include the hunk mentioned above,

  Reviewed-by: Andrea Bolognani <abologna@redhat.com>

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list