[pyparted] Add function for resetting partition's number
David Cantrell
dcantrell at redhat.com
Wed Nov 26 14:39:22 UTC 2014
I've committed this to pyparted, tested it, and pushed out a new release:
pyparted-3.10.2
I've built this in rawhide and f21 now.
Thanks,
On Wed, Nov 26, 2014 at 02:38:26PM +0100, Vratislav Podzimek wrote:
> The partition's number is a read-only property because it doesn't make sense to
> change it directly. However, it is sometimes necessary to reset partition's
> number to default which tell's parted that the partition should have a new
> number assigned. An example of such case is removing partition from a disk and
> adding it back.
>
> Related: rhbz#1166598
> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> ---
> include/docstrings/pydisk.h | 6 ++++++
> include/pydisk.h | 1 +
> include/typeobjects/pydisk.h | 2 ++
> src/parted/partition.py | 4 ++++
> src/pydisk.c | 14 ++++++++++++++
> 5 files changed, 27 insertions(+)
>
> diff --git a/include/docstrings/pydisk.h b/include/docstrings/pydisk.h
> index 77a399f..f9f6f09 100644
> --- a/include/docstrings/pydisk.h
> +++ b/include/docstrings/pydisk.h
> @@ -82,6 +82,12 @@ PyDoc_STRVAR(partition_get_path_doc,
> "level. For instance, on Linux this could return '/dev/sda' for a partition.\n"
> "If an error occurs, _ped.PartitionException is raised.");
>
> +PyDoc_STRVAR(partition_reset_num_doc,
> +"reset_num(self) -> boolean\n\n"
> +"Reset the partition's number to value allowing it to be set correctly when\n"
> +"the partition is added to _ped.PartedDisk. The returned value means\n"
> +"success/failure");
> +
> PyDoc_STRVAR(disk_duplicate_doc,
> "duplicate(self) -> Disk\n\n"
> "Return a new Disk that is a copy of self. This method raises\n"
> diff --git a/include/pydisk.h b/include/pydisk.h
> index a2bcc4f..5f69343 100644
> --- a/include/pydisk.h
> +++ b/include/pydisk.h
> @@ -135,6 +135,7 @@ PyObject *py_ped_partition_set_name(_ped_Partition *, PyObject *);
> PyObject *py_ped_partition_get_name(_ped_Partition *, PyObject *);
> PyObject *py_ped_partition_is_busy(_ped_Partition *, PyObject *);
> PyObject *py_ped_partition_get_path(_ped_Partition *, PyObject *);
> +PyObject *py_ped_partition_reset_num(_ped_Partition *, PyObject *);
> PyObject *py_ped_partition_type_get_name(PyObject *, PyObject *);
> PyObject *py_ped_partition_flag_get_name(PyObject *, PyObject *);
> PyObject *py_ped_partition_flag_get_by_name(PyObject *, PyObject *);
> diff --git a/include/typeobjects/pydisk.h b/include/typeobjects/pydisk.h
> index 40e7d59..6839b1f 100644
> --- a/include/typeobjects/pydisk.h
> +++ b/include/typeobjects/pydisk.h
> @@ -61,6 +61,8 @@ static PyMethodDef _ped_Partition_methods[] = {
> partition_is_busy_doc},
> {"get_path", (PyCFunction) py_ped_partition_get_path, METH_VARARGS,
> partition_get_path_doc},
> + {"reset_num", (PyCFunction) py_ped_partition_reset_num, METH_VARARGS,
> + partition_reset_num_doc},
> {NULL}
> };
>
> diff --git a/src/parted/partition.py b/src/parted/partition.py
> index 1649ba1..89cb673 100644
> --- a/src/parted/partition.py
> +++ b/src/parted/partition.py
> @@ -248,6 +248,10 @@ class Partition(object):
> For internal module use only."""
> return self.__partition
>
> + def resetNumber(self):
> + """Reset the partition's number to default"""
> + return self.__partition.reset_num()
> +
> # collect all partition flags and store them in a hash
> partitionFlag = {}
> __flag = _ped.partition_flag_next(0)
> diff --git a/src/pydisk.c b/src/pydisk.c
> index 4e70f55..f644a52 100644
> --- a/src/pydisk.c
> +++ b/src/pydisk.c
> @@ -1364,6 +1364,20 @@ PyObject *py_ped_partition_get_path(_ped_Partition *s, PyObject *args) {
> return PyUnicode_FromString(ret);
> }
>
> +PyObject *py_ped_partition_reset_num(_ped_Partition *s, PyObject *args) {
> + PedPartition *part = NULL;
> +
> + part = _ped_Partition2PedPartition(s);
> + if (part == NULL) {
> + Py_RETURN_FALSE;
> + }
> +
> + part->num = -1;
> +
> + Py_RETURN_TRUE;
> +}
> +
> +
> PyObject *py_ped_partition_type_get_name(PyObject *s, PyObject *args) {
> long type;
> char *ret = NULL;
> --
> 1.9.3
>
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
--
David Cantrell <dcantrell at redhat.com>
Manager, Installer Engineering Team
Red Hat, Inc. | Westford, MA | EST5EDT
More information about the anaconda-patches
mailing list