+ def do_sysprep(self):
+ """Prepare system for image creation."""
+
+ try:
+ if not self.mount(readonly=False):
+ raise FatalError("Unable to mount the media read-write")
+
+ self.out.output('Preparing system for image creation:')
+
+ tasks = self.list_syspreps()
+ enabled = filter(lambda x: x.enabled, tasks)
+
+ size = len(enabled)
+ cnt = 0
+ for task in enabled:
+ cnt += 1
+ self.out.output(('(%d/%d)' % (cnt, size)).ljust(7), False)
+ task()
+ setattr(task.im_func, 'executed', True)
+ finally:
+ self.umount()
+
+ self.out.output()
+
+ def mount(self, readonly=False):
+ """Mount image."""
+
+ if getattr(self, "mounted", False):
+ return True
+
+ mount_type = 'read-only' if readonly else 'read-write'
+ self.out.output("Mounting the media %s ..." % mount_type, False)
+
+ if not self._do_mount(readonly):
+ return False
+
+ self.mounted = True
+ self.out.success('done')
+ return True
+
+ def umount(self):
+ """Umount all mounted filesystems."""
+
+ self.out.output("Umounting the media ...", False)
+ self.g.umount_all()
+ self.mounted = False
+ self.out.success('done')
+
+ def _is_sysprep(self, obj):
+ """Checks if an object is a sysprep"""
+ return getattr(obj, 'sysprep', False) and callable(obj)
+