Monitor executed syspreps in os_type/__init__.py
[snf-image-creator] / image_creator / os_type / __init__.py
index c0fa505..cea08a3 100644 (file)
@@ -38,6 +38,7 @@ import re
 
 
 def os_cls(distro, osfamily):
+    """Given the distro name and the osfamily, return the appropriate class"""
     module = None
     classname = None
     try:
@@ -60,9 +61,11 @@ def add_prefix(target):
 
 
 def sysprep(enabled=True):
+    """Decorator for system preparation tasks"""
     def wrapper(func):
         func.sysprep = True
         func.enabled = enabled
+        func.executed = False
         return func
     return wrapper
 
@@ -80,6 +83,8 @@ class OSBase(object):
         self.meta['ROOT_PARTITION'] = "%d" % self.g.part_to_partnum(self.root)
         self.meta['OSFAMILY'] = self.g.inspect_get_type(self.root)
         self.meta['OS'] = self.g.inspect_get_distro(self.root)
+        if self.meta['OS'] == "unknown":
+            self.meta['OS'] = self.meta['OSFAMILY']
         self.meta['DESCRIPTION'] = self.g.inspect_get_product_name(self.root)
 
     def _is_sysprep(self, obj):
@@ -90,7 +95,7 @@ class OSBase(object):
         objs = [getattr(self, name) for name in dir(self)
                 if not name.startswith('_')]
 
-        return [x for x in objs if self._is_sysprep(x)]
+        return [x for x in objs if self._is_sysprep(x) and x.executed is False]
 
     def sysprep_info(self, obj):
         assert self._is_sysprep(obj), "Object is not a sysprep"
@@ -218,6 +223,7 @@ class OSBase(object):
             cnt += 1
             self.out.output(('(%d/%d)' % (cnt, size)).ljust(7), False)
             task()
+            setattr(task.im_func, 'executed', True)
         self.out.output()
 
 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :