Moises Henriquez avatar Moises Henriquez committed c42f022

Detecting no bootsector available

Comments (0)

Files changed (2)

src/vasm/ui/gtk2/modules/bootloaders.py

             return self.apply_grub2_event()
     
     def check_for_bootsector_availability(self):
+        """ Returns True when we are able to read the bootsector
+        and safe to continue.  False otherwise """
         # FIXME:
         # Add some checks to make sure we have a bootsector available.
         # If we are running in a chroot, this will fail.
-        pass
+        bsector = BOOTLOADERS.get_current_bootsector()
+        if not bsector:
+            #trouble!!!
+            msg = (
+                _("We are unable to determine which partition is being used as /"),
+                _("You will not be able to save changes in this environment"))
+            logger.error("Unable to find current bootsector... Possible chroot environment")
+            dia = dialogs.error('  '.join(msg), parent=self)
+            if dia.run():
+                dia.destroy()
+            return False
+        return True
     
     def apply_lilo_event(self, button=None):
         """ Apply event for when lilo is the selected bootloader """
+        if not self.check_for_bootsector_availability():
+            return
         res = dialogs.question(" ".join(self._warning), parent = self._parent)
         if res == gtk.RESPONSE_NO:
             return
     
     def apply_grub2_event(self, button=None):
         """ Apply event for when grub2 is the selected bootloader """
+        if not self.check_for_bootsector_availability():
+            return
         res = dialogs.question(" ".join(self._warning), parent = self._parent)
         if res == gtk.RESPONSE_NO:
             return

src/vasm/ui/tui/modules/tui_bootloaders.py

             ' '.join((
                 _("Select a valid target from the options list."),
                 _("Access the options list by pressing Enter or Space on the selection area")))
+    
+    def test_bootsector_available(self, widget=None):
+        bsector = BOOTLOADERS.get_current_bootsector()
+        if bsector is None:
+            msg = (
+                _("We are unable to determine which partition is being used as /."),
+                _("You will not be able to save changes in this environment"))
+            logger.error("Unable to find current bootsector... Possible chroot environment")
+            dia = dialogs.Error(
+                parent = self.parent,
+                buttons = (["OK", self.return_to_module]),
+                message = '  '.join(msg))
+            return self.pop_dialog(dia)
+        return True
 
     def module_ok_event(self, widget=None):
         """ Triggered when "Save" is pressed on this module """
+        if not self.test.bootsector_available():
+            # Cancel because we cannot read the bootsector 
+            return
         try:
             self._check_selections()
         except AssertionError as e:
                 buttons = [("OK", self.return_to_module)]
                 )
             return self.pop_dialog(dia)
-
         bootloader = self.blpicker.get_value()
         target = self.targetpicker.get_value()
         vgasize = self.videosizepicker.get_value()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.