Update image properties help page
[snf-image-creator] / image_creator / os_type / __init__.py
index e1481d1..c0fa505 100644 (file)
@@ -41,12 +41,12 @@ def os_cls(distro, osfamily):
     module = None
     classname = None
     try:
-        module = __import__("image_creator.os_type.%s"
-            % distro, fromlist=['image_creator.os_type'])
+        module = __import__("image_creator.os_type.%s" % distro,
+                            fromlist=['image_creator.os_type'])
         classname = distro.capitalize()
     except ImportError:
-        module = __import__("image_creator.os_type.%s"
-            % osfamily, fromlist=['image_creator.os_type'])
+        module = __import__("image_creator.os_type.%s" % osfamily,
+                            fromlist=['image_creator.os_type'])
         classname = osfamily.capitalize()
 
     return getattr(module, classname)
@@ -87,15 +87,20 @@ class OSBase(object):
 
     def list_syspreps(self):
 
-        objs = [getattr(self, name) for name in dir(self) \
-            if not name.startswith('_')]
+        objs = [getattr(self, name) for name in dir(self)
+                if not name.startswith('_')]
 
         return [x for x in objs if self._is_sysprep(x)]
 
-    def _sysprep_change_status(self, name, status):
+    def sysprep_info(self, obj):
+        assert self._is_sysprep(obj), "Object is not a sysprep"
 
+        return (obj.__name__.replace('_', '-'), textwrap.dedent(obj.__doc__))
+
+    def get_sysprep_by_name(self, name):
+        """Returns the sysprep object with the given name"""
         error_msg = "Syprep operation %s does not exist for %s" % \
-                (name, self.__class__.__name__)
+                    (name, self.__class__.__name__)
 
         method_name = name.replace('-', '_')
         method = None
@@ -107,18 +112,18 @@ class OSBase(object):
         if not self._is_sysprep(method):
             raise FatalError(error_msg)
 
-        setattr(method.im_func, 'enabled', status)
+        return method
 
-    def enable_sysprep(self, name):
-        """Enable a system preperation operation"""
-        self._sysprep_change_status(name, True)
+    def enable_sysprep(self, obj):
+        """Enable a system preparation operation"""
+        setattr(obj.im_func, 'enabled', True)
 
-    def disable_sysprep(self, name):
-        """Disable a system preperation operation"""
-        self._sysprep_change_status(name, False)
+    def disable_sysprep(self, obj):
+        """Disable a system preparation operation"""
+        setattr(obj.im_func, 'enabled', False)
 
     def print_syspreps(self):
-        """Print enabled and disabled system preperation operations."""
+        """Print enabled and disabled system preparation operations."""
 
         syspreps = self.list_syspreps()
         enabled = filter(lambda x: x.enabled, syspreps)
@@ -129,7 +134,7 @@ class OSBase(object):
         wrapper.initial_indent = '\t'
         wrapper.width = 72
 
-        self.out.output("Enabled system preperation operations:")
+        self.out.output("Enabled system preparation operations:")
         if len(enabled) == 0:
             self.out.output("(none)")
         else:
@@ -138,7 +143,7 @@ class OSBase(object):
                 descr = wrapper.fill(textwrap.dedent(sysprep.__doc__))
                 self.out.output('    %s:\n%s\n' % (name, descr))
 
-        self.out.output("Disabled system preperation operations:")
+        self.out.output("Disabled system preparation operations:")
         if len(disabled) == 0:
             self.out.output("(none)")
         else:
@@ -204,10 +209,12 @@ class OSBase(object):
 
         self.out.output('Preparing system for image creation:')
 
-        tasks, _ = self.list_syspreps()
-        size = len(tasks)
+        tasks = self.list_syspreps()
+        enabled = filter(lambda x: x.enabled, tasks)
+
+        size = len(enabled)
         cnt = 0
-        for task in tasks:
+        for task in enabled:
             cnt += 1
             self.out.output(('(%d/%d)' % (cnt, size)).ljust(7), False)
             task()