Compare commits

..

No commits in common. "master" and "v1.1" have entirely different histories.
master ... v1.1

4 changed files with 10 additions and 37 deletions

View File

@ -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 *device;
char *fname;
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,
&device, &readonly)) {
kwds, "s|p", kwlist,
&readonly)) {
PyErr_SetString(PyExc_TypeError, ARG_ERR);
return NULL;
}
if ((rc = fdisk_assign_device(self->cxt, device, readonly)) < 0) {
if ((rc = fdisk_assign_device(self->cxt, fname, readonly)) < 0) {
set_PyErr_from_rc(-rc);
return NULL;
}
@ -193,17 +193,12 @@ 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 | METH_KEYWORDS, Context_assign_device_HELP},
{"assign_device", (PyCFunction)Context_assign_device, METH_VARARGS, 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
View File

@ -59,23 +59,15 @@ 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;
}
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);
ptype = fdisk_label_get_parttype_from_code(self->lb, ptype_code);
if (!ptype) {
PyErr_Format(PyExc_RuntimeError, "No match for parttype with code: %d", ptype_code);
return NULL;
@ -88,9 +80,7 @@ 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)) {
@ -98,13 +88,7 @@ static PyObject *Label_get_parttype_from_string(LabelObject *self, PyObject *arg
return NULL;
}
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);
ptype = fdisk_label_get_parttype_from_string(self->lb, str);
if (!ptype) {
PyErr_Format(PyExc_RuntimeError, "No match for parttype with string: %s", str);
return NULL;

View File

@ -25,11 +25,6 @@ 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));
@ -41,7 +36,6 @@ 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}

View File

@ -5,7 +5,7 @@ libfdisk = Extension('fdisk',
sources = ['fdisk.c', 'context.c', 'label.c',
'partition.c', 'parttype.c'])
setup (name = 'python-libfdisk',
version = '1.2',
setup (name = 'libfdisk',
version = '1.1',
description = 'Python bindings for libfdisk',
ext_modules = [libfdisk])