Re: [PATCH pyparted]: Make the constraint argument for add_partition and maximize_partition optional

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2009-03-24 at 20:17 +0100, Hans de Goede wrote:
> ---
>   src/parted/disk.py |   16 ++++++++++++----
>   src/pydisk.c       |   26 ++++++++++++++++----------
>   2 files changed, 28 insertions(+), 14 deletions(-)

I think we will have the cylinder-alignment issue anytime a partition
has a max size, either explicitly or because of a filesystem limit,
since this forces us to pass a constraint to maximizePartition.

Dave

> 
> diff --git a/src/parted/disk.py b/src/parted/disk.py
> index b090c0e..cdfdf0a 100644
> --- a/src/parted/disk.py
> +++ b/src/parted/disk.py
> @@ -177,8 +177,13 @@ class Disk(object):
> 
>       def addPartition(self, partition=None, constraint=None):
>           """Add a new Partition to this Disk with the given Constraint."""
> -        if self.__disk.add_partition(partition.getPedPartition(),
> -                                     constraint.getPedConstraint()):
> +        if constraint:
> +            result = self.__disk.add_partition(partition.getPedPartition(),
> +                                               constraint.getPedConstraint())
> +        else:
> +            result = self.__disk.add_partition(partition.getPedPartition())
> +
> +        if result:
>               partition.geometry = parted.Geometry(PedGeometry=partition.getPedPartition().geom)
>               self.partitions.invalidate()
>               return True
> @@ -227,8 +232,11 @@ class Disk(object):
>       def maximizePartition(self, partition=None, constraint=None):
>           """Grow the Partition's Geometry to the maximum possible subject
>              to Constraint."""
> -        return self.__disk.maximize_partition(partition.getPedPartition(),
> -                                              constraint.getPedConstraint())
> +        if constraint:
> +            return self.__disk.maximize_partition(partition.getPedPartition(),
> +                                                  constraint.getPedConstraint())
> +        else:
> +            return self.__disk.maximize_partition(partition.getPedPartition())
> 
>       def calculateMaxPartitionGeometry(self, partition=None, constraint=None):
>           """Get the maximum Geometry the Partition can be grown to,
> diff --git a/src/pydisk.c b/src/pydisk.c
> index eef0efb..5886403 100644
> --- a/src/pydisk.c
> +++ b/src/pydisk.c
> @@ -1148,7 +1148,7 @@ PyObject *py_ped_disk_add_partition(PyObject *s, PyObject *args) {
>       PedConstraint *out_constraint = NULL;
>       int ret = 0;
> 
> -    if (!PyArg_ParseTuple(args, "O!O!",&_ped_Partition_Type_obj,
> +    if (!PyArg_ParseTuple(args, "O!|O!",&_ped_Partition_Type_obj,
>                             &in_part, &_ped_Constraint_Type_obj, &in_constraint)) {
>           return NULL;
>       }
> @@ -1168,9 +1168,11 @@ PyObject *py_ped_disk_add_partition(PyObject *s, PyObject *args) {
>           return NULL;
>       }
> 
> -    out_constraint = _ped_Constraint2PedConstraint(in_constraint);
> -    if (out_constraint == NULL) {
> -        return NULL;
> +    if (in_constraint) {
> +        out_constraint = _ped_Constraint2PedConstraint(in_constraint);
> +        if (out_constraint == NULL) {
> +            return NULL;
> +        }
>       }
> 
>       ret = ped_disk_add_partition(disk, out_part, out_constraint);
> @@ -1193,7 +1195,8 @@ PyObject *py_ped_disk_add_partition(PyObject *s, PyObject *args) {
>       in_part->_owned = 1;
>       *((_ped_Geometry *)in_part->geom)->ped_geometry = out_part->geom;
> 
> -    ped_constraint_destroy(out_constraint);
> +    if (out_constraint)
> +        ped_constraint_destroy(out_constraint);
> 
>       if (ret) {
>           Py_RETURN_TRUE;
> @@ -1367,7 +1370,7 @@ PyObject *py_ped_disk_maximize_partition(PyObject *s, PyObject *args) {
>       PedConstraint *out_constraint = NULL;
>       int ret = 0;
> 
> -    if (!PyArg_ParseTuple(args, "O!O!", &_ped_Partition_Type_obj, &in_part,
> +    if (!PyArg_ParseTuple(args, "O!|O!", &_ped_Partition_Type_obj, &in_part,
>                             &_ped_Constraint_Type_obj, &in_constraint)) {
>           return NULL;
>       }
> @@ -1387,14 +1390,17 @@ PyObject *py_ped_disk_maximize_partition(PyObject *s, PyObject *args) {
>           return NULL;
>       }
> 
> -    out_constraint = _ped_Constraint2PedConstraint(in_constraint);
> -    if (out_constraint == NULL) {
> -        return NULL;
> +    if (in_constraint) {
> +        out_constraint = _ped_Constraint2PedConstraint(in_constraint);
> +        if (out_constraint == NULL) {
> +            return NULL;
> +        }
>       }
> 
>       ret = ped_disk_maximize_partition(disk, out_part, out_constraint);
> 
> -    ped_constraint_destroy(out_constraint);
> +    if (out_constraint)
> +        ped_constraint_destroy(out_constraint);
> 
>       if (ret == 0) {
>           if (partedExnRaised) {

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

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux