diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2022-12-20 16:04:52 +0100 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2022-12-20 16:18:31 +0100 |
commit | 74784533592823753eb13376757059f85e2237f6 (patch) | |
tree | d14158994e9335388bbec3e1876468949ed46655 /context.c | |
parent | e23d9cd027afe96e627cab54906db2df9d78606b (diff) |
context: add label to repr function
Adds label information to context repr function.
%R is used to get the repr result of a PyObject, in this case this
object is the LabelObject representing the context's label information.
Helps showing more of the context information when printing out a
context object instance.
>>> import fdisk
>>> cxt = fdisk.Context('disk.bin')
>>> cxt
<libfdisk.Context object at 0x7fec52f39330, label=<libfdisk.Label object
at 0x7fec52f39310, name=gpt>, details=True, readonly=False>
Diffstat (limited to 'context.c')
-rw-r--r-- | context.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -296,8 +296,14 @@ static PyGetSetDef Context_getseters[] = { static PyObject *Context_repr(ContextObject *self) { - return PyUnicode_FromFormat("<libfdisk.Context object at %p, details=%s, readonly=%s>", + PyObject *lbo = Py_None; + + if (fdisk_has_label(self->cxt)) + lbo = PyObjectResultLabel(fdisk_get_label(self->cxt, NULL)); + + return PyUnicode_FromFormat("<libfdisk.Context object at %p, label=%R, details=%s, readonly=%s>", self, + lbo, fdisk_is_details(self->cxt) ? "True" : "False", fdisk_is_readonly(self->cxt) ? "True" : "False"); } |