Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
|
f20ba067ed | |
|
1a74bf5024 | |
|
0352d77335 | |
|
e4b2964ee0 | |
|
34fd2cbe48 | |
|
dce0b0c1e3 |
17
context.c
17
context.c
|
@ -83,9 +83,9 @@ static int Context_init(ContextObject *self, PyObject *args, PyObject *kwds)
|
|||
"and switch the current label driver to reflect the probing result. "
|
||||
static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
static char *kwlist[] = { "readonly", NULL };
|
||||
static char *kwlist[] = { "", "readonly", NULL };
|
||||
int rc, readonly = 0;
|
||||
char *fname;
|
||||
char *device;
|
||||
|
||||
if (!self->cxt) {
|
||||
PyErr_SetString(PyExc_TypeError, ARG_ERR);
|
||||
|
@ -93,13 +93,13 @@ static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyOb
|
|||
}
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args,
|
||||
kwds, "s|p", kwlist,
|
||||
&readonly)) {
|
||||
kwds, "s|$p", kwlist,
|
||||
&device, &readonly)) {
|
||||
PyErr_SetString(PyExc_TypeError, ARG_ERR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((rc = fdisk_assign_device(self->cxt, fname, readonly)) < 0) {
|
||||
if ((rc = fdisk_assign_device(self->cxt, device, readonly)) < 0) {
|
||||
set_PyErr_from_rc(-rc);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -193,12 +193,17 @@ static PyObject *Context_add_partition(ContextObject *self, PyObject *args, PyOb
|
|||
PyErr_Format(PyExc_RuntimeError, "Error adding partition to context: %s", strerror(-rc));
|
||||
return NULL;
|
||||
}
|
||||
rc = fdisk_wipe_partition(self->cxt, partno, 1);
|
||||
if (rc < 0) {
|
||||
PyErr_Format(PyExc_RuntimeError, "Error setting wipe for new partition: %s", strerror(-rc));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("n", partno);
|
||||
}
|
||||
|
||||
static PyMethodDef Context_methods[] = {
|
||||
{"assign_device", (PyCFunction)Context_assign_device, METH_VARARGS, Context_assign_device_HELP},
|
||||
{"assign_device", (PyCFunction)Context_assign_device, METH_VARARGS | METH_KEYWORDS, Context_assign_device_HELP},
|
||||
{"partition_to_string", (PyCFunction)Context_partition_to_string, METH_VARARGS, Context_partition_to_string_HELP},
|
||||
{"create_disklabel", (PyCFunction)Context_create_disklabel, METH_VARARGS, Context_create_disklabel_HELP},
|
||||
{"write_disklabel", (PyCFunction)Context_write_disklabel, METH_NOARGS, Context_write_disklabel_HELP},
|
||||
|
|
20
label.c
20
label.c
|
@ -59,15 +59,23 @@ static int Label_init(LabelObject *self, PyObject *args, PyObject *kwds)
|
|||
"Search for partition type in label-specific table."
|
||||
static PyObject *Label_get_parttype_from_code(LabelObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
struct fdisk_label *label = self->lb;
|
||||
struct fdisk_parttype *ptype;
|
||||
unsigned int ptype_code;
|
||||
const char *name;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "I", &ptype_code)) {
|
||||
PyErr_SetString(PyExc_TypeError, ARG_ERR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptype = fdisk_label_get_parttype_from_code(self->lb, ptype_code);
|
||||
if (!fdisk_label_has_code_parttypes(label)) {
|
||||
name = fdisk_label_get_name(label);
|
||||
PyErr_Format(PyExc_RuntimeError, "Current label %s has no code parttypes", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptype = fdisk_label_get_parttype_from_code(label, ptype_code);
|
||||
if (!ptype) {
|
||||
PyErr_Format(PyExc_RuntimeError, "No match for parttype with code: %d", ptype_code);
|
||||
return NULL;
|
||||
|
@ -80,7 +88,9 @@ static PyObject *Label_get_parttype_from_code(LabelObject *self, PyObject *args,
|
|||
"Search by string for partition type in label-specific table."
|
||||
static PyObject *Label_get_parttype_from_string(LabelObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
struct fdisk_label *label = self->lb;
|
||||
struct fdisk_parttype *ptype = NULL;
|
||||
const char *name;
|
||||
char *str;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &str)) {
|
||||
|
@ -88,7 +98,13 @@ static PyObject *Label_get_parttype_from_string(LabelObject *self, PyObject *arg
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ptype = fdisk_label_get_parttype_from_string(self->lb, str);
|
||||
if (fdisk_label_has_code_parttypes(label)) {
|
||||
name = fdisk_label_get_name(label);
|
||||
PyErr_Format(PyExc_RuntimeError, "Current label %s has no string parttypes", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptype = fdisk_label_get_parttype_from_string(label, str);
|
||||
if (!ptype) {
|
||||
PyErr_Format(PyExc_RuntimeError, "No match for parttype with string: %s", str);
|
||||
return NULL;
|
||||
|
|
|
@ -25,6 +25,11 @@ static PyMethodDef PartType_methods[] = {
|
|||
{NULL}
|
||||
};
|
||||
|
||||
static PyObject *PartType_get_string(PartTypeObject *self)
|
||||
{
|
||||
return PyObjectResultStr(fdisk_parttype_get_string(self->type));
|
||||
}
|
||||
|
||||
static PyObject *PartType_get_name(PartTypeObject *self)
|
||||
{
|
||||
return PyObjectResultStr(fdisk_parttype_get_name(self->type));
|
||||
|
@ -36,6 +41,7 @@ static PyObject *PartType_get_code(PartTypeObject *self)
|
|||
}
|
||||
|
||||
static PyGetSetDef PartType_getseters[] = {
|
||||
{"string", (getter)PartType_get_string, NULL, "partition type string (GUID for GPT)", NULL},
|
||||
{"name", (getter)PartType_get_name, NULL, "parttype human readable name", NULL},
|
||||
{"code", (getter)PartType_get_code, NULL, "parttype DOS code", NULL},
|
||||
{NULL}
|
||||
|
|
4
setup.py
4
setup.py
|
@ -5,7 +5,7 @@ libfdisk = Extension('fdisk',
|
|||
sources = ['fdisk.c', 'context.c', 'label.c',
|
||||
'partition.c', 'parttype.c'])
|
||||
|
||||
setup (name = 'libfdisk',
|
||||
version = '1.1',
|
||||
setup (name = 'python-libfdisk',
|
||||
version = '1.2',
|
||||
description = 'Python bindings for libfdisk',
|
||||
ext_modules = [libfdisk])
|
||||
|
|
Loading…
Reference in New Issue