Commits

Anonymous committed 33e87f5

[tui] added functionality to bootloaders module. Removed "video quality" selector and defaults to "high"

Comments (0)

Files changed (5)

modules/bootloaders.py

 
 class VectorBootLoaders(widgets.VasmModule):
     def __init__(self, parent):
+        self.vga_quality = "high"
         self._partitions = FSTAB.list_all_system_partitions()
         self._drives = FSTAB.list_all_system_drives()
         # indicate which one is the bootsector (lilo tradition)
         lb = WideLabel("<b>%s</b>"% _("Video Resolution"))
         vgabox.pack_start(lb, False, False, 4)
         vgabox.pack_start(self.vgaselector, False, False, 4)
-        lb = WideLabel("<b>%s</b>"% _("Video Quality"))
+        #        lb = WideLabel("<b>%s</b>"% _("Video Quality"))
         # create radiobuttons
-        store = gtk.ListStore(str)
-        store.append(["low"])
-        store.append(["med"])
-        store.append(["high"])
-        cr = gtk.CellRendererText()
-        self.vidqualityselector = gtk.ComboBox(store)
-        self.vidqualityselector.pack_start(cr, True)
-        self.vidqualityselector.add_attribute(cr, 'text', 0)
-        self.vidqualityselector.set_active(1)
-        self.vidqualityselector.connect("changed", self.vgaquality_toggle)
-        vgabox.pack_start(lb, False, False, 4)
-        vgabox.pack_start(self.vidqualityselector, False, False, 2)
+        #        store = gtk.ListStore(str)
+        #        store.append(["low"])
+        #        store.append(["med"])
+        #        store.append(["high"])
+        #        cr = gtk.CellRendererText()
+        #        self.vidqualityselector = gtk.ComboBox(store)
+        #        self.vidqualityselector.pack_start(cr, True)
+        #        self.vidqualityselector.add_attribute(cr, 'text', 0)
+        #        self.vidqualityselector.set_active(1)
+        #        self.vidqualityselector.connect("changed", self.vgaquality_toggle)
+        #        vgabox.pack_start(lb, False, False, 4)
+        #        vgabox.pack_start(self.vidqualityselector, False, False, 2)
         self.pack_start(vgabox, False, True, 4)
         
         # action to perform
                 loader.set_active(True)
                 self.populate_targets(self.targetselector, active.upper() == "LILO")
                 self.populate_video_modes(active.upper() == "GRUB2")
-                self.vidqualityselector.set_active(1)
                 self.vgaselector.set_active(1)
-                self.vga_quality = self.vidqualityselector.get_active_text()
                 break
     
     def fake_apply(self, button=None):

modules/support/vectorlinux/BOOTLOADERS.py

 import psutil
 import logging
 
-DEFAULT_BOOTLOADER='LILO'
+DEFAULT_BOOTLOADER='GRUB2'
 logger = logging.getLogger('vasm')
 LOADER_CONFIGS={
     "GRUB2": "/boot/grub/grub.cfg",
     "GRUB": "/boot/grub/menu.lst"
 }
 
+# Boot loader action constants
+Install = -1
+Refresh = -2
+
 def get_current_bootsector():
     """ Returns the current partition that is currently mounted in / """
     fslist = psutil.disk_partitions()
         ret.append("#")
         ret.append("# ------------------------------------ #")
         ret.append("# ------- END OF OS LISTING ---------- #")
-        ret.append("# ------------------------------------ #")
+        ret.append("# ------------------------------------ #\n\n")
         
         return ret
     
 
     def install(self):
         """ lilo requires you to setup the config file before installation """
-        ret = self.save_config()
-        if ret > 0:
-            return 1
+        self.save_config()
         return self._do_install()
     
     def _do_install(self):
         proc = sp.Popen(["lilo"], stdout=sp.PIPE, stderr=sp.PIPE)
         output = proc.communicate()[1]
         code = proc.returncode
-        if code > 0:
-            logger.fatal("Error while writing lilo to %s lilo said: \n%s"% (
-                self.target, "".join(output)))
-        return code
+        assert code == 0, output
+        logger.info("Lilo was installed to %s"% self.target)
     
     def refresh_menu(self):
         """ Procedure to refresh the menu """
         proc = utils.get_popen(["grub-install", "--no-floppy", self.target])
         err = proc.communicate()[1]
         code = proc.returncode
-        if code > 0:
-            logger.fatal("Error while installing grub2 to %s.  Grub2 said:\n"%(
-                self.target, "".join(err)))
-        else:
-            logger.info("Successfully installed grub2 to %s."% self.target)
-        return code
+        assert code == 0, err
+        logger.info("Grub2 was installed to %s"% self.target)
 
     def install(self):
         """ install the bootloader and give it its configuration """
         proc = utils.get_popen(["grub-mkconfig", "-o", LOADER_CONFIGS["GRUB2"]])
         err = proc.communicate()[1]
         code = proc.returncode
-        if code > 0:
-            logger.fatal("Error while generating grub2 boot menu.  Grub2 said: \n %s"% (
-                "".join(err)))
-        else:
-            logger.info("Grub2 menu was successfully updated.")
-        return code
+        assert code == 0, err
+        logger.info("Grub2 menu was updated.")
 
 
 class GrubCFG(object):

modules/tui/tui_bootloaders.py

 
 import urwid
 import os
+import time
 import sys
 if os.getcwd() not in sys.path:
     sys.path.append(os.getcwd())
         
         self.blpicker = widgets.HChoiceBox(
             label = 'Select Bootloader:',
-            choices = ["LILO", "GRUB2"],
+            choices = [("LILO", 'lilo'), ("GRUB2", 'grub2')],
             on_state_change = self.blpicker_event,
             on_focus = self.refresh_module_status_text
             )
             parent = self,
             on_focus = self.refresh_module_status_text
             )
-        self.videoqualitypicker = widgets.LabeledPicker(
-            label = _("Video Quality:"),
-            picker_title = _("Select your video quality for your boot screen."),
-            options = self._get_valid_video_quality(currentbootloader),
-            parent = self,
-            on_focus = self.refresh_module_status_text
-            )
+            #        self.videoqualitypicker = widgets.LabeledPicker(
+            #            label = _("Video Quality:"),
+            #            picker_title = _("Select your video quality for your boot screen."),
+            #            options = self._get_valid_video_quality(currentbootloader),
+            #            parent = self,
+            #            on_focus = self.refresh_module_status_text
+            #            )
         self.timeoutspinner = widgets.LabeledSpinner(
             label = "Timeout (seconds):",
             default_value=5,
         self.actionpicker = widgets.HChoiceBox(
             label = _("Action:"),
             choices = [
-                _("Install and refresh boot menu"),
-                _("Refresh boot menu only")],
+                (_("Install and refresh boot menu"),BOOTLOADERS.Install),
+                (_("Refresh boot menu only"), BOOTLOADERS.Refresh)],
                 on_state_change = self.action_toggle_event,
                 on_focus = self.refresh_module_status_text
             )
         _body = [self.blpicker,
                  self.targetpicker,
                  self.videosizepicker,
-                 self.videoqualitypicker,
                  self.timeoutspinner,
                  widgets.blank,
                  actionlabel,
         bootloader = self.blpicker.get_value()
         target = self.targetpicker.get_value()
         vgasize = self.videosizepicker.get_value()
-        vgaquality = self.videoqualitypicker.get_value()
+        vgaquality = "high" # we are default to 'high'
         timeout = self.timeoutspinner.get_value()
-        action = self.actionpicker.get_value()        
+        action = self.actionpicker.get_value()
+        dia = dialogs.Question(
+            parent = self,
+            message = ''.join((
+                _("WARNING: You are about to overwrite the bootloader on"), ' ',target,'.  ',
+                _("Are you sure you want to continue?")
+                )),
+            buttons = [
+                ("YES", self._do_write_changes),
+                ("NO", self.return_to_module)
+            ])
+        return self.pop_dialog(dia)
+
+    def _do_write_changes(self, widget=None):
+        # create the bootloader object
+        sloader = self.blpicker.get_value().upper()
+        tgt = self.targetpicker.get_value()
+        timeout = self.timeoutspinner.get_value()
+        vgasize = self.videosizepicker.get_value()
+        vgaquality = "high"
+        action = self.actionpicker.get_value_data()
+        methods = []
+        if sloader == 'LILO':
+            blobject = BOOTLOADERS.LILO(
+                target=tgt,
+                timeout = timeout,
+                vga_size = vgasize,
+                vga_quality = vgaquality
+                )
+            methods.append(blobject.install)
+        elif sloader == 'GRUB2':
+            blobject = BOOTLOADERS.GRUB2(
+                target=tgt,
+                timeout=timeout,
+                vga_size=vgasize,
+                vga_quality=vgaquality
+                )
+            if action == BOOTLOADERS.Install:
+                methods.append(blobject.install)
+                methods.append(blobject.refresh_menu)
+            elif action == BOOTLOADERS.Refresh:
+                methods.append(blobject.refresh_menu)
+        # run the changes.  First drop the UI and go to a terminal
+        self.pause_ui()
+        print "Saving changes to %s on %s"% (blobject.type, blobject.target)
+        print "This may take a few seconds... Please wait."
+        for method in methods:
+            try:
+                method()
+            except AssertionError as e:
+                dia = dialogs.Error(
+                    parent = self,
+                    message = "%e"% e,
+                    buttons = [("OK", self.return_to_module)]
+                    )
+                self.resume_ui()
+                self.return_to_module()
+                self.pop_dialog(dia)
+            time.sleep(1)
         dia = dialogs.Info(
             parent = self,
-            message = ''.join(
-                ("Install %s to %s\n"% (bootloader, target),
-                "Timeout=%s\n"% timeout,
-                "Video size=%s\n"% vgasize,
-                "Quality=%s\n"% vgaquality,
-                "action=%s\n"% action)
-                ),
-            buttons = [("OK", self.return_to_module)]
+            message = ''.join((
+                _("Changes saved successfully."), "  ",
+                _("You will see the changes applied the next time the system restarts.")
+                )),
+            buttons = [("OK", self.close_module)]                
             )
-        return self.pop_dialog(dia)
+        self.return_to_module()
+        self.pop_dialog(dia)
+        self.resume_ui()
 
     def do_save_changes(self, widget=None):
-        pass
+        return self._do_write_changes()
+
 
     def refresh_module_status_text(self, widget=None):
         if isinstance(widget, widgets.SensibleLabel):
         # populate the targets.
         self.targetpicker.set_options(self._get_valid_targets(bootloader))
         self.videosizepicker.set_options(self._get_valid_video_sizes(bootloader))
-        self.videoqualitypicker.set_options(
-            self._get_valid_video_sizes(bootloader)
-            )
-        self.videoqualitypicker.set_value('med')
         self.videosizepicker.set_value('800x600')
         # We want to force the target to reset because we dont want
         # an invalid (ie, bootsector) value in the target when grub is selected

modules/tuisupport/dialogs.py

     def pop_dialog(self, dialog, level=1):
         """ Send a dialog to the parent so it can be popped up"""
         return self.parent.pop_module_dialog(dialog, level)
+
+    def pause_ui(self):
+        """ Pause execution of the main loop and hand control to the tty """
+        ml = self.parent._mainloop
+        return ml.screen.stop()
+
+    def resume_ui(self):
+        """ Resume execution of the main loop """
+        ml = self.parent._mainloop
+        return ml.screen.start()
+        
+    
     
     def _emulate_left_button(self, times=1):
         """ emulate a left arrow hit """

modules/tuisupport/widgets.py

     def __init__(self, label="", group=None, state=False, on_state_change=None,
 		 user_data=None, on_focus=None):
 	self.on_focus=on_focus
+	self.user_data = user_data
 	urwid.RadioButton.__init__(
 		self,
 		group,
 	_widgets = [('fixed', len(label) + 1, self.label)]
 	rbw = 0
 	self._radios = []
-	for item in choices:
+	for item, data in choices:
 	    rbw = max(rbw, len(item) + 6, 10)
 	    rb = SensibleRadioButton(group=rbgroup, label=item,
 			     on_state_change=self.radio_toggle,
+			     user_data = data,
 			     on_focus=on_focus)
 		    #rb = urwid.RadioButton(group=rbgroup, label=item, on_state_change=self.radio_toggle)
 	    self._radios.append(rb)
     def get_value(self):
 	return self._selection
 
+    def get_value_data(self):
+	for rb in self._radios:
+	    if rb.get_label() == self._selection:
+		return rb.user_data
+
     def set_value(self, value):
 	for item in self._radios:
 	    if item.get_label().upper() == value.upper():
     def pop_dialog(self, dialog, level=1):
         """ Send a dialog to the parent so it can be popped up"""
         return self.parent.pop_module_dialog(dialog, level)
+
+    def pause_ui(self):
+        """ Pause execution of the main loop and hand control to the tty """
+        ml = self.parent._mainloop
+        return ml.screen.stop()
+
+    def resume_ui(self):
+        """ Resume execution of the main loop """
+        ml = self.parent._mainloop
+        return ml.screen.start()
     
     def _emulate_left_button(self, times=1):
         """ emulate a left arrow hit """
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.