summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--iw/partition_gui.py126
-rw-r--r--partitioning.py116
-rw-r--r--textw/partition_text.py99
3 files changed, 138 insertions, 203 deletions
diff --git a/iw/partition_gui.py b/iw/partition_gui.py
index 618f3be41..885d45bd2 100644
--- a/iw/partition_gui.py
+++ b/iw/partition_gui.py
@@ -585,7 +585,6 @@ class PartitionWindow(InstallWindow):
if partition:
self.diskStripeGraph.selectSlice(partition)
-
def newCB(self, widget):
# create new request of size 1M
request = PartitionSpec(fileSystemTypeGetDefault(), REQUEST_NEW, 1)
@@ -901,59 +900,9 @@ class PartitionWindow(InstallWindow):
def deleteCb(self, widget):
node = self.tree.selection[0]
partition = self.tree.node_get_row_data (node)
- if partition == None:
- dialog = GnomeWarningDialog(_("You must first select a partition"),
- parent=self.parent)
- dialog.set_position(WIN_POS_CENTER)
- dialog.run()
- return
- elif type(partition) == type("RAID"):
- # XXXX evil way to reference RAID device requests!!
- request = self.partitions.getRequestByDeviceName(partition)
- if request:
- self.partitions.removeRequest(request)
- else: # shouldn't happen
- raise ValueError, "Deleting a non-existent partition"
- elif partition.type & parted.PARTITION_FREESPACE:
- dialog = GnomeWarningDialog(_("You cannot remove free space."),
- parent=self.parent)
- dialog.set_position(WIN_POS_CENTER)
- dialog.run()
- return
- else:
- # see if device is in our partition requests, remove
- request = self.partitions.getRequestByDeviceName(get_partition_name(partition))
- if request:
- if request.type == REQUEST_PROTECTED:
- dialog = GnomeWarningDialog(_("You cannot remove this "
- "partition, as it is holding the data for the "
- "hard drive install."))
- dialog.set_position(WIN_POS_CENTER)
- dialog.run()
- return
-
- if self.partitions.isRaidMember(request):
- dialog = GnomeWarningDialog(_("You cannot remove this "
- "partition, as it is part of a RAID device."))
- dialog.set_position(WIN_POS_CENTER)
- dialog.run()
- return
-
- self.partitions.removeRequest(request)
- if request.type == REQUEST_PREEXIST:
- # get the drive
- drive = get_partition_drive(partition)
-
- if partition.type & parted.PARTITION_EXTENDED:
- deleteAllLogicalPartitions(partition, self.partitions)
-
- delete = DeleteSpec(drive, partition.geom.start, partition.geom.end)
- self.partitions.addDelete(delete)
- else: # shouldn't happen
- raise ValueError, "Deleting a non-existenent partition"
- # cheating
- self.refresh()
+ if doDeletePartitionByRequest(self.intf, self.partitions, partition):
+ self.refresh()
def clearTree(self):
node = self.tree.node_nth(0)
@@ -964,6 +913,9 @@ class PartitionWindow(InstallWindow):
self.tree.set_selection_mode (SELECTION_BROWSE)
def resetCb(self, *args):
+ if not confirmResetPartitionState(self.intf):
+ return
+
self.diskStripeGraph.shutDown()
self.newFsset = self.fsset.copy()
self.tree.freeze()
@@ -992,72 +944,18 @@ class PartitionWindow(InstallWindow):
def editCb(self, widget):
node = self.tree.selection[0]
- partition = self.tree.node_get_row_data (node)
-
- if partition == None:
- dialog = GnomeWarningDialog(_("You must first select an existing "
- "partition or free space to edit."),
- parent=self.parent)
- dialog.set_position(WIN_POS_CENTER)
- dialog.run()
- return
- elif type(partition) == type("RAID"):
- # XXXX evil way to reference RAID device requests!!
- request = self.partitions.getRequestByDeviceName(partition)
- if request:
- self.editRaidDevice(request)
- return
- else:
- raise ValueError, "Editting a non-existenent partition"
- elif partition.type & parted.PARTITION_FREESPACE:
-
- # create new request of size 1M
- request = PartitionSpec(fileSystemTypeGetDefault(), REQUEST_NEW,
- start = start_sector_to_cyl(partition.geom.disk.dev,
- partition.geom.start),
- end = end_sector_to_cyl(partition.geom.disk.dev,
- partition.geom.end),
- drive = [get_partition_drive(partition)])
- self.editPartitionRequest(request)
- return
-
- elif (partition.fs_type == None) or (partition.fs_type and not partition.fs_type.name):
- dialog = GnomeWarningDialog(_("You cannot edit partitions without "
- "a filesystem type."),
- parent = self.parent)
- dialog.set_position(WIN_POS_CENTER)
- dialog.run()
- return
-
- elif partition.type & parted.PARTITION_EXTENDED:
- return
-
- # otherwise this is a "normal" partition to edit
- request = self.partitions.getRequestByDeviceName(get_partition_name(partition))
+ part = self.tree.node_get_row_data (node)
+ (type, request) = doEditPartitionByRequest(self.intf, self.partitions, part)
if request:
- if request.type == REQUEST_PROTECTED:
- dialog = GnomeWarningDialog(_("You cannot remove this "
- "partition, as it is holding the data for the "
- "hard drive install."))
- dialog.set_position(WIN_POS_CENTER)
- dialog.run()
- return
-
- if self.partitions.isRaidMember(request):
- dialog = GnomeWarningDialog(_("You cannot edit this "
- "partition, as it is part of a RAID device."))
- dialog.set_position(WIN_POS_CENTER)
- dialog.run()
- return
+ if type == "RAID":
+ self.editRaidRequest(request)
else:
self.editPartitionRequest(request)
- else:
- raise ValueError, "Editing a non-existent partition"
- def editRaidDevice(self, raidrequest):
+ def editRaidRequest(self, raidrequest):
#
- # start of editRaidDevice
+ # start of editRaidRuquest
#
dialog = GnomeDialog(_("Make Raid Device"))
dialog.set_parent(self.parent)
@@ -1220,7 +1118,7 @@ class PartitionWindow(InstallWindow):
def makeraidCB(self, widget):
request = PartitionSpec(fileSystemTypeGetDefault(), REQUEST_RAID, 1)
- self.editRaidDevice(request)
+ self.editRaidRequest(request)
def getScreen (self, fsset, diskset, partitions, intf):
self.fsset = fsset
diff --git a/partitioning.py b/partitioning.py
index 0c804904b..82836c96e 100644
--- a/partitioning.py
+++ b/partitioning.py
@@ -922,3 +922,119 @@ def autoCreatePartitionRequests(autoreq):
requests.append(newrequest)
return requests
+
+def confirmDeleteRequest(intf, request):
+ if request.device:
+ errmsg = _("You are about to delete the /dev/%s partition.\n\nAre you sure?" % request.device)
+ else:
+ errmsg = _("Are you sure you want to delete this partition?")
+
+ rc = intf.messageWindow(_("Confirm Delete"), errmsg, type="yesno")
+ return rc
+
+def confirmResetPartitionState(intf):
+ rc = intf.messageWindow(_("Confirm Reset"),
+ _("Are you sure you want to reset the "
+ "partition table to its original state?"),
+ type="yesno")
+ return rc
+
+#
+# handle deleting a partition - pass in the list of requests and the
+# partition to be deleted
+#
+def doDeletePartitionByRequest(intf, requestlist, partition):
+ if partition == None:
+ intf.messageWindow(_("Unable To Remove"),
+ _("You must first select a partition to remove."))
+ return 0
+ elif type(partition) == type("RAID"):
+ device = partition
+ elif partition.type & parted.PARTITION_FREESPACE:
+ intf.messageWindow(_("Unable To Remove"),
+ _("You cannot remove free space."))
+ return 0
+ else:
+ device = get_partition_name(partition)
+
+ # see if device is in our partition requests, remove
+ request = requestlist.getRequestByDeviceName(get_partition_name(partition))
+ if request:
+ if request.type == REQUEST_PROTECTED:
+ intf.messageWindow(_("Unable To Remove"),
+ _("You cannot remove this "
+ "partition, as it is holding the data for "
+ "the hard drive install."))
+ return 0
+
+ if requestlist.isRaidMember(request):
+ intf.messageWindow(_("Unable To Remove"),
+ _("You cannot remove this "
+ "partition, as it is part of a RAID device."))
+ return 0
+
+ if confirmDeleteRequest(intf, request):
+ requestlist.removeRequest(request)
+ else:
+ return 0
+
+ if request.type == REQUEST_PREEXIST:
+ # get the drive
+ drive = get_partition_drive(partition)
+
+ if partition.type & parted.PARTITION_EXTENDED:
+ deleteAllLogicalPartitions(partition, requsestlist)
+
+ delete = DeleteSpec(drive, partition.geom.start, partition.geom.end)
+ requestlist.addDelete(delete)
+ else: # shouldn't happen
+ raise ValueError, "Deleting a non-existenent partition"
+
+ del partition
+ return 1
+
+
+def doEditPartitionByRequest(intf, requestlist, part):
+
+ if part == None:
+ intf.messageWindow(_("Unable To Edit"),
+ _("You must select a partition to edit"))
+
+ return (None, None)
+ elif type(part) == type("RAID"):
+ request = requestlist.getRequestByDeviceName(part)
+
+ return ("RAID", request)
+ elif part.type & parted.PARTITION_FREESPACE:
+ request = PartitionSpec(fsset.fileSystemTypeGetDefault(), REQUEST_NEW,
+ start = start_sector_to_cyl(part.geom.disk.dev, part.geom.start),
+ end = end_sector_to_cyl(part.geom.disk.dev, part.geom.end),
+ drive = [ get_partition_drive(part) ])
+
+ return ("PARTITION", request)
+ elif (part.fs_type == None) or (part.fs_type and not part.fs_type.name):
+ intf.messageWindow( _("Filesystem Missing"),
+ _("You cannot edit partitions "
+ "without a filesystem type."))
+ return (None, None)
+ elif part.type & parted.PARTITION_EXTENDED:
+ return (None, None)
+
+ request = requestlist.getRequestByDeviceName(get_partition_name(part))
+ if request:
+ if request.type == REQUEST_PROTECTED:
+ intf.messageWindow(_("Cannot Edit"),
+ _("You cannot edit this "
+ "partition, as it is in use by the installer."))
+ return (None, None)
+ if requestlist.isRaidMember(request):
+ intf.messageWindow( _("Cannot Edit"),
+ _("You cannot edit this partition "
+ "as it is part of a RAID device"))
+ return (None, None)
+
+ return ("PARTITION", request)
+ else: # shouldn't ever happen
+ raise ValueError, "Trying to edit non-existent partition %s" %(get_partition_name(part))
+
+
diff --git a/textw/partition_text.py b/textw/partition_text.py
index 770366b71..ea85b2efe 100644
--- a/textw/partition_text.py
+++ b/textw/partition_text.py
@@ -653,104 +653,25 @@ class PartitionWindow:
def editCb(self):
part = self.lb.current()
- if part == None:
- ButtonChoiceWindow(self.screen, _("Not a Partition"),
- _("You must select a partition to edit"),
- buttons = [ TEXT_OK_BUTTON ] )
- return
- elif type(part) == type("RAID"):
- request = self.partitions.getRequestByDeviceName(part)
- self.editRaidRequest(request)
- return
- elif part.type & parted.PARTITION_FREESPACE:
- request = PartitionSpec(fileSystemTypeGetDefault(), REQUEST_NEW,
- start = start_sector_to_cyl(part.geom.disk.dev, part.geom.start),
- end = end_sector_to_cyl(part.geom.disk.dev, part.geom.end),
- drive = [ get_partition_drive(part) ])
- self.editPartitionRequest(request)
- return
- elif (part.fs_type == None) or (part.fs_type and not part.fs_type.name):
- ButtonChoiceWindow(self.screen, _("Filesystem Missing"),
- _("You cannot edit partitions "
- "without a filesystem type."),
- buttons = [ TEXT_OK_BUTTON ] )
- return
- elif part.type & parted.PARTITION_EXTENDED:
- return
- request = self.partitions.getRequestByDeviceName(get_partition_name(part))
+ (type, request) = doEditPartitionByRequest(self.intf, self.partitions, part)
if request:
- if request.type == REQUEST_PROTECTED:
- ButtonChoiceWindow(self.screen, _("Cannot Edit"),
- _("You cannot edit this "
- "partition, as it is in use by the installer."),
- buttons = [ TEXT_OK_BUTTON ] )
- return
- if self.partitions.isRaidMember(request):
- ButtonChoiceWindow(self.screen, _("Unable to Remove"),
- _("You cannot remove this partition "
- "as it is part of a RAID device"),
- buttons = [ TEXT_OK_BUTTON ])
- return
-
- self.editPartitionRequest(request)
- else: # shouldn't ever happen
- raise ValueError, "Trying to edit non-existent partition %s" %(get_partition_name(part))
-
+ if type == "RAID":
+ self.editRaidRequest(request)
+ else:
+ self.editPartitionRequest(request)
def deleteCb(self):
partition = self.lb.current()
- if partition == None:
- ButtonChoiceWindow(self.screen, _("Unable to Remove"),
- _("You must first select a partition"),
- buttons = [ TEXT_OK_BUTTON ] )
- return
- elif type(partition) == type("RAID"):
- device = partition
- elif partition.type & parted.PARTITION_FREESPACE:
- ButtonChoiceWindow(self.screen, _("Unable to Remove"),
- _("You cannot remove freespace"),
- buttons = [ TEXT_OK_BUTTON ] )
- return
- else:
- device = get_partition_name(partition)
-
- request = self.partitions.getRequestByDeviceName(device)
-
-
- if request:
- if request.type == REQUEST_PROTECTED:
- ButtonChoiceWindow(self.screen, _("You cannot edit this "
- "partition, as it is part of a RAID device."),
- buttons = [ TEXT_OK_BUTTON ] )
- return
-
- if self.partitions.isRaidMember(request):
- ButtonChoiceWindow(self.screen, _("Unable to Remove"),
- _("You cannot remove this partition "
- "as it is part of a RAID device"),
- buttons = [ TEXT_OK_BUTTON ])
- return
-
- self.partitions.removeRequest(request)
- if request.type == REQUEST_PREEXIST:
- # get the drive
- drive = get_partition_drive(partition)
-
- if partition.type & parted.PARTITION_EXTENDED:
- deleteAllLogicalPartitions(partition, self.partitions)
-
- delete = DeleteSpec(drive, partition.geom.start, partition.geom.end)
- self.partitions.addDelete(delete)
- else: # shouldn't happen
- raise ValueError, "Deleting a non-existent partition"
-
- del partition
- self.refresh()
+ if doDeletePartitionByRequest(self.intf, self.partitions, partition):
+ self.refresh()
def resetCb(self):
+ if not confirmResetPartitionState(self.intf):
+ return
+
self.diskset.refreshDevices()
self.partitions.setFromDisk(self.diskset)
self.populate()