[PATCH 20/47] Don't use the native_type flag anymore.

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

 



From: Chris Lumens <clumens@xxxxxxxxxx>

In the old pyparted, this flag was marked with all sorts of warnings about
how it would go away once certain constants were supported.  We now support
all the constants libparted exposes, so we don't need to keep ancient hacks
around anymore.
---
 autopart.py             |   12 ++++++------
 bootloader.py           |    2 +-
 iw/partition_gui.py     |    4 ++--
 partIntfHelpers.py      |    2 +-
 partedUtils.py          |   28 ++++++++++++----------------
 textw/partition_text.py |    6 +++---
 6 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/autopart.py b/autopart.py
index 7ff5665..491eb5f 100644
--- a/autopart.py
+++ b/autopart.py
@@ -168,7 +168,7 @@ def bestPartType(disk, request):
         return parted.PARTITION_NORMAL
     if ((numPrimary == (maxPrimary - 1)) and
         not disk.extended_partition and
-        disk.type.check_feature(parted.DISK_TYPE_EXTENDED)):
+        disk.supportsFeature(parted.DISK_TYPE_EXTENDED)):
         return parted.PARTITION_EXTENDED
     return parted.PARTITION_NORMAL
 
@@ -238,7 +238,7 @@ def fitConstrained(diskset, requests, primOnly=0, newParts = None):
             if startSec < minSec:
                 startSec = minSec
 
-            if disk.type.check_feature(parted.DISK_TYPE_EXTENDED) and disk.extended_partition:
+            if disk.supportsFeature(parted.DISK_TYPE_EXTENDED) and disk.extended_partition:
 
                 if (disk.extended_partition.geom.start < startSec) and (disk.extended_partition.geom.end >= endSec):
                     partType = parted.PARTITION_LOGICAL
@@ -1142,12 +1142,12 @@ def doClearPartAction(anaconda, partitions, diskset):
             # 4) the ptable doesn't support numeric ids, but it appears to be
             #    a RAID or LVM device (#107319)
             # 5) the drive contains protected partitions and initAll is set
-            if ((linuxOnly == 0) or (ptype and ptype.isLinuxNativeFS()) or 
+            if ((linuxOnly == 0) or (ptype and ptype.isLinuxNativeFS()) or
                 (initAll and
                  partedUtils.hasProtectedPartitions(drive, anaconda)) or
                 (not ptype and
-                 partedUtils.isLinuxNativeByNumtype(part.native_type)) or 
-                ((part.native_type == -1) and # the ptable doesn't have types
+                 partedUtils.isLinuxNative(part)) or
+                ((part._fileSystem is None) and # the ptable doesn't have types
                  ((part.is_flag_available(parted.PARTITION_RAID) and part.get_flag(parted.PARTITION_RAID)) or  # this is a RAID
                   (part.is_flag_available(parted.PARTITION_LVM) and part.get_flag(parted.PARTITION_LVM)) or # or an LVM
                   (iutil.isMactel() and not ptype)))): # or we're on a mactel and have a blank partition from bootcamp #FIXME: this could be dangerous...
@@ -1193,7 +1193,7 @@ def doClearPartAction(anaconda, partitions, diskset):
                   and (linuxOnly == 1)
                   and (not anaconda.isKickstart) and
                   part.is_flag_available(parted.PARTITION_BOOT) and
-                  (part.native_type == 0x41) and
+                  (part.get_flag(parted.PARTITION_PREP)) and
                   part.get_flag(parted.PARTITION_BOOT)):
                 req = partitions.getRequestByDeviceName(part.getDeviceNodeName())
                 req.mountpoint = None
diff --git a/bootloader.py b/bootloader.py
index 5c495cf..eedd642 100644
--- a/bootloader.py
+++ b/bootloader.py
@@ -88,7 +88,7 @@ def bootloaderSetupChoices(anaconda):
             disk = anaconda.id.diskset.disks[drive]
             part = disk.next_partition()
             while part:
-                if part.is_active() and part.native_type == 0x41:
+                if part.is_active() and part.get_flag(parted.PARTITION_PREP):
                     bootPart = part.getDeviceNodeName()
                     break
                 part = disk.next_partition(part)
diff --git a/iw/partition_gui.py b/iw/partition_gui.py
index 2d161c8..f68b90b 100644
--- a/iw/partition_gui.py
+++ b/iw/partition_gui.py
@@ -914,7 +914,7 @@ class PartitionWindow(InstallWindow):
                     if request and request.fstype != None:
                         ptype = self.getShortFSTypeName(request.fstype.getName())
                         if ptype == "foreign":
-                            ptype = map_foreign_to_fsname(part.native_type)
+                            ptype = map_foreign_to_fsname(part)
                     else:
                         ptype = part.fs_type.name
 
@@ -927,7 +927,7 @@ class PartitionWindow(InstallWindow):
                         ptype = self.getShortFSTypeName(request.fstype.getName())
                         
                         if ptype == "foreign":
-                            ptype = map_foreign_to_fsname(part.native_type)
+                            ptype = map_foreign_to_fsname(part)
                     else:
                         ptype = _("None")
                 if part.type & parted.PARTITION_FREESPACE:
diff --git a/partIntfHelpers.py b/partIntfHelpers.py
index bf89829..1ac193c 100644
--- a/partIntfHelpers.py
+++ b/partIntfHelpers.py
@@ -382,7 +382,7 @@ def checkForSwapNoMatch(anaconda):
         
         part = parted.getPartitionByName(request.device)
         if (part and (not part.type & parted.PARTITION_FREESPACE)
-            and (part.native_type == 0x82)
+            and (part.get_flag(parted.LINUX_SWAP))
             and (request.fstype and request.fstype.getName() != "swap")
             and (not request.format)):
             rc = anaconda.intf.messageWindow(_("Format as Swap?"),
diff --git a/partedUtils.py b/partedUtils.py
index 2efe769..fe4bcea 100644
--- a/partedUtils.py
+++ b/partedUtils.py
@@ -57,7 +57,7 @@ def get_partition_file_system_type(part):
     Return:
     Filesystem object (as defined in fsset.py)
     """
-    if part.fileSystem is None and part.native_type == 0x41:
+    if part.fileSystem is None and part.getFlag(parted.PARTITION_PREP):
         ptype = fsset.fileSystemTypeGet("PPC PReP Boot")
     elif part.fileSystem == None:
         return None
@@ -99,12 +99,9 @@ def set_partition_file_system_type(part, fstype):
         print("Failed to set partition type to ", fstype.getName())
         pass
 
-def map_foreign_to_fsname(type):
+def map_foreign_to_fsname(part):
     """Return the partition type associated with the numeric type.""" 
-    if type in allPartitionTypesDict.keys():
-        return allPartitionTypesDict[type]
-    else:
-        return _("Foreign")
+    return part._fileSystem._type.name
 
 def filter_partitions(disk, func):
     rc = []
@@ -293,15 +290,14 @@ def validateFsType(part):
             part.system = fstype
             return
 
-def isLinuxNativeByNumtype(numtype):
+def isLinuxNative(part):
     """Check if the type is a 'Linux native' filesystem."""
-    linuxtypes = [0x82, 0x83, 0x8e, 0xfd]
-
-    for t in linuxtypes:
-        if int(numtype) == t:
-            return 1
-
-    return 0
+    fstype = part._fileSystem._type
+    if part.getFlag(parted.PARTITION_RAID) or parted.getFlag(parted.PARTITION_LVM) or \
+       part.getFlag(parted.PARTITION_SWAP) or fstype.name in ["ext2", "ext3", "jfs", "reiserfs", "xfs"]:
+        return True
+    else:
+        return False
 
 def getReleaseString(mountpoint):
     if os.access(mountpoint + "/etc/redhat-release", os.R_OK):
@@ -396,7 +392,7 @@ class DiskSet:
 
     def onlyPrimaryParts(self):
         for disk in self.disks.values():
-            if disk.type.check_feature(parted.DISK_TYPE_EXTENDED):
+            if disk.supportsFeature(parted.DISK_TYPE_EXTENDED):
                 return 0
 
         return 1
@@ -1007,7 +1003,7 @@ class DiskSet:
                 if not self.disks.has_key(drive):
                     try:
                         dev = parted.getDevice("/dev/%s" % (drive,))
-                        disk = parted.Disk.(device=dev)
+                        disk = parted.Disk(device=dev)
                         self._addDisk(drive, disk)
                     except:
                         self._removeDisk(drive)
diff --git a/textw/partition_text.py b/textw/partition_text.py
index 6b529f6..56bdf56 100644
--- a/textw/partition_text.py
+++ b/textw/partition_text.py
@@ -167,14 +167,14 @@ class PartitionWindow:
                     if request and request.fstype != None:
                         ptype = request.fstype.getName()
                         if ptype == "foreign":
-                            ptype = map_foreign_to_fsname(part.native_type)
+                            ptype = map_foreign_to_fsname(part)
                     else:
                         ptype = part.fs_type.name
                 else:
                     if request and request.fstype != None:
                         ptype = request.fstype.getName()
                         if ptype == "foreign":
-                            ptype = map_foreign_to_fsname(part.native_type)
+                            ptype = map_foreign_to_fsname(part)
                     else:
                         ptype = _("None")
 
@@ -573,7 +573,7 @@ class PartitionWindow:
 	if ptype == "foreign":
 	    part = parted.getPartitionByName(origrequest.device)
             if part is not None:
-                ptype = map_foreign_to_fsname(part.native_type)
+                ptype = map_foreign_to_fsname(part)
             else:
                 pytype = _("Foreign")
 	type = Label(ptype)
-- 
1.6.1.3

_______________________________________________
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