+ 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)
+ self.out.output()
+ finally:
+ self.umount()
+
+ def _do_mount(self, readonly):
+ try:
+ self.g.mount_options('ro' if readonly else 'rw', self.root, '/')
+ except RuntimeError as msg:
+ self.out.warn("unable to mount the root partition: %s" % msg)
+ return False
+
+ return True
+
+ 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("Mount the media %s ..." % mount_type, False)
+
+ if not self._do_mount(readonly):
+ return False