def check(self): """ Checks for updates. """ pkgs = self.moduleclass.settings["packages"].split(" ") atleastone = False for pkg in pkgs: try: if self.cac[pkg].is_upgradable: info(_("Found version %(version)s of %(package)s.") % {"package":pkg, "version":self.cac[pkg].candidate.version}) verbose("Marking %s to be upgrated." % pkg) self.cac[pkg].mark_upgrade() atleastone = True except KeyError: verbose("Unable to find %s; skipping." % pkg) if not atleastone: return False return True
def start(self): """ Start the frontend """ verbose("packages are: %s" % self.settings["packages"]) self.header(_("Installer Updates")) print(_("%(distroname)s's installer improves every day.") % {"distroname":self.moduleclass.main_settings["distro"]}) print(_("It is good measure to have the latest version before installing the distribution.") + "\n") result = self.question(_("Would you like to check for installer updates?"), default=True) if result: # Do checking. info(_("Updating APT cache...")) self.moduleclass.install.update() verbose("Opening the refreshed APT cache...") self.moduleclass.install.open() verbose("Checking if the packages have been updated...") res = self.moduleclass.install.check() if not res: info(_("No updates found.")) return info(_("Upgrading packages... this may take a while.")) try: self.moduleclass.install.upgrade() except: print warn(_("Something went wrong while updating packages.")) info(_("A reboot is recommended in order to start a safe linstaller version.\n")) result = self.question(_("Would you like to reboot now?"), default=True) if result: return "kthxbye" else: return # Everything should be cool now. self.header(_("Installer updated")) print(_("The installer packages have been updated successfully.") + "\n") result = self.entry(_("Press ENTER to start the updated installer"), blank=True) return "fullrestart"
def on_next(self): """ Override for the on_next function. """ status = self.cbox.get_active() # Get status. if status: # Do checking info(_("Updating APT cache...")) self.moduleclass.install.update() verbose("Opening the refreshed APT cache...") self.moduleclass.install.open() verbose("Checking if the packages have been updated...") res = self.moduleclass.install.check() if not res: info(_("No updates found.")) return info("Upgrading packages... this may take a while.") try: self.moduleclass.install.upgrade() except: print warn("Something went wrong while updating packages.") info("A reboot is recommended in order to start a safe linstaller version.\n") result = self.question("Would you like to reboot now?", default=True) if result: return "kthxbye" else: return # Everything should be cool now. self.window.set_header("ok", _("Installer updated"), _("Everything went well")) print(_("The installer packages have been updated successfully.") + "\n") result = self.entry(_("Press ENTER to start the updated installer"), blank=True) return "fullrestart"
def on_frontend_change(self): info("Frontend changed to %s" % self.current_frontend)
def on_module_change(self): info("Module changed to %s" % self.current_module)
def ready(self): info("Sample service called!")
def automatic(self, warning=False, information=False, jumpto=False, by="freespace"): """ Automatic partitioner. That's cool, babe! """ self.header(_("Automatic partitioner")) if warning: warn(warning + "\n") if information: info(information + "\n") # *RELOAD* original structure self._reload() if not jumpto: print(_("Available disks:")) res, choices = self.print_devices_partitions(interactive=True, only_disks=True, skip_notable=True) try: res = int(res) except ValueError: return self.edit_partitions(warning=_("You didn't entered a valid number.")) if not res in choices: # Number doesn't is in choices. return self.edit_partitions(warning=_("You didn't entered a valid number.")) obj = choices[res] if obj == "back": return self.edit_partitions() # Go back. self.header(_("Automatic partitioner") + " - %s" % obj.device.path) actions = {} actions[0] = (_("Use the free space"), "freespace") actions[1] = (_("Delete another system"), "delete") actions[2] = (_("Delete all partitions"), "deleteall") actions[3] = (_("Back"), "back") # Print actions for num, act in actions.iteritems(): print(" %d) %s") % (num, act[0]) print result = self.entry(_("Please insert your action here")) try: result = int(result) except: return self.edit_partitions(warning=_("You haven't entered a valid action.")) if not result in actions: return self.edit_partitions(warning=_("You haven't entered a valid action.")) by = actions[result][1] if by == "back": return self.edit_partitions() # Go back. if jumpto: obj = jumpto # We can continue. if by == "freespace": part, swap, swapcreated = lib.automatic_check(obj, by=by) if part == None: return self.automatic(information=_("Too little free space")) elif part == False: # Failed. return self.automatic(warning=_("Failed to add partition (AUTOMATIC)")) else: # Yey! self.header(_("Automatic partitioner choices")) if swap: # Get swap size. if int(swap.getSize("GB")) == 0: # GB is too big, use MB instead. _swap_unit = "MB" _swap_size = round(swap.getSize("MB")) else: # We can use GB. _swap_unit = "GB" _swap_size = round(swap.getSize("GB")) # Set-up touched... self.touched[part.path] = True if swap: self.touched[swap.path] = True print(" / - %s (%s - %s GB)" % (part.path, part.fileSystem.type, round(part.getSize("GB"), 2))) if swap: print(" swap - %s (%s %s)" % (swap.path, _swap_size, _swap_unit)) elif by == "delete": delete, swap = lib.automatic_check(obj, by=by) swapcreated = False print delete if not delete: # No distribution to delete. return self.automatic(warning=_("No distribution to delete!")) else: # Yey! self.header(_("Automatic partitioner choices")) if swap: # Get swap size. if int(swap.getSize("GB")) == 0: # GB is too big, use MB instead. _swap_unit = "MB" _swap_size = round(swap.getSize("MB")) else: # We can use GB. _swap_unit = "GB" _swap_size = round(swap.getSize("GB")) actions = {} num = 0 for part, distrib in delete: actions[num] = part print(" %s) (%s) / - %s (%s - %s GB)" % (num, bold(distrib), part.path, part.fileSystem.type, round(part.getSize("GB"), 2))) num += 1 print print(" %s) " % num + _("<- Back")) actions[num] = "back" print if swap: print(_("Whatever will be the selection, this swap partition will be used:") + "\n") print(" swap - %s (%s %s)" % (swap.path, _swap_size, _swap_unit)) print else: # Swap will be created - hopefully - by freespace. print(_("A swap partition, if all conditions are meet, will be created.")) print # Select action result = self.entry(_("Please insert your value here")) try: result = int(result) except: return self.automatic(warning=_("You didn't entered a valid value.")) if not result in actions: return self.automatic(warning=_("You didn't entered a valid value.")) if actions[result] == "back": # Go back. return self.automatic() # If we can continue, delete partition!! lib.delete_partition(actions[result]) # Now there is freespace ;-) # So use "freespace". return self.automatic(jumpto=obj, by="freespace") elif by == "deleteall": # The simplest ever! lib.delete_all(obj) # Now there is freespace ;-) # So use "freespace". return self.automatic(jumpto=obj, by="freespace") print res = self.question(_("Are you happy with this? Enter 'y' to write changes in memory"), default=True) # Cache part in self.changed if not part.path in self.changed: self.changed[part.path] = {"obj":part, "changes":{}} # Cache swap in self.changed if swap: if not swap.path in self.changed: self.changed[swap.path] = {"obj":swap, "changes":{}} if res: # Add useas. self.changed[part.path]["changes"] = {"useas":"/", "format_real":"ext4"} if swap: self.changed[swap.path]["changes"] = {"useas":"swap", "format_real":"linux-swap(v1)"} elif by == "freespace" and not jumpto: # We should deleted created partitions lib.delete_partition(part) if swapcreated: lib.delete_partition(swap) # We should delete swap if it was created. else: # We cannot undo, restore old structure self._reload() # Remove useas flags self.changed[part.path]["changes"] = {} if swap: self.changed[swap.path]["changes"] = {} return self.edit_partitions(information=_("Successfully added partitions."))
def edit_partitions(self, warning=None, information=None, device=False, device_changes=False): """ Partition editor. """ self.header(_("Edit Partition structure")) if warning: warn(warning + "\n") if information: info(information + "\n") res, choices = self.print_devices_partitions(interactive=True) try: res = int(res) except ValueError: return self.edit_partitions(warning=_("You didn't entered a valid number.")) if not res in choices: # Number doesn't is in choices. return self.edit_partitions(warning=_("You didn't entered a valid number.")) # We can continue. obj = choices[res] if obj == "back": return self.back() # We should go back. if obj == "write": return self.edit_partitions_write() # We should write to disk. if obj == "automatic": return self.automatic() # Automatic partitioning. if obj == "reload": return self._reload(interactive=True) # Reload. if obj == "commit": return self.commit(interactive=True) # Commit. self.header(_("Editing disk/partition")) print(_("You've selected:") + "\n") if type(obj) == lib.p.partition.Partition: if obj.fileSystem == None and not obj.number == -1 and not obj.type == 2: # If filesystem == None, skip. _fs = _("not formatted") elif obj.number == -1: _fs = _("free space") elif obj.type == 2: # Extended objition _fs = _("extended") else: _fs = obj.fileSystem.type if obj.name: _name = obj.name else: _name = "Untitled" if obj.path in self.distribs: # This partition contains a distribution! _moarspace = "%s: " % self.distribs[obj.path] else: _moarspace = "" if int(obj.getSize("GB")) > 0: # We can use GigaBytes to represent partition size. _size = round(obj.getSize("GB"), 2) _unit = "GB" elif int(obj.getSize("MB")) > 0: # Partition is too small to be represented with gigabytes. Use megabytes instead. _size = round(obj.getSize("MB"), 2) _unit = "MB" else: # Last try.. using kilobytes _size = round(obj.getSize("kB"), 2) _unit = "kB" print(bold(" %s%s (%s) - %s (%s %s)\n" % (_moarspace, _name, obj.path, _fs, _size, _unit))) actions = {} # Populate actions if obj.number == -1: actions[1] = (_("Add partition"), self.edit_partitions_add) num = 1 else: actions[1] = (_("Format partition"), self.edit_partitions_format) actions[2] = (_("Delete partition"), self.edit_partitions_delete) actions[3] = (_("Resize partition"), self.edit_partitions_resize) actions[4] = (_("Use as..."), self.edit_partitions_useas) actions[5] = (_("Unmark changes"), self.edit_partitions_unmark) num = 5 actions[num + 1] = (_("<- Back"), self.edit_partitions) elif type(obj) == lib.p.disk.Disk: # A disk. device = obj.device print(" %s - %s (%s GB)\n" % (device.path, device.model, round(device.getSize(unit="GB"), 2))) actions = {} # Populate actions actions[1] = (_("Delete all partitions on the disk"), self.edit_partitions_deleteall) actions[2] = (_("Unmark changes"), self.edit_partitions_unmark) actions[3] = (_("<- Back"), self.edit_partitions) else: # A device. device = obj print(" %s - %s (%s GB)\n" % (device.path, device.model, round(device.getSize(unit="GB"), 2))) actions = {} # Populate actions actions[1] = (_("Create MBR partition table"), self.edit_partitions_newmbr) actions[2] = (_("Create GPT partition table"), self.edit_partitions_newgpt) actions[3] = (_("<- Back"), self.edit_partitions) # Print actions for num, act in actions.iteritems(): print(" %d) %s") % (num, act[0]) print result = self.entry(_("Please insert your action here")) try: result = int(result) except: return self.edit_partitions(warning=_("You didn't entered a valid action.")) if not result in actions: return self.edit_partitions(warning=_("You didn't entered a valid action.")) # Generate a new device_changes, if any if type(obj) == lib.p.disk.Disk: # It is a Disk object, we should use Disk.device _path = obj.device.path else: _path = obj.path if not _path in self.changed: self.changed[_path] = {"obj":obj, "changes":{}} return actions[result][1](device=obj, device_changes=self.changed[_path]["changes"])
def commit(self, interactive=False): """ Commits all the changes to the disks. """ if interactive: self.header(_("Commit changes")) print(_("This table is going to be applied:")) print self.print_devices_partitions() print print(_("%(warning)s: This will COMMIT ALL THE CHANGES YOU'VE DONE on the physical disks.") % {"warning":bold(_("WARNING"))}) print(_("This is the last time that you can check your new partition table.")) print(_("If you continue, you CAN'T RESTORE THE OLD TABLE!") + "\n") result = self.question(_("Do you really want to continue?"), default=False) else: result = True if result: # Ok, continue. lst, dct = lib.device_sort(self.changed) for key in lst: try: obj = dct[key]["obj"] cng = dct[key]["changes"] except: verbose("Unable to get a correct object/changes from %s." % key) continue # Skip. verbose("Committing changes in %s" % key) # If working in a Virtual freespace partition, pyparted will segfault. # The following is a workaround, but should be fixed shortly. # FIXME # FIXME FIXME # FIXME ______ FIXME # FIXME | | FIXME # FIXME | | FIXME # FIXME FIXME FIXME FIXME FIXME FIXME FIXME # ------------------------------------------ # Figure 1: A FIXME big like an house. if "-1" in key: continue # New partition table? if "newtable" in cng: progress = lib.new_table(obj, cng["newtable"]) info(_("Creating new partition table on %s...") % key) status = progress.wait() if status != 0: # Failed ... if interactive: return self.edit_partitions(warning=_("FAILED: new partition table in %s") % key) else: raise m.CmdError(_("FAILED: new partition table in %s") % key) # Clear touched, as only this action can be done if we do not own a disk. del self.touched[obj.path] # Commit on the disk. lib.commit(obj, self.touched) # Should format? if "format_real" in cng: # If this is going to be the swap partition, if swap_nofromat is setted, we should not format. #if "useas" in cng and cng["useas"] == "swap" and self.settings["swap_noformat"]: # continue # Yes. progress = lib.format_partition_for_real(obj, cng["format_real"]) info(_("Formatting %s...") % key) status = progress.wait() if status != 0: # Failed ... if interactive: return self.edit_partitions(warning=_("FAILED: formatting %s") % key) else: raise m.CmdError(_("FAILED: formatting %s") % key) # Check if it is root or swap if "useas" in cng: if cng["useas"] == "/": # Preseed self.settings["root"] = key self.settings["root_noformat"] = True elif cng["useas"] == "swap": # Preseed self.settings["swap"] = key self.settings["swap_noformat"] = True # Preseed *all* changes self.settings["changed"] = self.changed # Reload. self._reload(complete=False) # Preserve useas. # Return. if interactive: return self.edit_partitions()
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()