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

  1. import iutil
  2. import os
  3. import isys
  4. from snack import *
  5. from textw.constants import *
  6. from translate import _
  7.  
  8. class PartitionMethod:
  9.     def __call__(self, screen, todo):
  10.     if todo.instClass.partitions:
  11.         todo.skipFdisk = 1
  12.         return INSTALL_NOOP
  13.  
  14.     rc = ButtonChoiceWindow(screen, _("Disk Setup"),
  15.         _("Disk Druid is a tool for partitioning and setting up mount "
  16.           "points. It is designed to be easier to use than Linux's "
  17.           "traditional disk partitioning sofware, fdisk, as well "
  18.           "as more powerful. However, there are some cases where fdisk "
  19.           "may be preferred.\n"
  20.           "\n"
  21.           "Which tool would you like to use?"),
  22.         [ (_("Disk Druid"), "dd") , (_("fdisk"), "fd"), 
  23.           (_("Back"), "back") ], width = 50)
  24.  
  25.     if rc == "back":
  26.         return INSTALL_BACK
  27.     elif rc == "dd":
  28.         todo.skipFdisk = 1
  29.     else:
  30.         todo.skipFdisk = 0
  31.  
  32.     return INSTALL_OK
  33.  
  34. class ManualPartitionWindow:
  35.     def __call__(self, screen, todo):
  36.     from newtpyfsedit import fsedit        
  37.  
  38.     if todo.skipFdisk:
  39.             return INSTALL_NOOP
  40.     
  41.     driveNames = todo.fstab.driveList()
  42.     drives = todo.fstab.drivesByName()
  43.  
  44.     choices = []
  45.     haveEdited = 0
  46.  
  47.     for device in driveNames:
  48.         descrip = drives[device]
  49.         if descrip:
  50.         choices.append("/dev/%s - %s" % (device, descrip))
  51.         else:
  52.         choices.append("/dev/%s" % (device,))
  53.  
  54.         button = None
  55.     while button != "done" and button != "back":
  56.         (button, choice) = \
  57.          ListboxChoiceWindow(screen, _("Disk Setup"),
  58.         _("To install Red Hat Linux, you must have at least one "
  59.              "partition of 150 MB dedicated to Linux. We suggest "
  60.              "placing that partition on one of the first two hard "
  61.              "drives in your system so you can boot into Linux "
  62.              "with LILO."), choices,
  63.         [ (_("Done"), "done") , (_("Edit"), "edit"), 
  64.           (_("Back"), "back") ], width = 50)
  65.  
  66.         if button != "done" and button != "back":
  67.         # free our fd's to the hard drive -- we have to 
  68.         # fstab.rescanDrives() after this or bad things happen!
  69.         if not haveEdited:
  70.             todo.fstab.setReadonly(1)
  71.             todo.fstab.closeDrives()
  72.         haveEdited = 1
  73.         device = driveNames[choice]
  74.         screen.suspend ()
  75.         if os.access("/sbin/fdisk", os.X_OK):
  76.             path = "/sbin/fdisk"
  77.         else:
  78.             path = "/usr/sbin/fdisk"
  79.                     
  80.                 try:
  81.                     isys.makeDevInode(device, '/tmp/' + device)
  82.                 except:
  83.                     # XXX FIXME
  84.                     pass
  85.         iutil.execWithRedirect (path, [ path, "/tmp/" + device ],
  86.                     ignoreTermSigs = 1)
  87.                 try:
  88.                     os.remove ('/tmp/' + device)
  89.                 except:
  90.                     # XXX fixme
  91.                     pass
  92.         screen.resume ()
  93.  
  94.     todo.fstab.rescanPartitions()
  95.  
  96.     if button == "back":
  97.         return INSTALL_BACK
  98.  
  99.     return INSTALL_OK
  100.  
  101. class AutoPartitionWindow:
  102.     def __call__(self, screen, todo):
  103.     druid = None
  104.  
  105.     if todo.instClass.partitions:
  106.         druid = \
  107.         todo.fstab.attemptPartitioning(todo.instClass.partitions,
  108.                            todo.instClass.clearParts)
  109.  
  110.     if not druid:
  111.         # auto partitioning failed
  112.         todo.fstab.setRunDruid(1)
  113.         return
  114.  
  115.     if not todo.getPartitionWarningText():
  116.         todo.fstab.setRunDruid(0)
  117.         todo.fstab.setDruid(druid, todo.instClass.raidList)
  118.  
  119.         # sets up lilo for raid boot partitions during kickstart
  120.         todo.lilo.allowLiloLocationConfig(todo.fstab)
  121.  
  122.         todo.fstab.formatAllFilesystems()
  123.         todo.instClass.addToSkipList("format")
  124.         return
  125.  
  126.     (rc, choice) = ListboxChoiceWindow(screen, _("Automatic Partitioning"),
  127.         _("%s\n\nIf you don't want to do this, you can continue with "
  128.           "this install by partitioning manually, or you can go back "
  129.           "and perform a fully customized installation.") % 
  130.             (todo.getPartitionWarningText(), ),
  131.         [_("Continue"), _("Manually partition")], 
  132.         buttons = basicButtons, default = _("Continue"))
  133.  
  134.     if (rc == "back"): 
  135.         # This happens automatically when we go out of scope, but it's
  136.         # important so let's be explicit
  137.         druid = None
  138.         return INSTALL_BACK
  139.  
  140.         if (choice == 1):
  141.             # if druid wasn't running, must have been in autopartition mode
  142.             # clear fstab cache so we don't get junk from attempted
  143.             # autopartitioning
  144.             #
  145.             # msf - this is not working becaue setRunDruid is not
  146.             #       called before we get here, unlike in the GUI case
  147.             #
  148.             #       Set clearcache - may need to be 1 to
  149.             #       avoid autopartitioning attempt above from
  150.             #       polluting manual partitioning with invalid
  151.             #       fstab entries
  152.             #
  153. #           clearcache = not todo.fstab.getRunDruid()
  154.             clearcache = 1
  155.         todo.fstab.setRunDruid(1)
  156.         del druid
  157.         todo.fstab.rescanPartitions(clearcache)
  158.         todo.instClass.removeFromSkipList("format")
  159.     else:
  160.         todo.fstab.setRunDruid(0)
  161.         todo.fstab.setDruid(druid, todo.instClass.raidList)
  162.         todo.lilo.allowLiloLocationConfig(todo.fstab)
  163.         todo.fstab.formatAllFilesystems()
  164.         todo.instClass.addToSkipList("format")
  165.  
  166.         return INSTALL_OK
  167.         
  168. class PartitionWindow:
  169.     def __call__(self, screen, todo):
  170.     dir = INSTALL_NOOP
  171.     if todo.fstab.getRunDruid():
  172.         dir = todo.fstab.runDruid()
  173.  
  174.     # runDruid returns None when it means INSTALL_OK
  175.         if not dir:
  176.         dir = INSTALL_OK
  177.  
  178.         return dir
  179.  
  180. class TurnOnSwapWindow:
  181.  
  182.     beenTurnedOn = 0
  183.  
  184.     def __call__(self, screen, todo):
  185.     if self.beenTurnedOn or (iutil.memInstalled() > 34000):
  186.         return INSTALL_NOOP
  187.  
  188.         if not todo.instClass.earlySwapOn:
  189.         rc = ButtonChoiceWindow(screen, _("Low Memory"),
  190.                _("As you don't have much memory in this machine, we "
  191.              "need to turn on swap space immediately. To do this "
  192.              "we'll have to write your new partition table to the "
  193.              "disk immediately. Is that okay?"),
  194.                [ (_("Yes"), "yes"), (_("No"), "back") ], width = 50)
  195.  
  196.         if (rc == "back"):
  197.         return INSTALL_BACK
  198.  
  199.         todo.fstab.savePartitions ()
  200.     todo.fstab.turnOnSwap()
  201.     todo.ddruidAlreadySaved = 1
  202.     self.beenTurnedOn = 1
  203.  
  204.     return INSTALL_OK
  205.  
  206. class FormatWindow:
  207.     def __call__(self, screen, todo):
  208.         tb = TextboxReflowed (55,
  209.                               _("What partitions would you like to "
  210.                                 "format? We strongly suggest formatting "
  211.                                 "all of the system partitions, including "
  212.                                 "/, /usr, and /var. There is no need to "
  213.                                 "format /home or /usr/local if they have "
  214.                                 "already been configured during a "
  215.                                 "previous install."))
  216.  
  217.     mounts = todo.fstab.mountList()
  218.         height = min (screen.height - 12, len (mounts))
  219.         
  220.         ct = CheckboxTree(height = height)
  221.  
  222.     gotOne = 0
  223.     for (mount, dev, fstype, format, size) in mounts:
  224.             if fstype == "ext2":
  225.         gotOne = 1
  226.                 ct.append("/dev/%s   %s" % (dev, mount), dev, format)
  227.  
  228.     if not gotOne: return INSTALL_NOOP
  229.  
  230.         cb = Checkbox (_("Check for bad blocks during format"),
  231.             todo.fstab.getBadBlockCheck())
  232.  
  233.         bb = ButtonBar (screen, ((_("OK"), "ok"), (_("Back"), "back")))
  234.  
  235.         g = GridForm (screen, _("Choose Partitions to Format"), 1, 4)
  236.         g.add (tb, 0, 0, (0, 0, 0, 1))
  237.         g.add (ct, 0, 1)
  238.         g.add (cb, 0, 2, (0, 1, 0, 1))
  239.         g.add (bb, 0, 3, growx = 1)
  240.  
  241.         result = g.runOnce()
  242.  
  243.     for (mount, dev, fstype, format, size) in mounts:
  244.         todo.fstab.setFormatFilesystem(dev, 0)
  245.  
  246.         for dev in ct.getSelection():
  247.         todo.fstab.setFormatFilesystem(dev, 1)
  248.  
  249.         todo.fstab.setBadBlockCheck(cb.selected ())
  250.  
  251.         rc = bb.buttonPressed (result)
  252.  
  253.         if rc == "back":
  254.             return INSTALL_BACK
  255.         return INSTALL_OK
  256.  
  257.  
  258. class LoopSizeWindow:
  259.  
  260.     def __call__(self, screen, todo):
  261.     if not todo.fstab.rootOnLoop():
  262.         return INSTALL_NOOP
  263.  
  264.     avail = apply(isys.spaceAvailable, todo.fstab.getRootDevice())
  265.     (size, swapSize) = todo.fstab.getLoopbackSize()
  266.     if not size:
  267.         size = avail / 2
  268.         swapSize = 32
  269.  
  270.     sizeEntry = Entry(6, "%d" % (size,))
  271.     swapSizeEntry = Entry(6, "%d" % (swapSize,))
  272.  
  273.     while 1:
  274.         (rc, ent) = EntryWindow(screen, _("Root Filesystem Size"),
  275.         _("You've chosen to put your root filesystem in a file on "
  276.           "an already-existing DOS or Windows filesystem. How large, "
  277.           "in megabytes, should would you like the root filesystem "
  278.           "to be, and how much swap space would you like? They must "
  279.           "total less then %d megabytes in size." % (avail, )),
  280.             [ ( _("Root filesystem size"), sizeEntry ),
  281.               ( _("Swap space"), swapSizeEntry ) ],
  282.             buttons = [ (_("OK"), "ok"), (_("Back"), "back") ] )
  283.  
  284.         if rc == "back": return INSTALL_BACK
  285.  
  286.         try:
  287.         size = int(sizeEntry.value())
  288.         swapSize = int(swapSizeEntry.value())
  289.         except:
  290.         ButtonChoiceWindow(screen, _("Bad Size"),
  291.             _("The size you enter must be a number."),
  292.             buttons = [ _("OK") ])
  293.         continue
  294.  
  295.         if size + swapSize >= avail:
  296.         ButtonChoiceWindow(screen, _("Bad Size"),
  297.             _("The total size must be smaller then the amount of "
  298.               "free space on the disk, which is %d megabytes."
  299.                 % (avail, )),
  300.             buttons = [ _("OK") ])
  301.         continue
  302.  
  303.         break
  304.  
  305.     todo.fstab.setLoopbackSize(size, swapSize)
  306.  
  307.     return INSTALL_NOOP
  308.     
  309.