We can purge any packages which expand to None straight away, and
simply convert to a set to get rid of duplicates.

Reviewed-by: Andrea Bolognani <abolo...@redhat.com>
Signed-off-by: Daniel P. Berrangé <berra...@redhat.com>
---
 guests/lcitool | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index 46af92b..88bc945 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -539,8 +539,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
@@ -548,21 +547,17 @@ 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 package not in pkgs:
+                    continue
+                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

Reply via email to