class Yali: def __init__(self, install_type=YALI_INSTALL, install_plugin=None): self._screens = {} # Normal Installation process self._screens[YALI_INSTALL] = [ # Numbers can be used with -s paramter yali.gui.ScrKahyaCheck, # 00 yali.gui.ScrWelcome, # 01 yali.gui.ScrCheckCD, # 02 yali.gui.ScrKeyboard, # 03 yali.gui.ScrDateTime, # 04 yali.gui.ScrUsers, # 05 yali.gui.ScrAdmin, # 06 yali.gui.ScrPartitionAuto, # 07 yali.gui.ScrPartitionManual, # 08 yali.gui.ScrBootloader, # 09 yali.gui.ScrSummary, # 10 yali.gui.ScrInstall, # 11 yali.gui.ScrGoodbye # 12 ] self._screens[YALI_DVDINSTALL] = [ # Numbers can be used with -s paramter yali.gui.ScrKahyaCheck, # 00 yali.gui.ScrWelcome, # 01 yali.gui.ScrCheckCD, # 02 yali.gui.ScrKeyboard, # 03 yali.gui.ScrDateTime, # 04 yali.gui.ScrUsers, # 05 yali.gui.ScrAdmin, # 06 yali.gui.ScrPartitionAuto, # 07 yali.gui.ScrPartitionManual, # 08 yali.gui.ScrBootloader, # 09 yali.gui.ScrInstallationAuto, # 10 yali.gui.ScrSummary, # 11 yali.gui.ScrInstall, # 12 yali.gui.ScrGoodbye # 13 ] # FirstBoot Installation process self._screens[YALI_FIRSTBOOT] = [ # Numbers can be used with -s paramter yali.gui.ScrWelcome, # 00 yali.gui.ScrKeyboard, # 01 yali.gui.ScrDateTime, # 02 yali.gui.ScrUsers, # 03 yali.gui.ScrAdmin, # 04 yali.gui.ScrGoodbye # 05 ] # Oem Installation process self._screens[YALI_OEMINSTALL] = [ # Numbers can be used with -s paramter yali.gui.ScrWelcome, # 00 yali.gui.ScrCheckCD, # 01 yali.gui.ScrPartitionAuto, # 02 yali.gui.ScrPartitionManual, # 03 yali.gui.ScrBootloader, # 04 yali.gui.ScrSummary, # 05 yali.gui.ScrInstall, # 06 yali.gui.ScrGoodbye # 07 ] # Use YALI just for partitioning self._screens[YALI_PARTITIONER] = [ yali.gui.ScrPartitionManual # Manual Partitioning ] # Rescue Mode self._screens[YALI_RESCUE] = [ yali.gui.ScrRescue, # Rescue Mode yali.gui.ScrRescueGrub, # Grub Rescue yali.gui.ScrRescuePisi, # Pisi HS Rescue yali.gui.ScrRescuePassword, # Password Rescue yali.gui.ScrRescueFinish # Final step for rescue ] self.plugin = None # mutual exclusion self.mutex = QMutex() self.waitCondition = QWaitCondition() self.retryAnswer = False # Let the show begin.. if install_type == YALI_PLUGIN: self.plugin = self.getPlugin(install_plugin) if self.plugin: self.screens = self.plugin.config.screens # run plugins setup self.plugin.config.setup() else: install_type = YALI_INSTALL InfoDialog(_("Plugin '%s' could not be loaded or found, switching to normal installation process." % install_plugin)) if not self.plugin: self.screens = self._screens[install_type] self.install_type = install_type self.info = InformationWindow("Please wait...") self.checkCDStop = True def getPlugin(self, p): try: _p = __import__("yali.plugins.%s.config" % p) except ImportError: return False plugin = getattr(_p.plugins,p) return plugin def checkCD(self, rootWidget): ctx.mainScreen.disableNext() ctx.mainScreen.disableBack() self.info.updateAndShow(_("Starting validation...")) class PisiUI(pisi.ui.UI): def notify(self, event, **keywords): pass def display_progress(self, operation, percent, info, **keywords): pass yali.pisiiface.initialize(ui = PisiUI(), with_comar = False, nodestDir = True) yali.pisiiface.addCdRepo() ctx.mainScreen.processEvents() pkg_names = yali.pisiiface.getAvailablePackages() rootWidget.progressBar.setMaximum(len(pkg_names)) cur = 0 for pkg_name in pkg_names: cur += 1 ctx.debugger.log("Validating %s " % pkg_name) self.info.updateMessage(_("Validating %s") % pkg_name) if self.checkCDStop: continue try: yali.pisiiface.checkPackageHash(pkg_name) rootWidget.progressBar.setValue(cur) except: self.showError(_("Validation Failed"), _("<b><p>Validation of installation packages failed.\ Please remaster your installation medium and restart the installation.</p></b>")) if not self.checkCDStop: rootWidget.checkLabel.setText(_('<font color="#FFF"><b>Validation succeeded. You can proceed with the installation.</b></font>')) rootWidget.checkButton.setText(_("Validate Integrity")) else: rootWidget.checkLabel.setText("") rootWidget.progressBar.setValue(0) yali.pisiiface.removeRepo(ctx.consts.cd_repo_name) ctx.mainScreen.enableNext() ctx.mainScreen.enableBack() self.info.hide() def setKeymap(self, keymap): yali.localeutils.setKeymap(keymap["xkblayout"], keymap["xkbvariant"]) ctx.installData.keyData = keymap def setTime(self, rootWidget): self.info.updateAndShow(_("Adjusting time settings...")) date = rootWidget.calendarWidget.selectedDate() args = "%02d%02d%02d%02d%04d.%02d" % (date.month(), date.day(), rootWidget.timeHours.time().hour(), rootWidget.timeMinutes.time().minute(), date.year(), rootWidget.timeSeconds.time().second()) # Set current date and time ctx.debugger.log("Date/Time setting to %s" % args) yali.sysutils.run("date %s" % args) # Sync date time with hardware ctx.debugger.log("YALI's time is syncing with the system.") yali.sysutils.run("hwclock --systohc") self.info.hide() def setTimeZone(self, rootWidget): # Store time zone selection we will set it in processPending actions. ctx.installData.timezone = rootWidget.timeZoneList.currentItem().text() ctx.debugger.log("Time zone selected as %s " % ctx.installData.timezone) def scanPartitions(self, rootWidget): def sortBySize(x,y): if x["newSize"]>y["newSize"]:return -1 elif x["newSize"]==y["newSize"]: return 0 return 1 self.info.updateAndShow(_("Analyzing disks...")) rootWidget.resizablePartitions = [] rootWidget.resizableDisks = [] rootWidget.freeSpacePartitions = [] rootWidget.freeSpaceDisks = [] ctx.debugger.log("Disk analysis started.") ctx.debugger.log("%d disk found." % len(yali.storage.devices)) for dev in yali.storage.devices: ctx.debugger.log("In disk %s, %d mb is free." % (dev.getPath(), dev.getLargestContinuousFreeMB())) #if dev.getLargestContinuousFreeMB() > ctx.consts.min_root_size + 100: # rootWidget.resizableDisks.append(dev) for part in dev.getOrderedPartitionList(): ctx.debugger.log("Partition %s found on disk %s, formatted as %s" % (part.getPath(), dev.getPath(), part.getFSName())) if part.isFreespace() and (part.isLogical() or dev.primaryAvailable()): ctx.debugger.log(" - This partition is free") if part.getMB() > ctx.consts.min_root_size: ctx.debugger.log(" - Usable size for this partition is %.2f MB" % part.getMB()) rootWidget.freeSpacePartitions.append({"partition":part,"newSize":part.getMB()}) if dev not in rootWidget.freeSpaceDisks: rootWidget.freeSpaceDisks.append(dev) elif part.isResizable(): minSize = part.getMinResizeMB() possibleFreeSize = part.getMB() - minSize ctx.debugger.log(" - This partition is resizable") ctx.debugger.log(" - Total size of this partition is %.2f MB" % part.getMB()) ctx.debugger.log(" - It can resizable to %.2f MB" % minSize) ctx.debugger.log(" - Usable size for this partition is %.2f MB" % possibleFreeSize) rootWidget.resizablePartitions.append({"partition":part,"newSize":possibleFreeSize}) if possibleFreeSize / 2 > ctx.consts.min_root_size: if dev not in rootWidget.resizableDisks: rootWidget.resizableDisks.append(dev) else: ctx.debugger.log("This partition is not usable") # Sort by size.. rootWidget.resizablePartitions.sort(sortBySize) rootWidget.freeSpacePartitions.sort(sortBySize) self.info.hide() def getResizableFirstPartition(self): # Hacky .. :) arp = [] class __v: pass mean = __v() self.scanPartitions(mean) for partition in mean.resizablePartitions: if partition["newSize"] / 2 >= ctx.consts.min_root_size: arp.append(partition) if len(arp)>0: return arp[0] else: raise YaliException, "No resizable partition found!" def autoPartDevice(self): self.info.updateAndShow(_("Writing partition table(s)...")) ctx.partrequests.remove_all() dev = ctx.installData.autoPartDev # first delete partitions on device dev.deleteAllPartitions() dev.commit() ctx.mainScreen.processEvents() p = dev.addPartition(None, parttype.root.parted_type, parttype.root.filesystem, dev.getFreeMB(), parttype.root.parted_flags) p = dev.getPartition(p.num) # get partition.Partition # create the partition dev.commit() ctx.mainScreen.processEvents() # make partition requests ctx.partrequests.append(request.MountRequest(p, parttype.root)) ctx.partrequests.append(request.FormatRequest(p, parttype.root)) ctx.partrequests.append(request.LabelRequest(p, parttype.root)) ctx.partrequests.append(request.SwapFileRequest(p, parttype.root)) time.sleep(2) def checkSwap(self): # check swap partition, if not present use swap file rt = request.mountRequestType pt = parttype.swap swap_part_req = ctx.partrequests.searchPartTypeAndReqType(pt, rt) if not swap_part_req: # No swap partition defined using swap as file in root # partition rt = request.mountRequestType pt = parttype.root root_part_req = ctx.partrequests.searchPartTypeAndReqType(pt, rt) ctx.partrequests.append(request.SwapFileRequest(root_part_req.partition(), root_part_req.partitionType())) def autoPartUseAvail(self): dev = ctx.installData.autoPartDev _part = ctx.installData.autoPartPartition part = _part["partition"] if part.isLogical(): ptype = PARTITION_LOGICAL else: ptype = PARTITION_PRIMARY if part.isResizable(): newPartSize = int(_part["newSize"]/2) - 2 ctx.debugger.log("UA: newPartSize : %s " % newPartSize) ctx.debugger.log("UA: resizing to : %s " % (int(part.getMB()) - newPartSize)) try: _np = dev.resizePartition(part._fsname, part.getMB() - newPartSize, part) except FSCheckError, message: ctx.debugger.log("FAILED: %s" % unicode(message)) InfoDialog(unicode(message), title = _("Filesystem Error")) self.info.updateMessage(_("Finished resizing partition(s)")) ctx.debugger.log("UA: Resize finished.") time.sleep(1) newStart = _np.geom.end np = dev.getPartition(_np.num) self.info.updateMessage(_("Creating new partition...")) ctx.debugger.log("UA: newStart : %s " % newStart) _newPart = dev.addPartition(None, ptype, parttype.root.filesystem, newPartSize - 8, parttype.root.parted_flags, newStart) newPart = dev.getPartition(_newPart.num) elif part.isFreespace(): newPartSize = part.getMB() - 8 newStart = part.getStart() _newPart = dev.addPartition(part._partition, ptype, parttype.root.filesystem, newPartSize, parttype.root.parted_flags) newPart = dev.getPartition(_newPart.num)
class Yali: def __init__(self, install_type=YALI_INSTALL, install_plugin=None): self._screens = {} # Normal Installation process self._screens[YALI_INSTALL] = [ # Numbers can be used with -s paramter yali.gui.ScrKahyaCheck, # 00 yali.gui.ScrWelcome, # 01 yali.gui.ScrCheckCD, # 02 yali.gui.ScrKeyboard, # 03 yali.gui.ScrDateTime, # 04 yali.gui.ScrUsers, # 05 yali.gui.ScrAdmin, # 06 yali.gui.ScrDriveSelection, yali.gui.ScrPartitionAuto, # 07 yali.gui.ScrPartitionManual, # 08 yali.gui.ScrBootloader, # 09 yali.gui.ScrSummary, # 10 yali.gui.ScrInstall, # 11 yali.gui.ScrGoodbye # 12 ] self._screens[YALI_DVDINSTALL] = [ # Numbers can be used with -s paramter yali.gui.ScrKahyaCheck, # 00 yali.gui.ScrWelcome, # 01 yali.gui.ScrCheckCD, # 02 yali.gui.ScrKeyboard, # 03 yali.gui.ScrDateTime, # 04 yali.gui.ScrUsers, # 05 yali.gui.ScrAdmin, # 06 yali.gui.ScrDriveSelection, yali.gui.ScrPartitionAuto, # 07 yali.gui.ScrPartitionManual, # 08 yali.gui.ScrBootloader, # 09 yali.gui.ScrInstallationAuto, # 10 yali.gui.ScrSummary, # 11 yali.gui.ScrInstall, # 12 yali.gui.ScrGoodbye # 13 ] # FirstBoot Installation process self._screens[YALI_FIRSTBOOT] = [ # Numbers can be used with -s paramter yali.gui.ScrWelcome, # 00 yali.gui.ScrKeyboard, # 01 yali.gui.ScrDateTime, # 02 yali.gui.ScrUsers, # 03 yali.gui.ScrAdmin, # 04 yali.gui.ScrGoodbye # 05 ] # Oem Installation process self._screens[YALI_OEMINSTALL] = [ # Numbers can be used with -s paramter yali.gui.ScrWelcome, # 00 yali.gui.ScrCheckCD, # 01 yali.gui.ScrPartitionAuto, # 02 yali.gui.ScrPartitionManual, # 03 yali.gui.ScrBootloader, # 04 yali.gui.ScrSummary, # 05 yali.gui.ScrInstall, # 06 yali.gui.ScrGoodbye # 07 ] # Use YALI just for partitioning self._screens[YALI_PARTITIONER] = [ yali.gui.ScrPartitionManual # Manual Partitioning ] # Rescue Mode self._screens[YALI_RESCUE] = [ yali.gui.ScrRescue, # Rescue Mode yali.gui.ScrRescueGrub, # Grub Rescue yali.gui.ScrRescuePisi, # Pisi HS Rescue yali.gui.ScrRescuePassword, # Password Rescue yali.gui.ScrRescueFinish # Final step for rescue ] self.plugin = None # mutual exclusion self.mutex = QMutex() self.waitCondition = QWaitCondition() self.retryAnswer = False # Let the show begin.. if install_type == YALI_PLUGIN: self.plugin = self.getPlugin(install_plugin) if self.plugin: self.screens = self.plugin.config.screens # run plugins setup self.plugin.config.setup() else: install_type = YALI_INSTALL ctx.interface.messageWindow(_("Warning"), _("Plugin '%s' could not be loaded or found, switching to" "normal installation process." % install_plugin), type="warning", customIcon="error") if not self.plugin: self.screens = self._screens[install_type] self.install_type = install_type self.info = InformationWindow("Please wait...") self.info.hide() self.checkCDStop = True self._inconsistentLVMAnswers = {} def getPlugin(self, p): try: _p = __import__("yali.plugins.%s.config" % p) except ImportError: return False plugin = getattr(_p.plugins,p) return plugin def checkCD(self, rootWidget): ctx.mainScreen.disableNext() ctx.mainScreen.disableBack() self.info.updateAndShow(_("Starting validation...")) class PisiUI(pisi.ui.UI): def notify(self, event, **keywords): pass def display_progress(self, operation, percent, info, **keywords): pass yali.pisiiface.initialize(ui = PisiUI(), with_comar = False, nodestDir = True) yali.pisiiface.addCdRepo() ctx.mainScreen.processEvents() pkg_names = yali.pisiiface.getAvailablePackages() rootWidget.progressBar.setMaximum(len(pkg_names)) cur = 0 for pkg_name in pkg_names: cur += 1 ctx.logger.debug("Validating %s " % pkg_name) self.info.updateMessage(_("Validating %s") % pkg_name) if self.checkCDStop: continue try: yali.pisiiface.checkPackageHash(pkg_name) rootWidget.progressBar.setValue(cur) except: rc = ctx.interface.messageWindow(_("Warning"), _("Validation of installation packages failed." "Please remaster your installation medium and" "reboot."), type="custom", customIcon="error", customButtons=[_("Go Forward"), _("Reboot")], default=1) break if not rc: ctx.mainScreen.enableBack() else: yali.util.reboot() if not self.checkCDStop: ctx.yali.info.updateAndShow(_('<font color="#FFF"><b>Validation succeeded. You can proceed with the installation.</b></font>')) rootWidget.checkButton.setText(_("Validate Integrity")) else: ctx.yali.info.hide() rootWidget.progressBar.setValue(0) yali.pisiiface.removeRepo(ctx.consts.cd_repo_name) ctx.mainScreen.enableNext() ctx.mainScreen.enableBack() self.info.hide() def setTime(self, rootWidget): self.info.updateAndShow(_("Adjusting time settings")) date = rootWidget.calendarWidget.date() time = rootWidget.timeEdit.time() args = "%02d%02d%02d%02d%04d.%02d" % (date.month(), date.day(), time.hour(), time.minute(), date.year(), time.second()) # Set current date and time ctx.logger.debug("Date/Time setting to %s" % args) yali.util.run_batch("date", args) # Sync date time with hardware ctx.logger.debug("YALI's time is syncing with the system.") yali.util.run_batch("hwclock", ["--systohc"]) self.info.hide() def setTimeZone(self, rootWidget): # Store time zone selection we will set it in processPending actions. index = rootWidget.timeZoneList.currentIndex() ctx.installData.timezone = rootWidget.timeZoneList.itemData(index) ctx.logger.debug("Time zone selected as %s " % ctx.installData.timezone) def storageComplete(self): title = None message = None details = None try: ctx.storage.doIt() except FilesystemResizeError as (msg, device): title = _("Resizing Failed") message = _("There was an error encountered while " "resizing the device %s.") % (device,) details = "%s" %(msg,) except FilesystemMigrateError as (msg, device): title = _("Migration Failed") message = _("An error was encountered while " "migrating filesystem on device %s.") % (device,) details = msg