home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / iw / lilo.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  8.2 KB  |  291 lines

  1. from iw import *
  2. from gtk import *
  3. from translate import _
  4. from xpms import SMALL_CHECK
  5. import GdkImlib
  6.  
  7. class LiloWindow (InstallWindow):
  8.     foo = GdkImlib.create_image_from_xpm (SMALL_CHECK)
  9.     foo.render()
  10.     checkMark = foo.make_pixmap()
  11.     del foo
  12.  
  13.     def __init__ (self, ics):
  14.     InstallWindow.__init__ (self, ics)
  15.  
  16.         ics.readHTML ("lilo")
  17.  
  18.         ics.setTitle (_("Lilo Configuration"))
  19.         ics.setNextEnabled (1)
  20.         self.type = None
  21.         self.bootdisk = None
  22.         self.lilo = None
  23.  
  24.     def getNext (self):
  25.         # XXX
  26.         if not self.bootdisk: return None
  27.  
  28.         if self.bootdisk.get_active ():
  29.             self.todo.bootdisk = 1
  30.         else:
  31.             self.todo.bootdisk = 0
  32.  
  33.     if self.lilo.get_active ():
  34.         self.todo.lilo.setDevice(None)
  35.     elif self.todo.lilo.allowLiloLocationConfig(self.todo.fstab):
  36.         if self.mbr.get_active ():
  37.         self.todo.lilo.setDevice("mbr")
  38.         else:
  39.         self.todo.lilo.setDevice("partition")
  40.  
  41.     images = {}
  42.     default = None
  43.     linuxDevice = None
  44.     for index in range(self.numImages):
  45.         device = self.imageList.get_text(index, 1)[5:]
  46.         type = self.types[index]
  47.         label = self.imageList.get_text(index, 3)
  48.         images[device] = (label, type)
  49.         if self.default == index:
  50.         default = label
  51.         if type == 2:
  52.         linuxDevice = label
  53.  
  54.     if not default:
  55.         default = linuxDevice
  56.  
  57.     self.todo.lilo.setLiloImages(images)
  58.     self.todo.lilo.setLinear(self.linearCheck.get_active())
  59.     self.todo.lilo.setAppend(self.appendEntry.get_text())
  60.     self.todo.lilo.setDefault(default)
  61.  
  62.     def typeName(self, type):
  63.     if (type == 2):
  64.         return "Linux Native"
  65.     elif (type == 1):
  66.         return "DOS/Windows"
  67.     elif (type == 4):    
  68.         return "OS/2 / Windows NT"
  69.     else:
  70.         return "Other"
  71.  
  72.     def toggled (self, widget, *args):
  73.         if widget.get_active ():
  74.         state = FALSE
  75.         else:
  76.         state = TRUE
  77.  
  78.     for n in [self.mbr, self.part, self.appendEntry, self.editBox, 
  79.           self.imageList, self.liloLocationBox, self.radioBox ]:
  80.             n.set_sensitive (state)
  81.  
  82.     if state and not \
  83.         self.todo.lilo.allowLiloLocationConfig(self.todo.fstab):
  84.         self.liloLocationBox.set_sensitive(0)
  85.         self.mbr.set_sensitive(0)
  86.         self.part.set_sensitive(0)
  87.         self.linearCheck.set_sensitive(0)
  88.  
  89.     def labelUpdated(self, *args):
  90.     index = self.imageList.selection[0]
  91.     device = self.imageList.get_text(index, 1)
  92.  
  93.     label = self.labelEntry.get_text()
  94.     self.imageList.set_text(index, 3, label)
  95.  
  96.         if label:
  97.             self.defaultCheck.set_sensitive (TRUE)
  98.         else:
  99.             self.defaultCheck.set_sensitive (FALSE)
  100.  
  101.     def defaultUpdated(self, *args):
  102.     if self.ignoreSignals: return
  103.  
  104.     index = self.imageList.selection[0]
  105.  
  106.     if self.defaultCheck.get_active():
  107.         if self.default != None:
  108.         self.imageList.set_text(self.default, 0, "")
  109.  
  110.         self.imageList.set_pixmap(index, 0, self.checkMark)
  111.         self.default = index
  112.     else:
  113.         self.imageList.set_text(index, 0, "")
  114.         self.default = None
  115.  
  116.     def labelSelected(self, *args):
  117.     index = self.imageList.selection[0]
  118.     device = self.imageList.get_text(index, 1)
  119.     type = self.imageList.get_text(index, 2)
  120.     label = self.imageList.get_text(index, 3)
  121.  
  122.     self.deviceLabel.set_text(_("Partition") + ": " + device)
  123.     device = device[5:]
  124.  
  125.     self.typeLabel.set_text(_("Type") + ":" + type)
  126.     self.labelEntry.set_text(label)
  127.  
  128.         if not label:
  129.             self.defaultCheck.set_sensitive (FALSE)
  130.  
  131.         self.ignoreSignals = 1
  132.     if index == self.default:
  133.         self.defaultCheck.set_active(1)
  134.     else:
  135.         self.defaultCheck.set_active(0)
  136.         self.ignoreSignals = 0
  137.  
  138.     def getScreen (self):
  139.     if self.todo.fstab.rootOnLoop():
  140.         self.todo.bootdisk = 1
  141.         return None
  142.  
  143.         if not self.todo.fstab.setupFilesystems:
  144.             return None
  145.         
  146.     (imageList, defaultLabel) = \
  147.         self.todo.lilo.getLiloImages(self.todo.fstab)
  148.         self.ignoreSignals = 0
  149.  
  150.     if self.todo.fstab.mountList()[0][0] != '/': return None
  151.  
  152.     bootpart = self.todo.fstab.getBootDevice()
  153.     boothd = self.todo.fstab.getMbrDevice()
  154.             
  155.         format = "/dev/%s"
  156.  
  157.         self.radioBox = GtkTable(2, 6)
  158.         self.radioBox.set_border_width (5)
  159.         
  160.     spacer = GtkLabel("")
  161.     spacer.set_usize(10, 1)
  162.     self.radioBox.attach(spacer, 0, 1, 2, 4, FALSE)
  163.  
  164.     label = GtkLabel(_("Install LILO boot record on:"))
  165.     label.set_alignment(0.0, 0.5)
  166.         self.liloLocationBox = GtkVBox (FALSE, 0)
  167.     self.liloLocationBox.pack_start(label)
  168.     self.radioBox.attach(self.liloLocationBox, 0, 2, 1, 2)
  169.  
  170.         self.mbr = GtkRadioButton(None, 
  171.         ("/dev/%s %s" % (boothd, _("Master Boot Record (MBR)"))))
  172.     self.radioBox.attach(self.mbr, 1, 2, 2, 3)
  173.         self.part = GtkRadioButton(self.mbr, 
  174.         ("/dev/%s %s" % (bootpart, 
  175.         _("First sector of boot partition"))))
  176.     self.radioBox.attach(self.part, 1, 2, 3, 4)
  177.  
  178.     self.linearCheck = GtkCheckButton(
  179.         _("Use linear mode (needed for some SCSI drives)"))
  180.     self.linearCheck.set_active(self.todo.lilo.getLinear())
  181.     self.radioBox.attach(self.linearCheck, 0, 2, 4, 5)
  182.  
  183.     if not self.todo.lilo.allowLiloLocationConfig(self.todo.fstab):
  184.         self.liloLocationBox.set_sensitive(0)
  185.         self.mbr.set_sensitive(0)
  186.         self.part.set_sensitive(0)
  187.         self.linearCheck.set_sensitive(0)
  188.  
  189.     label = GtkLabel(_("Kernel parameters") + ":")
  190.     label.set_alignment(0.0, 0.5)
  191.     self.appendEntry = GtkEntry()
  192.     if self.todo.lilo.getAppend():
  193.         self.appendEntry.set_text(self.todo.lilo.getAppend())
  194.     box = GtkHBox(FALSE, 5)
  195.     box.pack_start(label)
  196.     box.pack_start(self.appendEntry)
  197.     alignment = GtkAlignment()
  198.     alignment.set(0.0, 0.5, 0, 1.0)
  199.     alignment.add(box)
  200.     self.radioBox.attach(alignment, 0, 2, 5, 6)
  201.     
  202.         box = GtkVBox (FALSE, 0)
  203.  
  204.         optionBox = GtkVBox (FALSE, 5)
  205.         optionBox.set_border_width (5)
  206.         self.bootdisk = GtkCheckButton (_("Create boot disk"))
  207.         self.bootdisk.set_active (TRUE)
  208.         optionBox.pack_start (self.bootdisk)
  209.  
  210.         self.lilo = GtkCheckButton (_("Do not install LILO"))
  211.         self.lilo.set_active (FALSE)
  212.         self.lilo.connect ("toggled", self.toggled)
  213.         optionBox.pack_start (self.lilo, FALSE)
  214.  
  215.         box.pack_start (optionBox, FALSE)
  216.  
  217.         box.pack_start (GtkHSeparator (), FALSE)
  218.         box.pack_start (self.radioBox, FALSE)
  219.  
  220.     self.imageList = GtkCList (4,
  221.         ( _("Default"), _("Device"), _("Partition type"), _("Boot label")))
  222.  
  223.     sortedKeys = imageList.keys()
  224.     sortedKeys.sort()
  225.     self.numImages = len(sortedKeys)
  226.  
  227.         self.default = None
  228.     count = 0
  229.     self.types = []
  230.     for n in sortedKeys:
  231.         (label, type) = imageList[n]
  232.         self.types.append(type)
  233.         self.imageList.append(("", "/dev/" + n, self.typeName(type), 
  234.                     label))
  235.         if (label == defaultLabel):
  236.         self.default = count
  237.         self.imageList.set_pixmap(count, 0, self.checkMark)
  238.         count = count + 1
  239.  
  240.     self.imageList.connect("select_row", self.labelSelected)
  241.         self.imageList.columns_autosize ()
  242.         self.imageList.column_title_passive (1)
  243.         self.imageList.set_border_width (5)
  244.  
  245.     self.deviceLabel = GtkLabel(_("Partition") + ":")
  246.     self.typeLabel = GtkLabel(_("Type") + ":")
  247.  
  248.     tempBox = GtkHBox(TRUE)
  249.     self.deviceLabel.set_alignment(0.0, 0.0)
  250.     self.typeLabel.set_alignment(0.0, 0.0)
  251.     tempBox.pack_start(self.deviceLabel, FALSE)
  252.     tempBox.pack_start(self.typeLabel, FALSE)
  253.     self.defaultCheck = GtkCheckButton("Default boot image")
  254.     self.defaultCheck.connect("toggled", self.defaultUpdated)
  255.  
  256.     # Alliteration!
  257.     self.labelLabel = GtkLabel(_("Boot label") + ":")
  258.     self.labelEntry = GtkEntry(15)
  259.     self.labelEntry.connect("changed", self.labelUpdated)
  260.  
  261.     tempBox2 = GtkHBox(FALSE, 5)
  262.     self.labelLabel.set_alignment(0.0, 0.5)
  263.     tempBox2.pack_start(self.labelLabel, FALSE)
  264.     tempBox2.pack_start(self.labelEntry, FALSE)
  265.  
  266.     self.editBox = GtkVBox ()
  267.     self.editBox.pack_start (tempBox, FALSE)
  268.     self.editBox.pack_start (self.defaultCheck, FALSE)
  269.     self.editBox.pack_start (tempBox2, FALSE)
  270.     self.editBox.set_border_width (5)
  271.  
  272.         box.pack_start (GtkHSeparator (), FALSE)
  273.         box.pack_start (self.editBox, FALSE)
  274.  
  275.         self.imageList.set_selection_mode (SELECTION_BROWSE)
  276.  
  277.     sw = GtkScrolledWindow ()
  278.     sw.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC)
  279.     sw.add (self.imageList)
  280.         box.pack_start (sw, TRUE)
  281.  
  282.     where = self.todo.lilo.getDevice()
  283.     if not where:
  284.         self.lilo.set_active(1)
  285.     elif where == "mbr":
  286.         self.mbr.set_active(1)
  287.     else:
  288.         self.part.set_active(1)
  289.  
  290.         return box
  291.