So we just instantiate it in case it's needed. Helps to
keep the default log messages of an autotest client run
with less output.

Signed-off-by: Lucas Meneghel Rodrigues <l...@redhat.com>
---
 client/shared/software_manager.py |   32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/client/shared/software_manager.py 
b/client/shared/software_manager.py
index 6ec2dd9..7e6072e 100755
--- a/client/shared/software_manager.py
+++ b/client/shared/software_manager.py
@@ -111,25 +111,31 @@ class SoftwareManager(object):
     """
     def __init__(self):
         """
-        Class constructor.
+        Lazily instantiate the object
+        """
+        self.initialized = False
 
+    def _init_on_demand(self):
+        """
         Determines the best supported package management system for the given
         operating system running and initializes the appropriate backend.
         """
-        inspector = SystemInspector()
-        backend_type = inspector.get_package_management()
-        if backend_type == 'yum':
-            self.backend = YumBackend()
-        elif backend_type == 'zypper':
-            self.backend = ZypperBackend()
-        elif backend_type == 'apt-get':
-            self.backend = AptBackend()
-        else:
-            raise NotImplementedError('Unimplemented package management '
-                                      'system: %s.' % backend_type)
-
+        if not self.initialized:
+            inspector = SystemInspector()
+            backend_type = inspector.get_package_management()
+            if backend_type == 'yum':
+                self.backend = YumBackend()
+            elif backend_type == 'zypper':
+                self.backend = ZypperBackend()
+            elif backend_type == 'apt-get':
+                self.backend = AptBackend()
+            else:
+                raise NotImplementedError('Unimplemented package management '
+                                          'system: %s.' % backend_type)
+            self.initialized = True
 
     def __getattr__(self, name):
+        self._init_on_demand()
         return self.backend.__getattribute__(name)
 
 
-- 
1.7.10.4

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to