]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Change System to be a singleton pattern class and connect it to the hypervisor class.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 26 Nov 2010 12:45:17 +0000 (13:45 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 26 Nov 2010 12:45:17 +0000 (13:45 +0100)
fireinfo/hypervisor.py
fireinfo/system.py

index dc0d373598ca2d36bee3269c5eb5801932948f3b..4b8f873da942234371acefb880387c4c6e40172a 100644 (file)
@@ -1,11 +1,22 @@
 #!/usr/bin/python
 
 import _fireinfo
+import system
 
 class Hypervisor(object):
        def __init__(self):
                self.__info = _fireinfo.get_hypervisor()
 
+       @property
+       def system(self):
+               """
+                       Return the current instance of the System class.
+
+                       We need to do that as a property because otherwise
+                       we get a recursion.
+               """
+               return system.System()
+
        @property
        def vendor(self):
                """
index 50eddfead9723d2cad3a39f6079f4fd74411f2fd..43807c3f0b7554460999e0557155ca8f651bb2dd 100644 (file)
@@ -9,7 +9,20 @@ import cpu
 import device
 import hypervisor
 
+class Singleton(type):
+       def __init__(cls, name, bases, dict):
+               super(Singleton, cls).__init__(name, bases, dict)
+               cls.instance = None
+
+       def __call__(cls, *args, **kw):
+               if cls.instance is None:
+                       cls.instance = super(Singleton, cls).__call__(*args, **kw)
+
+               return cls.instance
+
+
 class System(object):
+       __metaclass__ = Singleton
 
        def __init__(self):
                # find all devices