def edit_partitions_write(self): """ Writes, in memory, the changes made. """ self.header(_("Write to memory")) print(_("Do you want to write to memory your changes?")) print(_("This will let you continue to manage the partitioning scheme.") + "\n") print(_("%(note)s: This will %(not)s write the changes to the disk! It only simulates it. You should write to memory every time you delete and resize partitions. This will let you add new partitions on the freed space.") % {"note":bold(_("NOTE")), "not":bold(_("not"))}) print(_("You can always restore original structure via the appropriate option into the main menu.")) print res = self.question(_("Do you want to write to memory the changes?"), default=False) if res: failed = lib.write_memory(self.changed) if failed != {}: return self.edit_partitions(warning=_("Something has failed: %s!") % str(failed)) else: return self.edit_partitions(information=_("Ok! You can continue."))
def main(self): """ Main prompt. """ self._reload(complete=False) self.header(_("Disk partitioning")) # Check if root and swap are preseeded. if self.settings["root"] and self.settings["swap"] != False: # They are. We can skip this step. ## ROOT # Get an appropriate device object _root_dev = self.disks[lib.return_device(self.settings["root"]).replace("/dev/","")] # Get an appropriate partition object _root_par = _root_dev.getPartitionByPath(self.settings["root"]) self.changed[self.settings["root"]] = {"obj":_root_par, "changes":{"useas":"/"}} ################################################################################### ## SWAP # Get an appropriate device object if not self.settings["swap"]: # Swap disabled self.settings["swap_noformat"] = True # Do not format swap, as it doesn't exist ;) else: # Get an appropriate partition object _swap_dev = self.disks[lib.return_device(self.settings["swap"]).replace("/dev/","")] _swap_par = _swap_dev.getPartitionByPath(self.settings["swap"]) self.changed[self.settings["swap"]] = {"obj":_swap_par, "changes":{"useas":"swap"}} ####################################################################################### # If root_filesystem is populated, we should format root with that filesystem. if self.settings["root_filesystem"]: # Format. Yay. # Set format. self.changed[self.settings["root"]]["changes"]["format"] = self.settings["root_filesystem"] self.changed[self.settings["root"]]["changes"]["format_real"] = self.settings["root_filesystem"] self.touched[lib.return_device(self.settings["root"])] = True if not self.settings["swap_noformat"]: # Format. Yay. # Set format. self.changed[self.settings["swap"]]["changes"]["format"] = "linux-swap(v1)" self.changed[self.settings["swap"]]["changes"]["format_real"] = "linux-swap(v1)" self.touched[lib.return_device(self.settings["swap"])] = True # Write to memory lib.write_memory(self.changed) # Commit. self.commit() verbose("Selected %s as root partition" % self.settings["root"]) if self.settings["swap"]: verbose("Selected %s as swap partition" % self.settings["swap"]) else: verbose("Swap disabled.") # Skip to next module return # If skip_to_selection == True, we need to skip the following block. if self.settings["skip_to_selection"] != True: self.print_devices_partitions() res = self.question(_("Do you want to change the partition table?"), default=False) if res: # We should change partition structure. res = self.edit_partitions() # Restart this module return self.main() else: # Check if root and swap are preseeded. self.partition_selection() else: # Run partition_selction() self.partition_selection() verbose("Selected %s as root partition" % self.settings["root"]) if self.settings["swap"]: verbose("Selected %s as swap partition" % self.settings["swap"]) else: verbose("Swap disabled.") verbose("Other changes: %s" % str(self.changed))
def partition_selection(self, warning=None, information=None): """ If root and swap aren't preseeded, prompts the user for a partition. """ self.header(_("Select distribution specific drives")) if warning: warn(warning + "\n") if information: info(information + "\n") self.print_devices_partitions() if not self.settings["root"]: # No root specified. Prompt for one. choice = self.entry(_("Select your root partition")) # Check if choice is into disk's partition try: _root_dev = self.disks[lib.return_device(choice).replace("/dev/","")] _root_par = _root_dev.getPartitionByPath(choice) if not _root_par: # Wrong disk return self.partition_selection(warning=_("Wrong partition selected!")) except: # Wrong disk return self.partition_selection(warning=_("Wrong partition selected!")) self.changed[choice] = {"obj":_root_par, "changes":{"useas":"/"}} self.settings["root"] = choice if not self.settings["root_filesystem"] and not self.settings["root_noformat"]: # No filesystem for root specified. # Prompt for one. return self.edit_partitions_format(_root_par, self.changed[choice]["changes"], _return="partsel") elif not self.settings["root_noformat"]: self.changed[choice]["changes"]["format"] = self.settings["root_filesystem"] self.changed[choice]["changes"]["format_real"] = self.settings["root_filesystem"] self.touched[lib.return_device(choice)] = True if self.settings["swap"] == False: swaps = lib.swap_available(deep=True) if swaps == []: # No swap available warn(_("No swap partition available. Continuing without.")) self.settings["swap"] = None else: # No swap specified. Prompt for one. choice = self.entry(_("Select your swap partition (press ENTER to not use swap)"), blank=True) if not choice: # Should not use swap. ok... self.settings["swap"] = None warn(_("No swap selected.")) else: # Check if choice is into disk's partition _swap_par = False for part in swaps: if choice == part.path: _swap_par = part if not _swap_par: # No swap :/ return self.partition_selection(warning=_("Wrong partition selected!")) self.changed[choice] = {"obj":_swap_par, "changes":{"useas":"swap"}} self.settings["swap"] = choice if not self.settings["swap_noformat"]: # Prompt for format. # Set format. self.changed[choice]["changes"]["format"] = "linux-swap(v1)" self.changed[choice]["changes"]["format_real"] = "linux-swap(v1)" self.touched[lib.return_device(self.settings["swap"])] = True if self.settings["root_noformat"]: # Do not alarm the user that we are going to format something -- as we will not format anything (if not swap) quest = _("Do you really want to continue?") else: quest = _("Do you really want to continue? This will destroy selected partitions.") res = self.question("\n" + quest, default=False) if res: # Write to memory lib.write_memory(self.changed) # Commit. self.commit() return else: return self.main()