diff --git a/tools/pygrub/src/GrubConf.py b/tools/pygrub/src/GrubConf.py index 9ff843780d..62d75ef40a 100644 --- a/tools/pygrub/src/GrubConf.py +++ b/tools/pygrub/src/GrubConf.py @@ -227,7 +227,7 @@ class _GrubConfigFile(object): if val == "saved": self._default = 0 else: - self._default = int(val) + self._default = val if self._default < 0: raise ValueError, "default must be positive number" @@ -427,11 +427,11 @@ class Grub2ConfigFile(_GrubConfigFile): if self.commands.has_key(com): if self.commands[com] is not None: - if arg.strip() == "${saved_entry}": + arg_strip = arg.strip() + if arg_strip == "${saved_entry}" or arg_strip == "${next_entry}": + logging.warning("grub2's saved_entry/next_entry not supported") arg = "0" - elif arg.strip() == "${next_entry}": - arg = "0" - setattr(self, self.commands[com], arg.strip()) + setattr(self, self.commands[com], arg_strip) else: logging.info("Ignored directive %s" %(com,)) elif com.startswith('set:'): diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub index 6d09d960f1..5287c9ba8d 100644 --- a/tools/pygrub/src/pygrub +++ b/tools/pygrub/src/pygrub @@ -463,9 +463,28 @@ class Grub: def run(self): timeout = int(self.cf.timeout) - self.selected_image = self.cf.default + if self.cf.default.isdigit(): + self.selected_image = int(self.cf.default) + else: + # We don't fully support submenus. Look for the leaf value in + # "submenu0>submenu1>...>menuentry" and hope that it's unique. + title = self.cf.default + while 1: + try: + title = re.search('(\S)>(\S.+$)',title).group(2) + except AttributeError: + break + + # Map string to index in images array + self.selected_image = 0 + for i in range(len(self.cf.images)): + if self.cf.images[i].title == title: + self.selected_image = i + break + # If the selected (default) image doesn't exist we select the first entry if self.selected_image > len(self.cf.images): + logging.warning("Default image not found") self.selected_image = 0 self.isdone = False while not self.isdone: