parted.constraint module
This module contains the Constraint class, which is used to specify the constraints on a Partition.
- author:
Adolfo Gómez, dkmaster at dkmon dot com
- class parted.constraint.Constraint(constraint: cffi.FFI.CData | None = None)[source]
Bases:
objectWrapper for PedConstraint object
This class represents a constraint on a partition. A constraint is a set of rules that a partition must follow. A constraint is composes of: - start_align: the alignment of the start of the partition - end_align: the alignment of the end of the partition - start_range: the range of the start of the partition - end_range: the range of the end of the partition - min_size: the minimum size of the partition - max_size: the maximum size of the partition
From parted documentation:
Constraints are used to communicate restrictions on operations Constraints are restrictions on the location and alignment of the start and end of a partition, and the minimum and maximum size. Constraints are closed under intersection (for the proof see the source code). For background information see the Chinese Remainder Theorem. This interface consists of construction constraints, finding the intersection of constraints, and finding solutions to constraints. The constraint solver allows you to specify constraints on where a partition or file system (or any PedGeometry) may be placed/resized/etc. For example, you might want to make sure that a file system is at least 10 Gb, or that it starts at the beginning of new cylinder.
- static align(dev: Device, align: int) Constraint[source]
- Return a constraint that will enforce an alignment on the start and end of a region.
start_align = alignment.Alignment(boundary, 0)
end_align = alignment.Alignment(boundary, 0)
start_range = geom.Geometry(0, dev.length)
end_range = geom.Geometry(0, dev.length)
- Parameters:
dev (device.Device) – The device to create the constraint for
alignment (int) – The alignment boundary in Kbytes. will be rounded up to the nearest multiple of dev.sector_size
- Returns:
A constraint that will enforce an alignment on the start and end of a region.
- Return type:
Examples
>>> import parted >>> dev = parted.getDevice('/dev/sda') >>> constraint = parted.Constraint.bound(dev, 1<<10) # 1 MiB
- static any(dev: Device) Constraint[source]
- Return a constraint that any region on the given device will satisfy.
start_align = aligment.Alignment.any()
end_align = aligment.Alignment.any()
start_range = geom.Geometry(0, dev.length)
end_range = geom.Geometry(0, dev.length)
min_size = 1
max_size = dev.length
- Parameters:
dev (device.Device) – The device to create the constraint for
- Returns:
A constraint that any region on the given device will satisfy.
- Return type:
- duplicate() Constraint[source]
Returns a new constraint that is a duplicate of this constraint.
- Returns:
A new constraint that is a duplicate of this constraint.
- Return type:
- Raises:
exceptions.InvalidObjectError – if self is not a valid constraint
- property end_align: Alignment
Returns the alignment of the end of the region.
- Returns:
The alignment of the end of the region.
- Return type:
- property end_range: Geometry
Returns the end range of the constraint.
- Returns:
The end range of the constraint.
- Return type:
- static exact(geom: Geometry) Constraint[source]
- Return a constraint that only the given region will satisfy.
start_align = alignment.Alignment(geom.start, 0)
end_align = alignment.Alignment(geom.end, 0)
start_range = geom.Geometry(geom.start, 1)
end_range = geom.Geometry(geom.end, 1)
- Parameters:
geom (geom.Geometry) – The geometry to constrain to.
- Returns:
A constraint that only the given region will satisfy.
- Return type:
- intersect(constraint: Constraint) Constraint[source]
Returns a new constraint that is the intersection of this constraint and the given constraint.
The intersection of two constraints is the largest constraint that is contained by both of them. This is calculated: - intersection of start_alignments. If no intersection, returns empty constraint - intersection of end_alignments. If no intersection, returns empty constraint - intersection of start_ranges. If no intersection, returns empty constraint - intersection of end_ranges. If no intersection, returns empty constraint - max of min_sizes - min of max_sizes
- Parameters:
constraint (Constraint) – The constraint to intersect with this constraint.
- Returns:
The intersection of this constraint and the given constraint.
- Return type:
- Raises:
exceptions.InvalidObjectError – if self is not a valid constraint
- is_solution(geom: Geometry) bool[source]
Check whether geom satisfies the given constraint. Will satisfied it if: - geom.start is aligned to start_align - geom.end is aligned to end_align - geom.start is in start_range - geom.end is in end_range - geom.length is in the range [min_size, max_size]
- Parameters:
geom (geom.Geometry) – The geometry to check
- Returns:
True if geom satisfies the given constraint, False otherwise
- Return type:
bool
- Raises:
exceptions.InvalidObjectError – if self is not a valid constraint
- property max_size: int
The max size of the constraint
- Returns:
The max size of the constraint
- Return type:
int
- property min_size: int
Minimum size of the partition in bytes
- Returns:
minimum size of the partition in bytes
- Return type:
int
- static new(start_align: Alignment, end_align: Alignment, start_range: Geometry, end_range: Geometry, min_size_sector: int, max_size_sector: int) Constraint[source]
Create a new constraint.
- Parameters:
start_align (alignment.Alignment) – The alignment of the start of the region.
end_align (alignment.Alignment) – The alignment of the end of the region.
start_range (geom.Geometry) – The range of the start of the region.
end_range (geom.Geometry) – The range of the end of the region.
min_size (int) – The minimum size of the region.
max_size (int) – The maximum size of the region.
- Returns:
A newly created contraint object.
- Return type:
- static new_from_max(max: Geometry) Constraint[source]
Return a constraint that requires a region to be entirely contained inside max.
- Parameters:
max (geom.Geometry) – The geometry to constrain to.
- Returns:
The new created constraint.
- Return type:
- static new_from_min(min: Geometry) Constraint[source]
Return a constraint that requires a region to entirely contain min.
- Parameters:
min (geom.Geometry) – The geometry to constrain to.
- Returns:
A constraint that requires a region to entirely contain min.
- Return type:
- static new_from_min_max(min: Geometry, max: Geometry) Constraint[source]
Return a constraint that requires a region to be entirely contained inside max, and to entirely contain min.
- Parameters:
min (geom.Geometry) – The minimum geometry to constrain to.
max (geom.Geometry) – The maximum geometry to constrain to.
- Returns:
The constraint.
- Return type:
- property obj: cffi.FFI.CData
Wrapped
PedConstraint*object
- solve_max() Geometry[source]
Find the largest region that satisfies a constraint.
- Returns:
The largest region that satisfies the constraint.
- Return type:
- Raises:
exceptions.InvalidObjectError – if self is not a valid constraint
- solve_nearest(geometry: Geometry) Geometry[source]
Return the nearest region to geometry that satisfy a constraint.
This is the region that, if geometry is moved to it, geometry will be as close as possible to the original geometry, and still satisfy the constraint.
- Parameters:
geometry (geom.Geometry) – The geometry to solve
- Returns:
The nearest geometry that satisfies the constraint
- Return type:
- Raises:
exceptions.InvalidObjectError – if self is not a valid constraint
- property start_align: Alignment
Returns the alignment of the start of the region.
- Returns:
The alignment of the start of the region.
- Return type: