Commit Graph

11 Commits (bd2703c54ea42da625b7e521297f9c4e493d86bb)
 

Author SHA1 Message Date
Jose M. Guisado bd2703c54e partition: return None if partno is unset
Undefined values in libfdisk should map to None type in Python.

Py_BuildValue("%d", -1); is also incorrectly formatted and raises an
error when executed.
2022-12-15 12:16:52 +01:00
Jose M. Guisado 3d9db0b93b context: add disklabel creation and writing
Adds wrappers for following label related functions from libfdisk:

- fdisk_create_disklabel
- fdisk_write_disklabel

These functions are declared as methods of a Context python object.
2022-12-15 12:16:49 +01:00
Jose M. Guisado e58c21bdc8 context: rename set_size_unit variables
Renames 'cval' to 'szunit' for better readability. This variable is used
to store the size_unit constant that is going to be set using
fdisk_set_size_unit.
2022-12-15 10:52:47 +01:00
Jose M. Guisado 06e59706fc context: add readonly parameter
fdisk_assign_device() contains 'readonly' parameter to indicate how to
open the device.

Assigned device 'readonly' must be false (0) in order to write in-memory
changes to it.
2022-12-15 10:51:04 +01:00
Jose M. Guisado Gomez 0747a84d1c context: add size_unit getset
Size unit can be get or set using 'size_unit' context member.

>>> for pa in cxt.partitions:
...     cxt.partition_to_string(pa, fdisk.FDISK_FIELD_SIZE)
...
'114.6G'
>>> cxt.size_unit
0
>>> cxt.size_unit == fdisk.FDISK_SIZEUNIT_HUMAN
True
>>> cxt.size_unit = fdisk.FDISK_SIZEUNIT_BYTES
>>> for pa in cxt.partitions:
...     cxt.partition_to_string(pa, fdisk.FDISK_FIELD_SIZE)
...
'123010531328'

Use fdisk_get_size_unit to get size unit value.
https://cdn.kernel.org/pub/linux/utils/util-linux/v2.34/libfdisk-docs/libfdisk-Context.html#fdisk-get-size-unit

Use fdisk_set_size_unit to set size unit value.
https://cdn.kernel.org/pub/linux/utils/util-linux/v2.34/libfdisk-docs/libfdisk-Context.html#fdisk-set-size-unit
2022-06-07 16:21:51 +02:00
Jose M. Guisado Gomez ba67cc7a7b Use c99 struct initialization
Declutters PyTypeObject struct initialization when declaring new types.
2022-04-28 15:47:55 +02:00
Jose M. Guisado Gomez c5ae6a3967 context: rename parts to partitions 2022-04-28 15:37:28 +02:00
Jose M. Guisado Gomez b905c1996f fdisk.c: add partition module object
Call Partition_AddModuleObject when initializing the python module.

Fixes bug when using the Partition class but the class has not
been added to the module via Py_TypeReady.

A common error was the type not being ready (missing attributes):

>>> for pa in cxt.parts:
...     print(pa.partno)
...
Traceback (most recent call last):
   File "<stdin>", line 2, in <module>
AttributeError: 'libfdisk.Partition' object has no attribute 'partno'
2022-04-26 17:08:49 +02:00
Jose M. Guisado Gomez ef613790e9 Add COPYING and license headers
LGPL2.1 or later.
2022-04-07 17:03:34 +02:00
Jose M. Guisado Gomez 02e75b5564 Add MANIFEST.in
Add MANIFEST.in to include .h files in source distributions.
2022-04-06 15:40:31 +02:00
Jose M. Guisado Gomez ca92f15e2a Initial commit
Add sources, setup.py and .gitignore

Build/Install:

	python setup.py build
	python setup.py install
2022-04-06 12:56:11 +02:00