def partition(diskname, specs, force=False, check_mode=False):
 count = 0
 dev = parted.getDevice(diskname)
 try:
  disk = parted.newDisk(dev)
 except parted.DiskException:
  disk = None
 if (disk and (len(disk.partitions) > 0) and (not force)):
  print('skipping', diskname)
  return 0
 disk = parted.freshDisk(dev, 'gpt')
 assign_space(dev.getSize(), specs)
 last_megabyte = 1
 for spec in specs:
  for _ in range(spec.count):
   start = parted.sizeToSectors(last_megabyte, 'MiB', dev.sectorSize)
   length = parted.sizeToSectors(spec.size, 'MiB', dev.sectorSize)
   geo = parted.Geometry(device=dev, start=start, length=length)
   filesystem = parted.FileSystem(type='ext4', geometry=geo)
   part = parted.Partition(disk=disk, type=parted.PARTITION_NORMAL, fs=filesystem, geometry=geo)
   disk.addPartition(partition=part, constraint=dev.optimalAlignedConstraint)
   last_megabyte += spec.size
   count += 1
 try:
  if (not check_mode):
   disk.commit()
 except parted.IOException:
  pass
 return count

def partition ( diskname , specs , force = False , check_mode = False ) : count = 0 dev = parted . getDevice ( diskname ) try : disk = parted . newDisk ( dev ) except parted . DiskException : disk = None if ( disk and ( len ( disk . partitions ) > 0 ) and ( not force ) ) : print ( 'skipping' , diskname ) return 0 disk = parted . freshDisk ( dev , 'gpt' ) assign_space ( dev . getSize ( ) , specs ) last_megabyte = 1 for spec in specs : for _ in range ( spec . count ) : start = parted . sizeToSectors ( last_megabyte , 'MiB' , dev . sectorSize ) length = parted . sizeToSectors ( spec . size , 'MiB' , dev . sectorSize ) geo = parted . Geometry ( device = dev , start = start , length = length ) filesystem = parted . FileSystem ( type = 'ext4' , geometry = geo ) part = parted . Partition ( disk = disk , type = parted . PARTITION_NORMAL , fs = filesystem , geometry = geo ) disk . addPartition ( partition = part , constraint = dev . optimalAlignedConstraint ) last_megabyte += spec . size count += 1 try : if ( not check_mode ) : disk . commit ( ) except parted . IOException : pass return count
partition sequence into tuples of length n .