def _GenerateOtherSection(self, boot_menu: BootLoaderMenu, sect: str, ofunc: Callable[[BootLoaderMenu, str], bool]) -> bool: """Generate section for non-Linux systems""" ok = ofunc(boot_menu, sect) self._defnames.append(sect) if self._default == sect: if boot_menu.default_position is not None: self.msgs.append(["warn", "multiple matches found for default boot entry \"{name}\" - first match used.".format(name=self._default)]) else: boot_menu.default_position = self._pos self._pos += 1 return ok
def _GenerateOtherSection( self, boot_menu: BootLoaderMenu, sect: str, ofunc: Callable[[BootLoaderMenu, str], bool]) -> bool: """Generate section for non-Linux systems""" ok = ofunc(boot_menu, sect) self._defnames.append(sect) if self._default == sect: if boot_menu.default_position is not None: self.msgs.append([ "warn", "multiple matches found for default boot entry \"{name}\" - first match used." .format(name=self._default) ]) else: boot_menu.default_position = self._pos self._pos += 1 return ok
def GenerateSections( self, boot_menu: BootLoaderMenu, sfunc: Callable[[BootLoaderMenu, str, str], bool], ofunc: Callable[[BootLoaderMenu, str], bool] = None) -> BootLoaderMenu: """Generates sections using passed in extension-supplied functions""" try: timeout = int(self.boot_config["boot/timeout"]) except ValueError: ok = False self.msgs.append(["fatal", "Invalid value for boot/timeout."]) return boot_menu if timeout == 0: self.msgs.append([ "warn", "boot/timeout value is zero - boot menu will not appear!" ]) elif timeout < 3: self.msgs.append( ["norm", "boot/timeout value is below 3 seconds."]) # Remove builtins from list of sections sections = self.boot_config.getSections() for sect in sections[:]: if sect in self.boot_config.builtins: sections.remove(sect) # If we have no boot entries, throw an error - force user to be # explicit. if len(sections) == 0: self.msgs.append( ["fatal", "No boot entries are defined in /etc/boot.conf."]) boot_menu.success = False return boot_menu # Warn if there are no linux entries has_linux = False for sect in sections: if self.boot_config["{s}/{t}".format(s=sect, t="type")] == "linux": has_linux = True break if has_linux is False: self.msgs.append([ "warn", "No Linux boot entries are defined. You may not be able to re-enter Linux." ]) # Generate sections for sect in sections: if self.boot_config["{s}/type".format(s=sect)] in ["linux", "xen"]: ok = self._GenerateLinuxSection(boot_menu, sect, sfunc) elif ofunc: ok = self._GenerateOtherSection(boot_menu, sect, ofunc) if self._pos == 0: # this means we processed no kernels -- so we have nothing to boot! self.msgs.append([ "fatal", "No matching kernels or boot entries found in /etc/boot.conf." ]) boot_menu.success = False return boot_menu elif boot_menu.default_position is None: # this means we didn't pick a default kernel to boot! self.msgs.append([ "warn", "Had difficulty finding a default kernel -- using first one." ]) # If we didn't find a specified default, use the first one boot_menu.default_position = 0 else: self.msgs.append([ "note", "Default kernel selected via: %s." % self._default_mode ]) # Tag the boot menu as being default for display: boot_menu.boot_entries[boot_menu.default_position]["flags"].append( BootMenuFlag.DEFAULT) if self._default_mode == "autopick: mtime" and self.boot_config.item( "boot", "autopick") == "last-booted": self.msgs.append([ "warn", "Falling back to last modification time booting due to lack of last-booted info." ]) return boot_menu
def _GenerateLinuxSection( self, boot_menu: BootLoaderMenu, sect: str, sfunc: Callable[[BootLoaderMenu, str, str, str], bool]) -> bool: """Generates section for Linux systems""" ok = True # Process a section, such as "genkernel" section. findlist, skiplist = self.boot_config.flagItemList( "{s}/kernel".format(s=sect)) # findlist == special patterns to match (i.e. kernel[-v]) # skiplist == patterns to skip. findmatch = [] skipmatch = [] scanpaths = self.boot_config.item(sect, "scan").split() for scanpath in scanpaths: scanpath = os.path.join(self.config.root_path, scanpath.lstrip("/")) if self.config.root_path == "/": self.mount_if_necessary(scanpath) if len(skiplist): # find kernels to skip... matches = self.GetMatchingKernels(scanpath, skiplist) skipmatch += matches if len(findlist): # find kernels to match (skipping any kernels we should skip...) matches = self.GetMatchingKernels(scanpath, findlist, skipmatch) findmatch += matches # Generate individual boot entry using extension-supplied function found_multi = False # logic for finding a kernel to boot, based on default setting: # sort by modification time: findmatch = sorted(findmatch, key=lambda x: x[2], reverse=True) if self._default_mode == "autopick: mtime": # pick newest kernel by mtime, which happens to be top-of-list boot_menu.default_position = 0 for kname, kext, mtime in findmatch: self._defnames.append(kname) ok = sfunc(boot_menu, sect, kname, kext) self._pos += 1 else: def_mtime = None for kname, kext, mtime in findmatch: if (self._default == sect) or (self._default == kname) or ( self._default == os.path.basename(kname)): # default match if boot_menu.default_position is not None: found_multi = True if mtime > def_mtime: # this kernel is newer, use it instead boot_menu.default_position = self._pos def_mtime = mtime else: boot_menu.default_position = self._pos def_mtime = os.stat(kname)[8] self._defnames.append(kname) ok = sfunc(boot_menu, sect, kname, kext) if not ok: break self._pos += 1 if found_multi: self.msgs.append([ "warn", "multiple matches found for default \"{name}\" - most recent used." .format(name=self._default) ]) return ok
def GenerateSections(self, boot_menu: BootLoaderMenu, sfunc: Callable[[BootLoaderMenu, str, str], bool], ofunc: Callable[[BootLoaderMenu, str], bool] = None) -> BootLoaderMenu: """Generates sections using passed in extension-supplied functions""" try: timeout = int(self.boot_config["boot/timeout"]) except ValueError: ok = False self.msgs.append(["fatal", "Invalid value for boot/timeout."]) return boot_menu if timeout == 0: self.msgs.append(["warn", "boot/timeout value is zero - boot menu will not appear!"]) elif timeout < 3: self.msgs.append(["norm", "boot/timeout value is below 3 seconds."]) # Remove builtins from list of sections sections = self.boot_config.getSections() for sect in sections[:]: if sect in self.boot_config.builtins: sections.remove(sect) # If we have no boot entries, throw an error - force user to be # explicit. if len(sections) == 0: self.msgs.append(["fatal", "No boot entries are defined in /etc/boot.conf."]) boot_menu.success = False return boot_menu # Warn if there are no linux entries has_linux = False for sect in sections: if self.boot_config["{s}/{t}".format(s=sect, t="type")] == "linux": has_linux = True break if has_linux is False: self.msgs.append(["warn", "No Linux boot entries are defined. You may not be able to re-enter Linux."]) # Generate sections for sect in sections: if self.boot_config["{s}/type".format(s=sect)] in ["linux", "xen"]: ok = self._GenerateLinuxSection(boot_menu, sect, sfunc) elif ofunc: ok = self._GenerateOtherSection(boot_menu, sect, ofunc) if self._pos == 0: # this means we processed no kernels -- so we have nothing to boot! self.msgs.append(["fatal", "No matching kernels or boot entries found in /etc/boot.conf."]) boot_menu.success = False return boot_menu elif boot_menu.default_position is None: # this means we didn't pick a default kernel to boot! self.msgs.append(["warn", "Had difficulty finding a default kernel -- using first one."]) # If we didn't find a specified default, use the first one boot_menu.default_position = 0 else: self.msgs.append(["note", "Default kernel selected via: %s." % self._default_mode]) # Tag the boot menu as being default for display: boot_menu.boot_entries[boot_menu.default_position]["flags"].append(BootMenuFlag.DEFAULT) if self._default_mode == "autopick: mtime" and self.boot_config.item("boot", "autopick") == "last-booted": self.msgs.append(["warn", "Falling back to last modification time booting due to lack of last-booted info."]) return boot_menu
def _GenerateLinuxSection(self, boot_menu: BootLoaderMenu, sect: str, sfunc: Callable[[BootLoaderMenu, str, str, str], bool]) -> bool: """Generates section for Linux systems""" ok = True # Process a section, such as "genkernel" section. findlist, skiplist = self.boot_config.flagItemList("{s}/kernel".format(s=sect)) # findlist == special patterns to match (i.e. kernel[-v]) # skiplist == patterns to skip. findmatch = [] skipmatch = [] scanpaths = self.boot_config.item(sect, "scan").split() for scanpath in scanpaths: scanpath = os.path.join(self.config.root_path, scanpath.lstrip("/")) if self.config.root_path == "/": self.mount_if_necessary(scanpath) if len(skiplist): # find kernels to skip... matches = self.GetMatchingKernels(scanpath, skiplist) skipmatch += matches if len(findlist): # find kernels to match (skipping any kernels we should skip...) matches = self.GetMatchingKernels(scanpath, findlist, skipmatch) findmatch += matches # Generate individual boot entry using extension-supplied function found_multi = False # logic for finding a kernel to boot, based on default setting: # sort by modification time: findmatch = sorted(findmatch, key=lambda x: x[2], reverse=True) if self._default_mode == "autopick: mtime": # pick newest kernel by mtime, which happens to be top-of-list boot_menu.default_position = 0 for kname, kext, mtime in findmatch: self._defnames.append(kname) ok = sfunc(boot_menu, sect, kname, kext) self._pos += 1 else: def_mtime = None for kname, kext, mtime in findmatch: if (self._default == sect) or (self._default == kname) or (self._default == os.path.basename(kname)): # default match if boot_menu.default_position is not None: found_multi = True if mtime > def_mtime: # this kernel is newer, use it instead boot_menu.default_position = self._pos def_mtime = mtime else: boot_menu.default_position = self._pos def_mtime = os.stat(kname)[8] self._defnames.append(kname) ok = sfunc(boot_menu, sect, kname, kext) if not ok: break self._pos += 1 if found_multi: self.msgs.append(["warn", "multiple matches found for default \"{name}\" - most recent used.".format(name=self._default)]) return ok