Add a new line the end of the acpid action script
[snf-image-creator] / image_creator / os_type / __init__.py
index 260cb08..b9fd4e0 100644 (file)
@@ -1,6 +1,38 @@
-#!/usr/bin/env python
+# Copyright 2012 GRNET S.A. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or
+# without modification, are permitted provided that the following
+# conditions are met:
+#
+#   1. Redistributions of source code must retain the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer.
+#
+#   2. Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# The views and conclusions contained in the software and
+# documentation are those of the authors and should not be
+# interpreted as representing official policies, either expressed
+# or implied, of GRNET S.A.
 
 import re
+from clint.textui import indent, puts
 
 
 def add_prefix(target):
@@ -69,16 +101,45 @@ class OSBase(object):
                 action(full_path)
 
     def get_metadata(self):
-        """Returnes some descriptive metadata of the OS."""
+        """Returns some descriptive metadata about the OS."""
         meta = {}
-        meta["OSFAMILY"] = self.g.inspect_get_type(self.root)
-        meta["OS"] = self.g.inspect_get_distro(self.root)
-        meta["description"] = self.g.inspect_get_product_name(self.root)
+        meta['ROOT_PARTITION'] = "%d" % self.g.part_to_partnum(self.root)
+        meta['OSFAMILY'] = self.g.inspect_get_type(self.root)
+        meta['OS'] = self.g.inspect_get_distro(self.root)
+        meta['DESCRIPTION'] = self.g.inspect_get_product_name(self.root)
 
         return meta
 
     def data_cleanup(self):
-        """Cleanup sesitive data out of the OS image."""
-        raise NotImplementedError
+        """Cleanup sensitive data out of the OS image."""
+
+        puts('Cleaning up sensitive data out of the OS image:')
+
+        is_cleanup = lambda x: x.startswith('data_cleanup_') and \
+                                                    callable(getattr(self, x))
+        tasks = [getattr(self, x) for x in dir(self) if is_cleanup(x)]
+        size = len(tasks)
+        cnt = 0
+        for task in tasks:
+            cnt += 1
+            puts(('(%d/%d)' % (cnt, size)).ljust(7), False)
+            task()
+        puts()
+
+    def sysprep(self):
+        """Prepere system for image creation."""
+
+        puts('Preparing system for image creation:')
+
+        is_sysprep = lambda x: x.startswith('sysprep_') and \
+                                                    callable(getattr(self, x))
+        tasks = [getattr(self, x) for x in dir(self) if is_sysprep(x)]
+        size = len(tasks)
+        cnt = 0
+        for task in tasks:
+            cnt += 1
+            puts(('(%d/%d)' % (cnt, size)).ljust(7), False)
+            task()
+        puts()
 
 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :