Пример #1
0
def prermpart(args, dev, disk):
    """Given args, device and disk needed to remove part specified. 
    The format of args: args = [partition.number]. Raise Exception 
    given wrong args or a valid parttiton.number."""

    disk = rfparted.rmpart(disk, args[0])
    return disk
def gpt_easyhandler(dev, disk, start, end, number):
    fs = "ext4"
    bios_grub = False
    for p in disk.partitions:
        if p.number != number and p.getFlag(parted.PARTITION_BIOS_GRUB):
            bios_grub = True
            break
    if bios_grub and number > 0:
        return [disk, number]

    if bios_grub == False:
        if number > 0:
            disk = rfparted.rmpart(disk, number)
        size = parted.sizeToSectors(1, "MB", 512)
        disk = rfparted.mkpart(dev, disk, "primary", start, size, end, "bios_grub")
        start = start + size + 1

    partnumber = [part.number for part in disk.partitions]
    disk = rfparted.mkpart(dev, disk, "primary", start, 0, end, fs)
    number = 0
    for p in disk.partitions:
        if p.number in partnumber:
            continue
        number = p.number
        break

    return [disk, number]