+ def print_sysprep_params(self):
+ """Print the system preparation parameter the user may use"""
+
+ self.out.output("Needed system preparation parameters:")
+
+ if len(self.needed_sysprep_params) == 0:
+ self.out.output("(none)")
+ return
+
+ for name, param in self.needed_sysprep_params.items():
+ self.out.output("\t%s (%s): %s" %
+ (param.description, name,
+ self.sysprep_params[name] if name in
+ self.sysprep_params else "(none)"))
+
+ def do_sysprep(self):
+ """Prepare system for image creation."""
+
+ self.out.output('Preparing system for image creation:')
+
+ if self.image.is_unsupported():
+ self.out.warn(
+ "System preparation is disabled for unsupported media")
+ return
+
+ try:
+ if not self.mount(readonly=False):
+ raise FatalError("Unable to mount the media read-write")
+
+ enabled = [task for task in self.list_syspreps() if task.enabled]
+
+ 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.image.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)
+