parted.alignment module

This module contains the Alignment class.

The alignment class is used to specify the alignment of a partition. It’s a wrapper for the PedAlignment struct. and related functions.

author:

Adolfo Gómez, dkmaster at dkmon dot com

class parted.alignment.Alignment(alignment_or_offset: int | cffi.FFI.CData | None, grain_size: int = 0)[source]

Bases: object

Aligment wrapper

This class wraps the PedAlignment object, and provides a more pythonic interface to itself.

align_down(geometry: Geometry, sector: int) int[source]

Returns the closest sector to sector that lies inside geom that satisfies the given alignment constraint align.

Parameters:
  • geometry (geom.Geometry) – The geometry that contains the sector to align

  • sector (int) – the sector to align

Returns:

The aligned sector

Return type:

int

Raises:

exceptions.InvalidObjectError – If the wrapped alignment is not valid

align_nearest(geometry: Geometry, sector: int) int[source]

Returns the sector that is closest to sector, satisfies the align constraint and lies inside geom.

Parameters:
  • geometry (geom.Geometry) – The geometry that contains the sector to align

  • sector (int) – the sector to align

Returns:

The aligned sector

Return type:

int

Raises:

exceptions.InvalidObjectError – If the wrapped alignment is not valid

align_up(geometry: Geometry, sector: int) int[source]

Returns the closest sector to sector that lies inside geom that satisfies self aligment.

Parameters:
  • geometry (geom.Geometry) – The geometry that contains the sector to align

  • sector (int) – The sector to align

Returns:

_description_

Return type:

int

Raises:

exceptions.InvalidObjectError – If the wrapped alignment is not valid

static any() Alignment[source]

Return an alignment object that represents all PedSector’s. (that is, offset=0, grain_size=1)

Returns:

_description_

Return type:

Alignment

duplicate() Alignment[source]

Generates a Duplicated self.

This is an independent copy of the alignment, that can be manipulated without affecting the original one.

Returns:

An Aligment with a duplicate of our managed PEDAlignment object

Return type:

Alignment

property grain_size: int

Wrapped alignment grain size

Returns:

The grain size of the alignment

Return type:

int

init(offset: int, grain_size: int) None[source]

Initializes an already created alignment object

Parameters:
  • offset (int) – The offset

  • grain_size (int) – The grain size

Raises:

exceptions.InvalidObjectError – If the wrapped alignment is not valid

intersect(other: Alignment) Alignment[source]

Intersect operation between self alignment and the other one.

The intersect operation is the alignment that complies with both alignments.

Parameters:

other (Alignment) – The other alignment

Returns:

The resulting alignment

Return type:

Alignment

Raises:

exceptions.InvalidObjectError – If the wrapped alignment is not valid

is_aligned(geometry: Geometry, sector: int) bool[source]

This function returns True if sector satisfies the alignment constraint align and lies inside geom.

Parameters:
  • geometry (geom.Geometry) – The geometry that contains the sector to check if it is aligned

  • sector (int) – the sector to check if it is aligned

Returns:

_description_

Return type:

bool

Raises:

exceptions.InvalidObjectError – If the wrapped alignment is not valid

static new(offset: int, grain_size: int) Alignment[source]

Return an alignment object (used by PedConstraint), representing all PedSector’s that are of the form offset + X * grain_size.

Parameters:
  • offset (int) – The offset

  • grain_size (int) – The grain size

Returns:

The alignment object

Return type:

Alignment

static none() Alignment[source]

Return an alignment object that represents no PedSector’s. (that is, offset=0, grain_size=0)

Returns:

_description_

Return type:

Alignment

property obj: cffi.FFI.CData

Wrapped PedAlignment* object

property offset: int

Wrapped alignment offset

Returns:

The offset of the alignment

Return type:

int