[virt-tools-list] [virt-manager PATCH 1/3] inspection: create and use a separate vmmInspectionApplication

Pino Toscano ptoscano at redhat.com
Thu Apr 18 14:08:30 UTC 2019


Instead of passing around the raw results of
g.inspect_list_applications(), create an helper vmmInspectionApplication
object with the data of an inspected application that we use.  This is
done for different reasons:
- when using the data, it is easier to use member variables instead of
  looking up values in a dictionary
- we keep only the data needed, slightly lowering the memory/objects
  used for the inspected applications
- it will be easier to switch from g.inspect_list_applications() to
  g.inspect_list_applications2() without changing code outside the
  inspection code
---
 virtManager/details.py    | 28 ++++++++++++++--------------
 virtManager/domain.py     | 11 +++++++++++
 virtManager/inspection.py | 23 +++++++++++++++++++++--
 3 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/virtManager/details.py b/virtManager/details.py
index 1b0d5d02..381e2594 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -2528,22 +2528,22 @@ class vmmDetails(vmmGObjectUI):
         apps_model.clear()
         for app in apps:
             name = ""
-            if app["app_name"]:
-                name = app["app_name"]
-            if app["app_display_name"]:
-                name = app["app_display_name"]
+            if app.name:
+                name = app.name
+            if app.display_name:
+                name = app.display_name
             version = ""
-            if app["app_epoch"] > 0:
-                version += str(app["app_epoch"]) + ":"
-            if app["app_version"]:
-                version += app["app_version"]
-            if app["app_release"]:
-                version += "-" + app["app_release"]
+            if app.epoch > 0:
+                version += str(app.epoch) + ":"
+            if app.version:
+                version += app.version
+            if app.release:
+                version += "-" + app.release
             summary = ""
-            if app["app_summary"]:
-                summary = app["app_summary"]
-            elif app["app_description"]:
-                summary = app["app_description"]
+            if app.summary:
+                summary = app.summary
+            elif app.description:
+                summary = app.description
                 pos = summary.find("\n")
                 if pos > -1:
                     summary = _("%(summary)s ...") % {
diff --git a/virtManager/domain.py b/virtManager/domain.py
index cb15b77f..54447a15 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -67,6 +67,17 @@ def start_job_progress_thread(vm, meter, progtext):
         t.start()
 
 
+class vmmInspectionApplication(object):
+    def __init__(self):
+        self.name = None
+        self.display_name = None
+        self.epoch = None
+        self.version = None
+        self.release = None
+        self.summary = None
+        self.description = None
+
+
 class vmmInspectionData(object):
     def __init__(self):
         self.os_type = None
diff --git a/virtManager/inspection.py b/virtManager/inspection.py
index 4b183b5b..a682dea9 100644
--- a/virtManager/inspection.py
+++ b/virtManager/inspection.py
@@ -9,7 +9,7 @@ import threading
 
 from .baseclass import vmmGObject
 from .connmanager import vmmConnectionManager
-from .domain import vmmInspectionData
+from .domain import vmmInspectionApplication, vmmInspectionData
 
 
 def _inspection_error(_errstr):
@@ -264,7 +264,26 @@ class vmmInspection(vmmGObject):
 
             # Inspection applications.
             try:
-                apps = g.inspect_list_applications(root)
+                gapps = g.inspect_list_applications(root)
+                # applications listing worked, so make apps a real list
+                # (instead of None)
+                apps = []
+                for gapp in gapps:
+                    app = vmmInspectionApplication()
+                    if gapp["app_name"]:
+                        app.name = gapp["app_name"]
+                    if gapp["app_display_name"]:
+                        app.display_name = gapp["app_display_name"]
+                    app.epoch = gapp["app_epoch"]
+                    if gapp["app_version"]:
+                        app.version = gapp["app_version"]
+                    if gapp["app_release"]:
+                        app.release = gapp["app_release"]
+                    if gapp["app_summary"]:
+                        app.summary = gapp["app_summary"]
+                    if gapp["app_description"]:
+                        app.description = gapp["app_description"]
+                    apps.append(app)
             except Exception:
                 logging.exception("%s: exception while listing apps (ignored)",
                                   prettyvm)
-- 
2.20.1




More information about the virt-tools-list mailing list