Re: [PATCH 2/3] Fix format check box for pre-existing partitions (#491675)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Cantrell wrote:

When performing a custom partitioning layout, make the Format check mark
column work correctly depending on what you enter in the Edit Partition
dialog box.  Also register and cancel storage actions as necessary.

I think you are hitting what I was, which is that we don't have origfs accessible here in UI (it is stored only in format action), but it seems we might need it. You are carrying over exists, migrate, size, and device through edited formats, but for migrate, we need also original format type (example: have preexisting ext3, Edit: choose format to ext2, next Edit: offers migration to ext3 - see below (*).
Another similar example I met is "Original filesystem" label in raid dialog.

As I wrote some days ago I tried to store the original format in device, or
in UI in dict keyed with device, but maybe there is better way, or even
storing some info about original format is enough.

Another thing - we probably need to cancel also resize and migrate actions
if unchecked in reedit (similarly as with format)?

Sorry for not coming with patches :(

Radek
---
 iw/partition_dialog_gui.py     |   66 ++++++++++++++++++---------
 iw/partition_ui_helpers_gui.py |   98 ++++++++++++++++++++++++---------------
 2 files changed, 105 insertions(+), 59 deletions(-)

diff --git a/iw/partition_dialog_gui.py b/iw/partition_dialog_gui.py
index bb4a730..2842a12 100644
--- a/iw/partition_dialog_gui.py
+++ b/iw/partition_dialog_gui.py
@@ -214,27 +214,51 @@ class PartitionEditor:
                 # preexisting partition, just set mount point and format flag
                 request = self.origrequest
                 mountpoint = self.mountCombo.get_children()[0].get_text()
-
-                if self.fsoptionsDict.has_key("formatcb") and \
-                   self.fsoptionsDict["formatcb"].get_active():
-                    fmt_class = self.fsoptionsDict["fstypeCombo"].get_active_value()
-                    format = fmt_class(mountpoint=mountpoint)
-                    luksdev = None
-                    if self.fsoptionsDict.has_key("lukscb") and \
-                       self.fsoptionsDict["lukscb"].get_active() and \
-                       request.format.type != "luks":
-                        luksdev = LUKSDevice("luks%d" % self.storage.nextID,
-                                             format=format,
-                                             parents=request)
-                        format = getFormat("luks",
-                                           device=self.origrequest.path,
-                                           passphrase=self.storage.encryptionPassphrase)
-                    actions.append(ActionCreateFormat(request, format))
-                    if luksdev:
-                        actions.append(ActionCreateDevice(luksdev))
-                        actions.append(ActionCreateFormat(luksdev))
-                elif request.format.mountable:
-                    request.format.mountpoint = mountpoint
+                devicetree = self.anaconda.id.storage.devicetree
+
+                if self.fsoptionsDict.has_key("formatcb"):
+                   if self.fsoptionsDict["formatcb"].get_active():
+                       fmt_class = self.fsoptionsDict["fstypeCombo"].get_active_value()
+
+                       # carry over exists, migrate, size, and device
+                       # necessary for partition editor UI
+                       try:
+                           format = fmt_class(mountpoint=mountpoint,
+                                              exists=request.format.exists,
+                                              migrate=request.format.migrate,
+                                              size=request.format.size,
+                                              device=request.format.device)
+                       except AttributeError:
+                           format = fmt_class(mountpoint=mountpoint,
+                                              exists=request.format.exists,
+                                              migrate=request.format.migrate,
+                                              device=request.format.device)
+
+                       luksdev = None
+                       if self.fsoptionsDict.has_key("lukscb") and \
+                          self.fsoptionsDict["lukscb"].get_active() and \
+                          request.format.type != "luks":
+                           luksdev = LUKSDevice("luks%d" % self.storage.nextID,
+                                                format=format,
+                                                parents=request)
+                           format = getFormat("luks",
+                                              device=self.origrequest.path,
+                                              passphrase=self.storage.encryptionPassphrase)
+                       actions.append(ActionCreateFormat(request, format))
+                       if luksdev:
+                           actions.append(ActionCreateDevice(luksdev))
+                           actions.append(ActionCreateFormat(luksdev))
+                   elif not self.fsoptionsDict["formatcb"].get_active():

here only else would do

+                       creates = devicetree.findActions(type="create",
+                                                        object="format",
+                                                        path=request.format.device)
+                       for action in creates:
+                           devicetree.cancelAction(action)
+
+                       request.format.exists = True
+
+                       if request.format.mountable:
+                           request.format.mountpoint = mountpoint
request.weight = self.anaconda.platform.weight(mountpoint=mountpoint,
                                                                fstype=request.format.type)
diff --git a/iw/partition_ui_helpers_gui.py b/iw/partition_ui_helpers_gui.py
index 0ad1803..2e00dc3 100644
--- a/iw/partition_ui_helpers_gui.py
+++ b/iw/partition_ui_helpers_gui.py
@@ -35,6 +35,9 @@ from storage.formats import *
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
+FLAG_FORMAT = 1
+FLAG_MIGRATE = 2
+
 class WideCheckList(checklist.CheckList):
     def toggled_item(self, data, row):
@@ -231,7 +234,9 @@ def mountptchangeCB(widget, fstypecombo):
 def resizeOptionCB(widget, resizesb):
     resizesb.set_sensitive(widget.get_active())
-def formatOptionResizeCB(widget, resizesb):
+def formatOptionResizeCB(widget, data):
+    (resizesb, fmt) = data
+
     if widget.get_active():
         lower = 1
     else:
@@ -249,9 +254,18 @@ def formatMigrateOptionCB(widget, data):
     if not sensitive:
         return
- (combowidget, mntptcombo, ofstype, lukscb, othercombo, othercb) = data
+    (combowidget, mntptcombo, fs, lukscb, othercombo, othercb, flag) = data
     combowidget.set_sensitive(widget.get_active())
+ if flag == FLAG_FORMAT:
+        fs.exists = not widget.get_active()
+
+        if fs.migratable and fs.exists:
+            fs.migrate = False
+    elif flag == FLAG_MIGRATE:
+        fs.exists = True
+        fs.migrate = widget.get_active()
+
     if othercb is not None:
         othercb.set_sensitive(not widget.get_active())
         othercb.set_active(False)
@@ -264,9 +278,9 @@ def formatMigrateOptionCB(widget, data):
         if not widget.get_active():
             # set "Encrypt" checkbutton to match partition's initial state
             lukscb.set_active(lukscb.get_data("encrypted"))
-            lukscb.set_sensitive(0)
+            lukscb.set_sensitive(False)
         else:
-            lukscb.set_sensitive(1)
+            lukscb.set_sensitive(True)
# inject event for fstype menu
     if widget.get_active():
@@ -274,10 +288,10 @@ def formatMigrateOptionCB(widget, data):
         setMntPtComboStateFromType(fstype, mntptcombo)
         combowidget.grab_focus()
     else:
-        if isinstance(ofstype, type(ofstype)):
-            ofstype = type(ofstype)
+        if isinstance(fs, type(fs)):
+            fs = type(fs)
- setMntPtComboStateFromType(ofstype, mntptcombo)
+        setMntPtComboStateFromType(fs, mntptcombo)
def createPreExistFSOptionSection(origrequest, maintable, row, mountCombo,
@@ -303,55 +317,63 @@ def createPreExistFSOptionSection(origrequest, maintable, row, mountCombo,
     else:
         origfs = origrequest.format
- formatcb = gtk.CheckButton(label=_("_Format as:"))
-    maintable.attach(formatcb, 0, 1, row, row + 1)
-    formatcb.set_active(not origfs.exists)
-    rc["formatcb"] = formatcb
-
-    fstypeCombo = createFSTypeMenu(origfs, fstypechangeCB,
-                                   mountCombo, ignorefs=ignorefs)
-    fstypeCombo.set_sensitive(formatcb.get_active())
-    maintable.attach(fstypeCombo, 1, 2, row, row + 1)
-    row += 1
-    rc["fstypeCombo"] = fstypeCombo
+    if origfs.formattable:
+        formatcb = gtk.CheckButton(label=_("_Format as:"))
+        maintable.attach(formatcb, 0, 1, row, row + 1)
+        formatcb.set_active(origfs.formattable and not origfs.exists)
+        rc["formatcb"] = formatcb
+
+        fstypeCombo = createFSTypeMenu(origfs, fstypechangeCB,
+                                       mountCombo, ignorefs=ignorefs)
+        fstypeCombo.set_sensitive(formatcb.get_active())
+        maintable.attach(fstypeCombo, 1, 2, row, row + 1)
+        row += 1
+        rc["fstypeCombo"] = fstypeCombo
+    else:
+        formatcb = None
+        fstypeCombo = None
if not formatcb.get_active() and not origfs.migrate:
-	mountCombo.set_data("prevmountable", origfs.mountable)
+        mountCombo.set_data("prevmountable", origfs.mountable)
# this gets added to the table a bit later on
     lukscb = gtk.CheckButton(_("_Encrypt"))
if origfs.migratable:
(*)
here origfs is not the original format (which is only stored in create format action),
-	migratecb = gtk.CheckButton(label=_("Mi_grate filesystem to:"))
-        migratecb.set_active(origfs.migrate)
+        migratecb = gtk.CheckButton(label=_("Mi_grate filesystem to:"))
+        if formatcb is not None:
+            migratecb.set_active(origfs.migrate and (not formatcb.get_active()))
+        else:
+            migratecb.set_active(origfs.migrate)
- migtypes = [origfs.migrationTarget]
+        migtypes = [origfs.migrationTarget]
- maintable.attach(migratecb, 0, 1, row, row + 1)
-	migfstypeCombo = createFSTypeMenu(origfs,
+        maintable.attach(migratecb, 0, 1, row, row + 1)
+        migfstypeCombo = createFSTypeMenu(origfs,
                                           None, None,
                                           availablefstypes = migtypes)
-	migfstypeCombo.set_sensitive(migratecb.get_active())
-	maintable.attach(migfstypeCombo, 1, 2, row, row + 1)
-	row = row + 1
+        migfstypeCombo.set_sensitive(migratecb.get_active())
+        maintable.attach(migfstypeCombo, 1, 2, row, row + 1)
+        row = row + 1
         rc["migratecb"] = migratecb
         rc["migfstypeCombo"] = migfstypeCombo
-	migratecb.connect("toggled", formatMigrateOptionCB,
+        migratecb.connect("toggled", formatMigrateOptionCB,
                           (migfstypeCombo, mountCombo, origfs, None,
-                           fstypeCombo, formatcb))
+                           fstypeCombo, formatcb, FLAG_MIGRATE))
     else:
-	migratecb = None
-	migfstypeCombo = None
+        migratecb = None
+        migfstypeCombo = None
- formatcb.connect("toggled", formatMigrateOptionCB,
-                    (fstypeCombo, mountCombo, origfs, lukscb,
-                     migfstypeCombo, migratecb))
+    if formatcb:
+        formatcb.connect("toggled", formatMigrateOptionCB,
+                         (fstypeCombo, mountCombo, origfs, lukscb,
+                          migfstypeCombo, migratecb, FLAG_FORMAT))
if origrequest.resizable:
         resizecb = gtk.CheckButton(label=_("_Resize"))
-        resizecb.set_active(origrequest.resizable and \
-            ((origrequest.targetSize != 0) and \
-             (origrequest.targetSize != origrequest.currentSize)))
+        resizecb.set_active(origfs.resizable and \
+                            (origfs.currentSize != origfs.targetSize) and \
+                            (origfs.currentSize != 0))
         rc["resizecb"] = resizecb
         maintable.attach(resizecb, 0, 1, row, row + 1)
@@ -378,7 +400,7 @@ def createPreExistFSOptionSection(origrequest, maintable, row, mountCombo,
         resizeOptionCB(resizecb, resizesb)
         row = row + 1
- formatcb.connect("toggled", formatOptionResizeCB, resizesb)
+        formatcb.connect("toggled", formatOptionResizeCB, (resizesb, origfs))
if luksdev:
         lukscb.set_active(1)

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux