FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu Masters Of The Universe

 
 
LinkBack Thread Tools
 
Old 02-11-2009, 11:54 PM
David Cantrell
 
Default Syntax changes for the new pyparted.

1) Iterate over partitions with a for loop over
disk.partitions.values() rather than calling next_partition()

2) Call getFlag() rather than get_flag()

3) Call setFlag() to enable a flag, call unsetFlag() to disable
a flag.

4) Reference the active property rather than calling the
is_active() method.

And other fixes.
---
autopart.py | 74 ++++++++++++++++++++-------------------------------
bootloader.py | 14 +++------
fsset.py | 18 +++++-------
iw/osbootwidget.py | 4 +-
iw/partition_gui.py | 4 +-
partIntfHelpers.py | 10 +++---
partedUtils.py | 15 +++-------
partitions.py | 21 +++++---------
8 files changed, 63 insertions(+), 97 deletions(-)

diff --git a/autopart.py b/autopart.py
index 7e25d63..84a9549 100644
--- a/autopart.py
+++ b/autopart.py
@@ -114,11 +114,9 @@ def bootAlphaCheckRequirements(part):

# The first free space should start at the begining of the drive
# and span for a megabyte or more.
- free = disk.next_partition()
- while free:
+ for free in disk.partitions.values():
if free.type & parted.PARTITION_FREESPACE:
break
- free = disk.next_partition(free)
if (not free or free.geom.start != 1L or free.getSize(unit="MB") < 1):
return BOOTALPHA_NO_RESERVED_SPACE

@@ -151,11 +149,9 @@ def findFreespace(diskset):
for drive in diskset.disks.keys():
disk = diskset.disks[drive]
free[drive] = []
- part = disk.next_partition()
- while part:
+ for part in disk.partitions.values():
if part.type & parted.PARTITION_FREESPACE:
free[drive].append(part)
- part = disk.next_partition(part)
return free


@@ -274,11 +270,11 @@ def fitConstrained(diskset, requests, primOnly=0, newParts = None):
except Exception, msg:
raise PartitioningError, str(msg)
for flag in request.fstype.getPartedPartitionFlags():
- if not newp.is_flag_available(flag):
- disk.delete_partition(newp)
+ if not newp.isFlagAvailable(flag):
+ disk.deletePartition(newp)
raise PartitioningError, ("requested FileSystemType needs "
"a flag that is not available.")
- newp.set_flag(flag, 1)
+ newp.setFlag(flag)
request.device = fsset.PartedPartitionDevice(newp).getDevice()
request.currentDrive = request.drive[0]
newParts.parts.append(newp)
@@ -442,8 +438,7 @@ def fitSized(diskset, requests, primOnly = 0, newParts = None):
# now need to update freespace since adding extended
# took some space
found = 0
- part = disk.next_partition()
- while part:
+ for part in disk.partitions.values():
if part.type & parted.PARTITION_FREESPACE:
if part.geom.start > freeStartSec and part.geom.end <= freeEndSec:
found = 1
@@ -451,8 +446,6 @@ def fitSized(diskset, requests, primOnly = 0, newParts = None):
freeEndSec = part.geom.end
break

- part = disk.next_partition(part)
-
if not found:
raise PartitioningError, "Could not find free space after making new extended partition"

@@ -477,11 +470,11 @@ def fitSized(diskset, requests, primOnly = 0, newParts = None):
except Exception, msg:
raise PartitioningError, str(msg)
for flag in request.fstype.getPartedPartitionFlags():
- if not newp.is_flag_available(flag):
- disk.delete_partition(newp)
+ if not newp.isFlagAvailable(flag):
+ disk.deletePartition(newp)
raise PartitioningError, ("requested FileSystemType needs "
"a flag that is not available.")
- newp.set_flag(flag, 1)
+ newp.setFlag(flag)

request.device = fsset.PartedPartitionDevice(newp).getDevice()
drive = newp.geom.dev.path[5:]
@@ -870,8 +863,7 @@ def setPreexistParts(diskset, requests):
lvmLog.info("pre-existing partition on non-native disk %s, ignoring" %(request.drive,))
continue
disk = diskset.disks[request.drive]
- part = disk.next_partition()
- while part:
+ for part in disk.partitions.values():
if part.geom.start == request.start and part.geom.end == request.end:
if partedUtils.isEfiSystemPartition(part) and
request.fstype.name == "vfat":
@@ -896,30 +888,27 @@ def setPreexistParts(diskset, requests):
request.device = part.getDeviceNodeName()
if request.fstype:
if request.fstype.getName() != request.origfstype.getName():
- if part.is_flag_available(parted.PARTITION_RAID):
+ if part.isFlagAvailable(parted.PARTITION_RAID):
if request.fstype.getName() == "software RAID":
- part.set_flag(parted.PARTITION_RAID, 1)
+ part.setFlag(parted.PARTITION_RAID)
else:
- part.set_flag(parted.PARTITION_RAID, 0)
- if part.is_flag_available(parted.PARTITION_LVM):
+ part.unsetFlag(parted.PARTITION_RAID)
+ if part.isFlagAvailable(parted.PARTITION_LVM):
if request.fstype.getName() == "physical volume (LVM)":
- part.set_flag(parted.PARTITION_LVM, 1)
+ part.setFlag(parted.PARTITION_LVM)
else:
- part.set_flag(parted.PARTITION_LVM, 0)
+ part.unsetFlag(parted.PARTITION_LVM)

partedUtils.set_partition_file_system_type(part, request.fstype)
-
+
break
- part = disk.next_partition(part)

def deletePart(diskset, delete):
disk = diskset.disks[delete.drive]
- part = disk.next_partition()
- while part:
+ for part in disk.partitions.values():
if part.geom.start == delete.start and part.geom.end == delete.end:
- disk.delete_partition(part)
+ disk.deletePartition(part)
return
- part = disk.next_partition(part)

def processPartitioning(diskset, requests, newParts):
# collect a hash of all the devices that we have created extended
@@ -947,7 +936,7 @@ def processPartitioning(diskset, requests, newParts):
# Finally, remove all of the partitions we added in the last try from
# the disks. We'll start again from there.
for part in newParts.parts:
- part.disk.delete_partition(part)
+ part.disk.deletePartition(part)

newParts.reset()

@@ -959,7 +948,7 @@ def processPartitioning(diskset, requests, newParts):

# sort requests by size
requests.sortRequests()
-
+
# partitioning algorithm in simplistic terms
#
# we want to allocate partitions such that the most specifically
@@ -1115,7 +1104,7 @@ def doClearPartAction(anaconda, partitions, diskset):
return
else:
raise ValueError, "Invalid clear part type in doClearPartAction"
-
+
drives = diskset.disks.keys()
drives.sort()

@@ -1125,11 +1114,9 @@ def doClearPartAction(anaconda, partitions, diskset):
drive in diskset.skippedDisks:
continue
disk = diskset.disks[drive]
- part = disk.next_partition()
- while part:
- if (not part.is_active() or (part.type == parted.PARTITION_EXTENDED) or
+ for part in disk.partitions.values():
+ if (not part.active or (part.type == parted.PARTITION_EXTENDED) or
(part.disk.type.name == "mac" and part.num == 1 and part.name == "Apple")):
- part = disk.next_partition(part)
continue
if part.fs_type:
ptype = partedUtils.get_partition_file_system_type(part)
@@ -1148,12 +1135,11 @@ def doClearPartAction(anaconda, partitions, diskset):
(not ptype and
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
+ ((part.isFlagAvailable(parted.PARTITION_RAID) and part.getFlag(parted.PARTITION_RAID)) or # this is a RAID
+ (part.isFlagAvailable(parted.PARTITION_LVM) and part.getFlag(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...
old = partitions.getRequestByDeviceName(part.getDeviceNo deName())
if old.getProtected():
- part = disk.next_partition(part)
continue

partitions.deleteDependentRequests(old)
@@ -1192,9 +1178,9 @@ def doClearPartAction(anaconda, partitions, diskset):
(iutil.getPPCMachine() == "iSeries"))
and (linuxOnly == 1)
and (not anaconda.isKickstart) and
- part.is_flag_available(parted.PARTITION_BOOT) and
- (part.get_flag(parted.PARTITION_PREP)) and
- part.get_flag(parted.PARTITION_BOOT)):
+ part.isFlagAvailable(parted.PARTITION_BOOT) and
+ (part.getFlag(parted.PARTITION_PREP)) and
+ part.getFlag(parted.PARTITION_BOOT)):
req = partitions.getRequestByDeviceName(part.getDeviceNo deName())
req.mountpoint = None
req.format = 0
@@ -1205,8 +1191,6 @@ def doClearPartAction(anaconda, partitions, diskset):
break
if request:
partitions.autoPartitionRequests.remove(request)
-
- part = disk.next_partition(part)

# set the diskset up
try:
diff --git a/bootloader.py b/bootloader.py
index eedd642..301a8dd 100644
--- a/bootloader.py
+++ b/bootloader.py
@@ -65,12 +65,10 @@ def bootloaderSetupChoices(anaconda):
bootPart = None
for drive in drives:
disk = anaconda.id.diskset.disks[drive]
- part = disk.next_partition()
- while part:
- if part.is_active() and partedUtils.isEfiSystemPartition(part):
+ for part in disk.partitions.values():
+ if part.active and partedUtils.isEfiSystemPartition(part):
bootPart = part.getDeviceNodeName()
break
- part = disk.next_partition(part)
if bootPart:
break
if bootPart:
@@ -80,18 +78,16 @@ def bootloaderSetupChoices(anaconda):
anaconda.id.fsset.add(FileSystemSetEntry(dev, None, fileSystemTypeGet("efi")))

# iSeries bootloader on upgrades
- if iutil.getPPCMachine() == "iSeries" and not anaconda.id.bootloader.device:
+ if iutil.getPPCMachine() == "iSeries" and not anaconda.id.bootloader.device:
drives = anaconda.id.diskset.disks.keys()
drives.sort()
bootPart = None
for drive in drives:
disk = anaconda.id.diskset.disks[drive]
- part = disk.next_partition()
- while part:
- if part.is_active() and part.get_flag(parted.PARTITION_PREP):
+ for part in disk.partitions.values():
+ if part.active and part.getFlag(parted.PARTITION_PREP):
bootPart = part.getDeviceNodeName()
break
- part = disk.next_partition(part)
if bootPart:
break
if bootPart:
diff --git a/fsset.py b/fsset.py
index 77cf841..0af78d7 100644
--- a/fsset.py
+++ b/fsset.py
@@ -1656,8 +1656,8 @@ MAILADDR root
or iutil.getPPCMachine() in ("pSeries", "iSeries", "PMac")
or (iutil.isX86()
and partedUtils.hasGptLabel(diskset, drive)):
- if part and part.is_flag_available(parted.PARTITION_BOOT):
- part.set_flag(parted.PARTITION_BOOT, 1)
+ if part and part.isFlagAvailable(parted.PARTITION_BOOT):
+ part.setFlag(parted.PARTITION_BOOT)
return

for drive in diskset.disks.keys():
@@ -1666,18 +1666,16 @@ MAILADDR root
if partedUtils.hasGptLabel(diskset, drive):
continue
disk = diskset.disks[drive]
- part = disk.next_partition()
- while part:
- if not part.is_active():
- part = disk.next_partition(part)
+ for part in disk.partitions.values():
+ if not part.active:
continue

- if not part.is_flag_available(parted.PARTITION_BOOT):
+ if not part.isFlagAvailable(parted.PARTITION_BOOT):
foundActive = 1
part = None
continue

- if part.get_flag(parted.PARTITION_BOOT):
+ if part.getFlag(parted.PARTITION_BOOT):
foundActive = 1
part = None
continue
@@ -1688,10 +1686,8 @@ MAILADDR root
if part.getDeviceNodeName() == bootDev:
bootPart = part

- part = disk.next_partition(part)
-
if bootPart and not foundActive:
- bootPart.set_flag(parted.PARTITION_BOOT, 1)
+ bootPart.setFlag(parted.PARTITION_BOOT)

if bootPart:
del bootPart
diff --git a/iw/osbootwidget.py b/iw/osbootwidget.py
index 481267d..38e1772 100644
--- a/iw/osbootwidget.py
+++ b/iw/osbootwidget.py
@@ -158,8 +158,8 @@ class OSBootWidget:
parts = []
disks = self.diskset.disks
func = lambda part: (part.is_active() and
- part.get_flag(parted.PARTITION_LVM) != 1 and
- part.get_flag(parted.PARTITION_RAID) != 1)
+ part.getFlag(parted.PARTITION_LVM) != 1 and
+ part.getFlag(parted.PARTITION_RAID) != 1)
for drive in disks.keys():
pedparts.extend(partedUtils.filter_partitions(disk s[drive], func))
for part in pedparts:
diff --git a/iw/partition_gui.py b/iw/partition_gui.py
index f68b90b..78df896 100644
--- a/iw/partition_gui.py
+++ b/iw/partition_gui.py
@@ -836,7 +836,7 @@ class PartitionWindow(InstallWindow):
continue
# ignore the tiny < 1 MB partitions (#119479)
if part.getSize(unit="MB") <= 1.0:
- if not part.is_active() or not part.get_flag(parted.PARTITION_BOOT):
+ if not part.is_active() or not part.getFlag(parted.PARTITION_BOOT):
part = disk.next_partition(part)
continue

@@ -890,7 +890,7 @@ class PartitionWindow(InstallWindow):
ptype = _("Free space")
elif part.type == parted.PARTITION_EXTENDED:
ptype = _("Extended")
- elif part.get_flag(parted.PARTITION_RAID) == 1:
+ elif part.getFlag(parted.PARTITION_RAID) == 1:
ptype = _("software RAID")
parreq = self.partitions.getRaidMemberParent(request)
if parreq:
diff --git a/partIntfHelpers.py b/partIntfHelpers.py
index 1ac193c..dcc15ef 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.get_flag(parted.LINUX_SWAP))
+ and (part.getFlag(parted.PARTITION_SWAP))
and (request.fstype and request.fstype.getName() != "swap")
and (not request.format)):
rc = anaconda.intf.messageWindow(_("Format as Swap?"),
@@ -393,15 +393,15 @@ def checkForSwapNoMatch(anaconda):
"Would you like to format this "
"partition as a swap partition?")
% (request.device), type = "yesno",
- custom_icon="question")
+ custom_icon="question")
if rc == 1:
request.format = 1
request.fstype = fsset.fileSystemTypeGet("swap")
if request.fstype.getName() == "software RAID":
- part.set_flag(parted.PARTITION_RAID, 1)
+ part.setFlag(parted.PARTITION_RAID)
else:
- part.set_flag(parted.PARTITION_RAID, 0)
-
+ part.unsetFlag(parted.PARTITION_RAID)
+
partedUtils.set_partition_file_system_type(part,
request.fstype)

diff --git a/partedUtils.py b/partedUtils.py
index 0f3162b..037fe1d 100644
--- a/partedUtils.py
+++ b/partedUtils.py
@@ -91,7 +91,7 @@ def set_partition_file_system_type(part, fstype):
if not part.isFlagAvailable(flag):
raise PartitioningError, ("requested file system type needs "
"a flag that is not available.")
- part.setFlag(flag, True)
+ part.setFlag(flag)
if isEfiSystemPartition(part):
part.system = parted.fileSystemType["fat32"]
else:
@@ -211,7 +211,7 @@ def checkDiskLabel(disk, intf):
"""Check that the disk label on disk is valid for this machine type."""
arch = iutil.getArch()
if arch in parted.archLabels.keys():
- if disk.type.name in parted.archLabels[arch]:
+ if disk.type in parted.archLabels[arch]:
# this is kind of a hack since we don't want LDL to be used
return checkDasdFmt(disk, intf)
else:
@@ -681,19 +681,17 @@ class DiskSet:

for drive in drives:
disk = self.disks[drive]
- part = disk.next_partition ()
- while part:
+ for part in disk.partitions.values():
node = part.getDeviceNodeName()
crypto = self.anaconda.id.partitions.encryptedDevices.get(n ode)
- if (part.is_active()
+ if (part.active
and (part.getFlag(parted.PARTITION_RAID)
or part.getFlag(parted.PARTITION_LVM))):
- part = part.nextPartition()
continue
elif part.fileSystem or crypto:
theDev = node
if part.fileSystem:
- fstype = part.fileSystem.name
+ fstype = part.fileSystem.type
else:
fstype = None

@@ -708,7 +706,6 @@ class DiskSet:
log.error("failed to open encrypted device %s" % node)

if not fstype or fstype not in fsset.getUsableLinuxFs():
- part = part.nextPartition()
continue

try:
@@ -716,7 +713,6 @@ class DiskSet:
self.anaconda.rootPath, fstype)
checkRoot = self.anaconda.rootPath
except SystemError:
- part = part.nextPartition()
continue

if os.access (checkRoot + '/etc/fstab', os.R_OK):
@@ -735,7 +731,6 @@ class DiskSet:

isys.umount(self.anaconda.rootPath)

- part = disk.next_partition(part)
return rootparts

def driveList (self):
diff --git a/partitions.py b/partitions.py
index b8b2ca2..612c984 100644
--- a/partitions.py
+++ b/partitions.py
@@ -372,10 +372,8 @@ class Partitions:
drives.sort()
for drive in drives:
disk = diskset.disks[drive]
- part = disk.next_partition()
- while part:
+ for part in disk.partitions.values():
if part.type & parted.PARTITION_METADATA:
- part = disk.next_partition(part)
continue

format = None
@@ -383,9 +381,9 @@ class Partitions:
ptype = None
elif part.type & parted.PARTITION_EXTENDED:
ptype = None
- elif part.get_flag(parted.PARTITION_RAID) == 1:
+ elif part.getFlag(parted.PARTITION_RAID) == 1:
ptype = fsset.fileSystemTypeGet("software RAID")
- elif part.get_flag(parted.PARTITION_LVM) == 1:
+ elif part.getFlag(parted.PARTITION_LVM) == 1:
ptype = fsset.fileSystemTypeGet("physical volume (LVM)")
else:
ptype = partedUtils.get_partition_file_system_type(part)
@@ -441,7 +439,6 @@ class Partitions:
if labels[mappedDev] and len(labels[mappedDev])>0:
spec.fslabel = labels[mappedDev]
self.addRequest(spec)
- part = disk.next_partition(part)

# now we need to read in all pre-existing RAID stuff
diskset.startMPath()
@@ -661,14 +658,12 @@ class Partitions:

rc = []
disk = diskset.disks[device]
- part = disk.next_partition()
- while part:
+ for part in disk.partitions.values():
dev = part.getDeviceNodeName()
request = self.getRequestByDeviceName(dev)

if request:
rc.append(request)
- part = disk.next_partition(part)

if len(rc) > 0:
return rc
@@ -1713,8 +1708,8 @@ class Partitions:

disk = part.disk
while part:
- if not part.is_active():
- part = disk.next_partition(part)
+ if not part.active:
+ part = disk.nextPartition(part)
continue

device = part.getDeviceNodeName()
@@ -1729,8 +1724,8 @@ class Partitions:

if self.isLVMVolumeGroupMember(request):
return _("a partition which is a member of a LVM Volume Group.")
-
- part = disk.next_partition(part)
+
+ part = disk.nextPartition(part)
return None


--
1.6.1.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 02-12-2009, 01:12 AM
Jeremy Katz
 
Default Syntax changes for the new pyparted.

On Wednesday, February 11 2009, David Cantrell said:
> 1) Iterate over partitions with a for loop over
> disk.partitions.values() rather than calling next_partition()

Not calling this specific patch out, but is there any reason we don't
expose just iterating over disk.partitions?

Jeremy

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 02-12-2009, 01:30 AM
David Cantrell
 
Default Syntax changes for the new pyparted.

Jeremy Katz wrote:

On Wednesday, February 11 2009, David Cantrell said:

1) Iterate over partitions with a for loop over
disk.partitions.values() rather than calling next_partition()


Not calling this specific patch out, but is there any reason we don't
expose just iterating over disk.partitions?


See patch 32/47

--
David Cantrell <dcantrell@redhat.com>
Red Hat / Honolulu, HI

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

Thread Tools




All times are GMT. The time now is 07:13 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org