Anonymous avatar Anonymous committed f49fb3d

Added main launcher script. [tui] Fixed crash due to lacking default value on HChoiceBoxes

Comments (0)

Files changed (7)

modules/support/vectorlinux/BOOTLOADERS.py

 import psutil
 import logging
 
+DEFAULT_BOOTLOADER='LILO'
 logger = logging.getLogger('vasm')
 LOADER_CONFIGS={
     "GRUB2": "/boot/grub/grub.cfg",

modules/support/vectorlinux/utils.py

 
 def _(txt):
     return txt
-
-def start_logger():
-    logger = logging.getLogger('vasm')
-    hdlr = logging.FileHandler('/var/log/vasm.log')
-    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
-    hdlr.setFormatter(formatter)
-    logger.addHandler(hdlr)
-    logger.setLevel(logging.ERROR)
     
 logger = logging.getLogger('vasm')
 

modules/tui/tui_bootloaders.py

 class BootloaderTui(dialogs.ModuleDialog):
     def __init__(self, parent):
         self.parent = parent
+        bsector = BOOTLOADERS.get_current_bootsector()
+        rootdev = bsector[:len('/dev/sda'):]
+        currentbootloader = BOOTLOADERS.MBR(rootdev).read_bootloader() or \
+            BOOTLOADERS.DEFAULT_BOOTLOADER
         msg = (
             _("Select which bootloader you would like to use."), "\n",
             _("WARNING: this tool will over-write the target you selecct below."), "  ",
             _("Selecting the wrong options here could render your system unbootable."),)
-
+        
         self.blpicker = widgets.HChoiceBox(
             label = 'Select Bootloader:',
             choices = ["LILO", "GRUB2"],
         self.targetpicker = widgets.LabeledPicker(
             label = "Installation Target:",
             picker_title = _("Select the installation target for your bootloader."),
-            options = ["Foo", "bar", "foobar", "barfoo"],
+            options = self._get_valid_targets(currentbootloader),
             parent = self,
             on_focus = self.refresh_module_status_text
             )
         self.videosizepicker = widgets.LabeledPicker(
             label = _("Video Resolution:"),
             picker_title = _("Select the video resolution for your boot screen."),
-            options = ["FOO", "BAR", "FOO"],
+            options = self._get_valid_video_sizes(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 = ["low", "med", "high"],
+            options = self._get_valid_video_quality(currentbootloader),
             parent = self,
             on_focus = self.refresh_module_status_text
             )
 
     def action_toggle_event(self, radio=None, new_state=None, user_data=None):
         pass
+
+    def _get_valid_targets(self, bootloader=BOOTLOADERS.DEFAULT_BOOTLOADER):
+        partitions = FSTAB.list_all_system_partitions()
+        drives = FSTAB.list_all_system_drives()
+        if bootloader.upper() == 'LILO':
+            targets = partitions
+            targets.extend(drives)
+            targets.sort()
+            return targets
+        elif bootloader.upper() == 'GRUB2':
+            targets = drives
+            targets.sort()
+            return targets
+        return []
+
+    def _get_valid_video_sizes(self, bootloader=BOOTLOADERS.DEFAULT_BOOTLOADER):
+        ret = []
+        if bootloader.upper() in ("LILO","GRUB2"):
+            ret = ["600x480","800x600","1024x768"]
+            return ret
+        return ret
+
+    def _get_valid_video_quality(self, bootloader=BOOTLOADERS.DEFAULT_BOOTLOADER):
+        ret = []
+        if bootloader.upper() == 'LILO':
+            ret = ['low','med','hight']
+        elif bootloader.upper() == 'GRUB2':
+            ret = ['med']
+        return ret
+            
     
     def populate_pickers(self, bootloader):
         # populate the targets.
-        partitions = FSTAB.list_all_system_partitions()
-        drives = FSTAB.list_all_system_drives()
-        if bootloader == "LILO":
-            targets = partitions
-            targets.extend(drives)
-            targets.sort()
-            self.targetpicker.set_options(targets)
-            self.videosizepicker.set_options([
-                "640x480","800x600","1024x768"
-                ])
-            self.videoqualitypicker.set_options(["low", "med", "high"])
-        elif bootloader == "GRUB2":
-            self.targetpicker.set_options(drives)
-            self.videoqualitypicker.set_options(["med"])
-        self.videosizepicker.set_value("800x600")
-        self.videoqualitypicker.set_value("med")
+        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
         return self.targetpicker.reset_value()        

modules/tuisupport/widgets.py

 		parent = parent)
 	self.set_options(options)
         self.set_focus('body')
-        self._selection = None
+	if self.choices:
+	    self._selection = self.choices[0].original_widget.get_label()
 
     def set_options(self, options):
 	_grp = []
 import logging
 from optparse import OptionParser
 
-utils.start_logger()
 logger = logging.getLogger('vasm')
 
 _ = utils._
             return
         @utils.launch_external_gui
         def run_as_root():
-            proc = sp.Popen(["vsuper","python", "panedui.py"])
+            # find the command for this process
+            script = os.path.abspath(__file__)
+            proc = sp.Popen(["vsuper","python", script])
             proc.communicate()
         logger.info("Escalating privileges and re-launching vasm.")
         run_as_root()
             return False
         return True
 
-def _get_logger_level(level):
-    """ return the proper logger level for the specified level"""
-    levels = {'0':logging.CRITICAL,
-        '1':logging.FATAL,
-        '2':logging.ERROR,
-        '3':logging.INFO,
-        '4':logging.DEBUG}
-    return levels[level] or levels['4']
+def main():
+    logger.info("Starting vasm GTK+2 UI as uid=%s"% os.geteuid())
+    gtk.gdk.threads_init()
+    gobject.threads_init()
+    w = VASM()
+    w.show_all()
+    gtk.main()
 
 if __name__ == '__main__':
     # process commandline options
     (options, args) = parser.parse_args()
     
     if options.verbose is not None:
-        logger.setLevel(_get_logger_level(options.verbose))
-    # otherwide, it defaults to info
-    # start the logging
-    logger.info("Starting vasm Gtk+2 UI as uid=%s"% os.geteuid())
-    gtk.gdk.threads_init()
-    gobject.threads_init()
-    w = VASM()
-    w.show_all()
-    gtk.main()
+        logger.setLevel(logging.DEBUG)
+    main()
+
 import logging
 
 _ = utils._
-utils.start_logger()
+
 logger = logging.getLogger('vasm')
 
 palette = widgets.palette
         self.parent._GO_TO_ROOT = True
         raise urwid.ExitMainLoop
         self.parent._mainloop.screen.stop()
-        cmd = "/bin/vsuper python /home/vluser/devel/vasm/tvasm.py"
-        proc = sp.Popen(cmd.split())
+        script = os.path.abspath(__file__)
+        proc = sp.popen(['/bin/vsuper','python', script])
+        proc.communicate()
         raise urwid.ExitMainLoop
-        proc.communicate()
     
     def do_popup_message(self, dialog):
         """ Pass a message to the parent so it pops up on the screen"""
         '4':logging.DEBUG}
     return levels[level] or levels['4']
 
-if __name__ == '__main__':
-    # process commandline options
-    parser = OptionParser()
-    parser.add_option("-v", "--verbose", dest="verbose",
-        help = "Verbosity level")
-    (options, args) = parser.parse_args()
-    
-    if options.verbose is not None:
-        logger.setLevel(_get_logger_level(options.verbose))
-    # otherwide, it defaults to info
+def main():
     # start the logging
     logger.info("Starting vasm urwid interface as uid=%s"% os.geteuid())
-
     wbad = urwid.SolidFill()
     # Get the right palette
     if os.getenv("DISPLAY"):
         proc = sp.Popen("clear")
         proc.communicate()
         print _("You must enter the root password to access the administrative settings.")
-        print ""
-        proc = sp.Popen(["su","-c" ,
-        os.path.join(os.getcwd(), "tvasm.py")])
+        script = os.path.abspath(__file__)
+        proc = sp.Popen(["su","-c" ,script])
         proc.communicate()
     sys.exit()
 
+    
+    
+
+if __name__ == '__main__':
+    # process commandline options
+    parser = OptionParser()
+    parser.add_option("-v", "--verbose", dest="verbose",
+        help = "Verbosity level")
+    (options, args) = parser.parse_args()
+    
+    if options.verbose is not None:
+        logger.setLevel(_get_logger_level(options.verbose))
+    # otherwide, it defaults to info
+    main()
+
+#!/usr/bin/env python
+
+#    This file is part of VASM.
+#
+#    VASM is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    VASM is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
+
+__author__ = "Moises Henriquez"
+__author_email__ = "moc.liamg@xnl.E0M"[::-1]
+
+# vasm launcher script.
+import os
+import logging
+from optparse import OptionParser
+
+def start_logger():
+    logger = logging.getLogger('vasm')
+    hdlr = logging.FileHandler('/var/log/vasm.log')
+    formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
+    hdlr.setFormatter(formatter)
+    logger.addHandler(hdlr)
+    logger.setLevel(logging.ERROR)
+
+def get_logger_level(level):
+    """ return the proper logger level for the specified level"""
+    levels = {'0':logging.CRITICAL,
+        '1':logging.FATAL,
+        '2':logging.ERROR,
+        '3':logging.INFO,
+        '4':logging.DEBUG}
+    return levels[level] or levels['4']
+
+def launch_tui():
+    import tvasm
+    return tvasm.main()
+
+def launch_gui():
+    import panedui
+    return panedui.main()
+
+def main():
+    if os.getenv("DISPLAY"):
+        return launch_gui()
+    return launch_tui()
+
+if __name__ == "__main__":
+     # process commandline options
+    start_logger()
+    logger = logging.getLogger('vasm')
+    parser = OptionParser()
+    parser.add_option("-v", "--verbose", dest="verbose",
+                      help = "Verbosity level [ 0 - 4 ].")
+    parser.add_option('-i','--interface', dest='interface',
+                      help=''.join(('Interface to be  launched [ gui or tui ].', '  '
+                                   'If nothing is specified, it will default to whatever is available')))
+    (options, args) = parser.parse_args()
+    
+    if options.verbose is not None:
+        logger.setLevel(get_logger_level(options.verbose))
+    if options.interface is None:
+        main()
+    elif options.interface == 'tui':
+        launch_tui()
+    elif options.interface == 'gui':
+        launch_gui()
+    
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.