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

  1. from gtk import *
  2. from iw import *
  3. from thread import *
  4. import isys
  5. from translate import _
  6. import gui
  7. from fdisk import *
  8. import isys
  9. import iutil
  10.  
  11. class ConfirmPartitionWindow (InstallWindow):
  12.     def __init__ (self, ics):
  13.     InstallWindow.__init__ (self, ics)
  14.  
  15.         self.todo = ics.getToDo ()
  16.         ics.setTitle (_("Confirm Partitioning Selection"))
  17.         ics.readHTML ("partition")
  18.     ics.setNextEnabled (TRUE)
  19.         
  20.     def getScreen (self):
  21.         return self.window
  22.  
  23.     def getPrev (self):
  24.         return PartitionWindow
  25.  
  26. class PartitionWindow (InstallWindow):
  27.     swapon = 0
  28.     def __init__ (self, ics):
  29.     InstallWindow.__init__ (self, ics)
  30.  
  31.         self.todo = ics.getToDo ()
  32.         ics.setTitle (_("Disk Druid"))
  33.         ics.readHTML ("partition")
  34.     ics.setNextEnabled (FALSE)
  35.     self.skippedScreen = 0
  36.         self.swapon = 0
  37.  
  38.     def checkSwap (self):
  39.         if PartitionWindow.swapon or (iutil.memInstalled() > 34000):
  40.         return 1
  41.  
  42.         threads_leave ()
  43.     message = gui.MessageWindow(_("Low Memory"),
  44.            _("As you don't have much memory in this machine, we "
  45.              "need to turn on swap space immediately. To do this "
  46.              "we'll have to write your new partition table to the "
  47.              "disk immediately. Is that okay?"), "okcancel")
  48.  
  49.     if (message.getrc () == 1):
  50.         threads_enter ()
  51.         return 0
  52.  
  53.     self.todo.fstab.savePartitions()
  54.     self.todo.fstab.turnOnSwap(self.todo.intf.waitWindow)
  55.     self.todo.ddruidAlreadySaved = 1
  56.     PartitionWindow.swapon = 1
  57.  
  58.         threads_enter ()
  59.  
  60.         return 1
  61.  
  62.     def getNext (self):
  63.     if not self.running: return 0
  64.     self.todo.fstab.runDruidFinished()
  65.  
  66.         # FIXME
  67.     #if not self.skippedScreen:
  68.         #win = self.todo.ddruid.getConfirm ()
  69.         #if win:
  70.         #bin = GtkFrame (None, _obj = win)
  71.         #bin.set_shadow_type (SHADOW_NONE)
  72.         #window = ConfirmPartitionWindow
  73.         #window.window = bin
  74.         #return window
  75.  
  76.     bootPartition = None
  77.     rootPartition = None
  78.  
  79.         if not self.checkSwap ():
  80.             return PartitionWindow
  81.  
  82.         if self.todo.fstab.rootOnLoop():
  83.             return LoopSizeWindow
  84.  
  85.         return None
  86.  
  87.     def enableCallback (self, value):
  88.         self.ics.setNextEnabled (value)
  89.  
  90.     def getScreen (self):
  91.     self.running = 0
  92.     if not self.todo.fstab.getRunDruid(): return None
  93.     self.running = 1
  94.     return self.todo.fstab.runDruid(self.enableCallback)
  95.  
  96. class LoopSizeWindow(InstallWindow):
  97.     def __init__ (self, ics):
  98.     InstallWindow.__init__ (self, ics)
  99.         ics.readHTML ("loopback")
  100.  
  101.     def getNext (self):
  102.         self.todo.fstab.setLoopbackSize (self.sizeAdj.value, self.swapAdj.value)
  103.  
  104.     def getScreen (self):
  105.         # XXX error check mount that this check tries
  106.         avail = apply(isys.spaceAvailable, self.todo.fstab.getRootDevice())
  107.     (size, swapSize) = self.todo.fstab.getLoopbackSize()
  108.     if not size:
  109.         size = avail / 2
  110.         swapSize = 32
  111.  
  112.         vbox = GtkVBox (FALSE, 5)
  113.         
  114.         label = GtkLabel (
  115.         _("You've chosen to put your root filesystem in a file on "
  116.           "an already-existing DOS or Windows filesystem. How large, "
  117.           "in megabytes, should would you like the root filesystem "
  118.           "to be, and how much swap space would you like? They must "
  119.           "total less then %d megabytes in size." % (avail, )))
  120.         label.set_usize (400, -1)
  121.         label.set_line_wrap (TRUE)
  122.         vbox.pack_start (label, FALSE, FALSE)
  123.  
  124.         # XXX lower is 150
  125.         self.sizeAdj = GtkAdjustment (value = size, lower = 150, upper = avail, step_incr = 1)
  126.         self.sizeSpin = GtkSpinButton (self.sizeAdj, digits = 0)
  127.         self.sizeSpin.set_usize (100, -1)
  128.  
  129.         self.swapAdj = GtkAdjustment (value = swapSize, lower = 16, upper = avail, step_incr = 1)
  130.         self.swapSpin = GtkSpinButton (self.swapAdj, digits = 0)
  131.         self.swapSpin.set_usize (100, -1)
  132.  
  133.         table = GtkTable ()
  134.  
  135.         label = GtkLabel (_("Root filesystem size:"))
  136.         label.set_alignment (1.0, 0.5)
  137.         table.attach (label, 0, 1, 0, 1, xpadding=5, ypadding=5)
  138.         table.attach (self.sizeSpin, 1, 2, 0, 1, xpadding=5, ypadding=5)
  139.  
  140.         label = GtkLabel (_("Swap space size:"))
  141.         label.set_alignment (1.0, 0.5)
  142.         table.attach (label, 0, 1, 1, 2, xpadding=5, ypadding=5)
  143.         table.attach (self.swapSpin, 1, 2, 1, 2, xpadding=5, ypadding=5)
  144.  
  145.         align = GtkAlignment ()
  146.         align.add (table)
  147.         align.set (0, 0, 0.5, 0.5)
  148.         vbox.pack_start (align, FALSE, FALSE)
  149.  
  150.     self.ics.setNextEnabled (TRUE)
  151.  
  152.         return vbox
  153.         
  154. class AutoPartitionWindow(InstallWindow):
  155.     def __init__ (self, ics):
  156.     InstallWindow.__init__ (self, ics)
  157.  
  158.         self.todo = ics.getToDo ()
  159.         ics.setTitle (_("Automatic Partitioning"))
  160.     ics.setNextEnabled (TRUE)
  161.         self.ics = ics
  162.  
  163.     def getPrev(self):
  164.     self.druid = None
  165.     self.beingDisplayed = 0
  166.  
  167.     def getNext(self):
  168.     if not self.beingDisplayed: return
  169.  
  170.     if not self.__dict__.has_key("manuallyPartition"):
  171.             # if druid wasn't running, must have been in autopartition mode
  172.             # clear fstab cache so we don't get junk from attempted
  173.             # autopartitioning
  174.             clearcache = not self.todo.fstab.getRunDruid()
  175.         self.todo.fstab.setRunDruid(1)
  176.             #print "Rescanning partitions 1 - ", clearcache
  177.             self.todo.fstab.rescanPartitions(clearcache)
  178.         self.todo.instClass.removeFromSkipList("format")
  179.     elif self.manuallyPartition.get_active():
  180.             del self.druid
  181.             # see comment above about clearing cache
  182.             clearcache = not self.todo.fstab.getRunDruid()
  183.         self.todo.fstab.setRunDruid(1)
  184.             #print "Rescanning partitions 2 - ", clearcache
  185.         self.todo.fstab.rescanPartitions(clearcache)
  186.         self.todo.instClass.removeFromSkipList("format")
  187.     else:
  188.         self.todo.fstab.setRunDruid(0)
  189.         self.todo.fstab.setDruid(self.druid, self.todo.instClass.raidList)
  190.         self.todo.fstab.formatAllFilesystems()
  191.         self.todo.instClass.addToSkipList("format")
  192.  
  193.     self.beingDisplayed = 0
  194.         
  195.     return None
  196.  
  197.     def __init__(self, todo):
  198.     InstallWindow.__init__(self, todo)
  199.     self.druid = None
  200.     self.beingDisplayed = 0
  201.  
  202.     def getScreen (self):   
  203.         from installpath import InstallPathWindow
  204.  
  205.         if (InstallPathWindow.fdisk and
  206.             InstallPathWindow.fdisk.get_active ()):
  207.         return None
  208.         
  209.         # XXX hack
  210.         if self.todo.instClass.clearType:
  211.             self.ics.readHTML (self.todo.instClass.clearType)
  212.  
  213.     todo = self.todo
  214.     self.druid = None
  215.  
  216.     if self.todo.instClass.partitions:
  217.         self.druid = \
  218.         todo.fstab.attemptPartitioning(todo.instClass.partitions,
  219.                            todo.instClass.clearParts)
  220.     self.ics.setNextEnabled (TRUE)
  221.  
  222.     if not self.druid:
  223.         # auto partitioning failed
  224.         self.todo.fstab.setRunDruid(1)
  225.         return
  226.  
  227.     if not todo.getPartitionWarningText():
  228.         self.todo.fstab.setRunDruid(0)
  229.         self.todo.fstab.setDruid(self.druid)
  230.         self.todo.fstab.formatAllFilesystems()
  231.         self.todo.instClass.addToSkipList("format")
  232.         return
  233.  
  234.     label = \
  235.            GtkLabel(_("%s\n\nIf you don't want to do this, you can continue with "
  236.           "this install by partitioning manually, or you can go back "
  237.           "and perform a fully customized installation.") % 
  238.             (_(todo.getPartitionWarningText()), ))
  239.  
  240.     label.set_line_wrap(TRUE)
  241.     label.set_alignment(0.0, 0.0)
  242.     label.set_usize(400, -1)
  243.  
  244.         box = GtkVBox (FALSE)
  245.     box.pack_start(label, FALSE)
  246.         box.set_border_width (5)
  247.  
  248.         radioBox = GtkVBox (FALSE)
  249.     self.continueChoice = GtkRadioButton (None, _("Remove data"))
  250.     radioBox.pack_start(self.continueChoice, FALSE)
  251.     self.manuallyPartition = GtkRadioButton(
  252.         self.continueChoice, _("Manually partition"))
  253.     radioBox.pack_start(self.manuallyPartition, FALSE)
  254.  
  255.     align = GtkAlignment()
  256.     align.add(radioBox)
  257.     align.set(0.5, 0.5, 0.0, 0.0)
  258.  
  259.     box.pack_start(align, TRUE, TRUE)
  260.     box.set_border_width (5)
  261.     self.beingDisplayed = 1
  262.     return box
  263.  
  264.  
  265.  
  266.