diff options
| author | Joel Andres Granados <jgranado@redhat.com> | 2008-10-28 16:41:56 +0100 |
|---|---|---|
| committer | Joel Andres Granados <jgranado@redhat.com> | 2008-10-28 17:16:42 +0100 |
| commit | dab11be258ed383b138519be5613f74ac985cd0d (patch) | |
| tree | a7944f9c6ea857fb4e7bb8bbad177063faf34593 /plugins | |
| parent | c9de756d4f4dff1f2fafc4b839e23313c6090f5c (diff) | |
| download | firstaidkit-dab11be258ed383b138519be5613f74ac985cd0d.tar.gz firstaidkit-dab11be258ed383b138519be5613f74ac985cd0d.tar.xz firstaidkit-dab11be258ed383b138519be5613f74ac985cd0d.zip | |
Grup Plugin:
1. Address various minor issues with messages to the user.
2. Make the name of the issues different so they can be told appart.
3. Make sure that the fix step fails when there are no devs or parts.
4. Inform the user of the devices and partitions that are being backed up.
5. Make sure that the description is visible.
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/grub/grub.py | 42 | ||||
| -rw-r--r-- | plugins/grub/grubUtils.py | 32 |
2 files changed, 51 insertions, 23 deletions
diff --git a/plugins/grub/grub.py b/plugins/grub/grub.py index 1935056..6da6fd9 100644 --- a/plugins/grub/grub.py +++ b/plugins/grub/grub.py @@ -34,6 +34,7 @@ class Grub(Plugin): name = "Grub" version = "0.0.1" author = "Joel Andres Granados" + description = "Plugin to recover lost grub bootloader functionality" @classmethod def getDeps(cls): @@ -82,9 +83,10 @@ class Grub(Plugin): self.install_grub_devs = [] # Initialize our list of related issues. - self.issue_grub_dir = SimpleIssue(self.name, "Missing grub dir or " \ - "dir files.") - self.issue_grub_image = SimpleIssue(self.name, "Bad grub stage1 image.") + self.issue_grub_dir = SimpleIssue(self.name+"_DIR", "Missing grub " \ + "dir or dir files.") + self.issue_grub_image = SimpleIssue(self.name+"_IMAGE", "Bad grub " \ + "stage1 image.") # Initialize the backup space. self.backupSpace = self._backups.getBackup( \ @@ -186,16 +188,18 @@ class Grub(Plugin): if not grubUtils.other_bootloader_present(Dname(part)): self._reporting.info("Found no other bootloader " \ "in %s partition." % Dname.asPath(part), \ - origin = self) + origin = self) self.install_grub_parts.append(Dname(part)) else: # If not arguments where specified the right thing to do is to # leave everything alone:) self.install_grub_parts = [] self.install_grub_devs = [] - self._reporting.info("Grub will modify any drive. " \ + self._reporting.info("Grub wont modify any drive. " \ "If you want grub to take action you must specify: " \ - "--install-to, --install-all or --install-auto.") + "--installto-devs, --installto-parts, " \ + "--install-all or --install-auto.", \ + origin = self) self._result = ReturnSuccess except Exception, e: @@ -247,14 +251,26 @@ class Grub(Plugin): # Since we are going to install the stage1 grub image in all the # devices in self.install_grub_devs, we will backup all of them. # FIXME: We have to modify the plugin to consider partitions. - self._reporting.info("Going to backup all the first 446 bytes of " \ - "all storage devices in the system.", origin = self) firstblockdict = {} + + if len(self.install_grub_devs) > 0: + self._reporting.info("Going to backup all the first 446 bytes of " \ + "%s." % self.install_grub_devs, origin = self) for device in self.install_grub_devs: fd = os.open(device.path(), os.O_RDONLY) first446btemp = os.read(fd, 446) os.close(fd) firstblockdict[device.name()] = [first446btemp, device] + + if len(self.install_grub_parts) > 0: + self._reporting.info("Going to backup all the first 446 bytes of " \ + "%s." % self.install_grub_parts, origin = self) + for part in self.install_grub_parts: + fd = os.open(part.path(), os.O_RDONLY) + first446btemp = os.read(fd, 446) + os.close(fd) + firstblockdict[part.name()] = [first446btemp, part] + self.backupSpace.backupValue( firstblockdict, "firstblockdict") self._result = ReturnSuccess @@ -263,9 +279,17 @@ class Grub(Plugin): if len(self.grub_dir_parts) == 0: self._reporting.error("No grub directories where found... exiting.", origin = self) - self.issue_grub_image.set(fixed = False, \ + self.issue_grub_dir.set(fixed = False, \ reporting = self._reporting, origin = self) + self._result = ReturnFailure + return + # We are to fail if there are no devs or parts to install to. + if len(self.install_grub_devs) + len(self.install_grub_parts) == 0: + self._reporting.error("No devices or partitions to install to.", + origin = self) + self.issue_grub_image.set(fixed = False, \ + reporting = self._reporting, origin = self) self._result = ReturnFailure return diff --git a/plugins/grub/grubUtils.py b/plugins/grub/grubUtils.py index 7d1a286..7488b87 100644 --- a/plugins/grub/grubUtils.py +++ b/plugins/grub/grubUtils.py @@ -67,20 +67,24 @@ def get_all_devs(): continue else: - # parted will provide us with all the partitions. - partitions = [] - parteddev = parted.PedDevice.get(device["device"]) - disk = parted.PedDisk.new(parteddev) - part = disk.next_partition() - while part: - if part.num > 0: - partitions.append( - Dname("%s%s"%(device["device"],part.num))) - part = disk.next_partition(part) - # The key will be the device name and it will contain a list of - # parts. This is very unfortunate as the object would be better - # sutied as a key. - retval[Dname.asName(device["device"])] = partitions + try: + # parted will provide us with all the partitions. + partitions = [] + parteddev = parted.PedDevice.get(device["device"]) + disk = parted.PedDisk.new(parteddev) + part = disk.next_partition() + while part: + if part.num > 0: + partitions.append( + Dname("%s%s"%(device["device"],part.num))) + part = disk.next_partition(part) + # The key will be the device name and it will contain a list of + # parts. This is very unfortunate as the object would be better + # sutied as a key. + retval[Dname.asName(device["device"])] = partitions + except: + # If there is a problem with this dev... jus continue. + continue return retval |
