def __call__(self):
with self.tui:
- # Walk through all steps
- for step in self.steps:
- try:
- self._run_step(step)
-
- # End installer if aborted
- except InstallAbortedError:
- return 1
-
- # Catch any failed commands
- except subprocess.CalledProcessError as e:
- args = {
- "command" : " ".join(e.cmd),
- "output" : e.output.decode(),
- "returncode" : e.returncode,
- }
-
- # Log the error
- log.error("Command \"%(command)s\" failed with error code "
- "%(returncode)s:\n%(output)s" % args)
-
- # Format the error message
- error = _("Command \"%(command)s\" failed with error code "
- "%(returncode)s:\n\n%(output)s" % args)
-
- # Show it
- self.tui.error(_("An Unexpected Error Occured"), error,
- buttons=[_("Exit")], width=78)
-
- # Exit
- return e.returncode
-
- # Catch all other exceptions and show an error
- except:
- type, value, tb = sys.exc_info()
-
- # Log the error
- log.error("An unexpected error occured:", exc_info=True)
-
- # Format the exception
- error = _("The installation cannot be continued due to an error:"
- "\n\n%s") % "".join(traceback.format_exception(type, value, tb))
-
- # Show an error message
- self.tui.error(_("An Unexpected Error Occured"),
- "".join(error), buttons=[_("Exit")], width=78)
-
- # Exit
- return 1
+ try:
+ # Walk through all steps
+ for step in self.steps:
+ try:
+ self._run_step(step)
+
+ # End installer if aborted
+ except InstallAbortedError:
+ return 1
+
+ # Catch any failed commands
+ except subprocess.CalledProcessError as e:
+ args = {
+ "command" : " ".join(e.cmd),
+ "output" : e.output.decode(),
+ "returncode" : e.returncode,
+ }
+
+ # Log the error
+ log.error("Command \"%(command)s\" failed with error code "
+ "%(returncode)s:\n%(output)s" % args)
+
+ # Format the error message
+ error = _("Command \"%(command)s\" failed with error code "
+ "%(returncode)s:\n\n%(output)s" % args)
+
+ # Show it
+ self.tui.error(_("An Unexpected Error Occured"), error,
+ buttons=[_("Exit")], width=78)
+
+ # Exit
+ return e.returncode
+
+ # Catch all other exceptions and show an error
+ except:
+ type, value, tb = sys.exc_info()
+
+ # Log the error
+ log.error("An unexpected error occured:", exc_info=True)
+
+ # Format the exception
+ error = _("The installation cannot be continued due to an error:"
+ "\n\n%s") % "".join(traceback.format_exception(type, value, tb))
+
+ # Show an error message
+ self.tui.error(_("An Unexpected Error Occured"),
+ "".join(error), buttons=[_("Exit")], width=78)
+
+ # Exit
+ return 1
+
+ # Cleanup when we leave
+ finally:
+ self.disks.tear_down()
def _run_step(self, stepcls):
"""
# Create one giant root partition
root.create_system_partitions()
+ def tear_down(self):
+ """
+ Shuts down any storage
+ """
+ for disk in self.disks:
+ disk.tear_down()
+
class Disk(object):
def __init__(self, bricklayer, device):
if self.path.startswith("/dev/loop"):
self.bricklayer.command(["kpartx", "-av", self.path])
+ def tear_down(self):
+ """
+ Shuts down this disk
+ """
+ # Unmap partitions on loop devices
+ if self.path.startswith("/dev/loop"):
+ self.bricklayer.command(["kpartx", "-dv", self.path])
+
+ # Free the loop device
+ self.bricklayer.command(["losetup", "-d", self.path])
+
class Partition(object):
def __init__(self, bricklayer, parted):