示例#1
0
文件: convert.c 项目: axaxs/pyparted
_ped_Disk *PedDisk2_ped_Disk(PedDisk *disk) {
    _ped_Disk *ret = NULL;

    if (disk == NULL) {
        PyErr_SetString(PyExc_TypeError, "Empty PedDisk()");
        return NULL;
    }

    ret = (_ped_Disk *) _ped_Disk_Type_obj.tp_new(&_ped_Disk_Type_obj, NULL, NULL);
    if (!ret) {
        ped_disk_destroy(disk);
        return (_ped_Disk *) PyErr_NoMemory();
    }
    ret->ped_disk = disk;

    ret->dev = (PyObject *) PedDevice2_ped_Device(disk->dev);
    if (!ret->dev)
        goto error;

    ret->type = (PyObject *) PedDiskType2_ped_DiskType(disk->type);
    if (!ret->type)
        goto error;

    return ret;

error:
    Py_DECREF(ret);
    return NULL;
}
示例#2
0
PyObject *py_ped_device_get(PyObject *s, PyObject *args) {
    PedDevice *device = NULL;
    _ped_Device *ret = NULL;
    char *path = NULL;

    if (!PyArg_ParseTuple(args, "z", &path)) {
        return NULL;
    }

    if (path == NULL) {
        PyErr_Format(DeviceException, "Could not find device for empty path");
        return NULL;
    }

    device = ped_device_get(path);
    if (device) {
        ret = PedDevice2_ped_Device(device);
    }
    else {
        if (partedExnRaised) {
            partedExnRaised = 0;

            if (!PyErr_ExceptionMatches(PartedException) &&
                !PyErr_ExceptionMatches(PyExc_NotImplementedError))
                PyErr_SetString(IOException, partedExnMessage);
        }
        else
            PyErr_Format(DeviceException, "Could not find device for path %s", path);

        return NULL;
    }

    return (PyObject *) ret;
}
示例#3
0
PyObject *py_ped_device_get_next(PyObject *s, PyObject *args) {
    PyObject *in_device = NULL;
    PedDevice *cur = NULL, *next = NULL;
    _ped_Device *ret = NULL;

    if (!PyArg_ParseTuple(args, "|O!", &_ped_Device_Type_obj, &in_device)) {
        return NULL;
    }

    if (in_device) {
        cur = _ped_Device2PedDevice(in_device);
        if (!cur) {
            return NULL;
        }
    }

    next = ped_device_get_next(cur);
    if (next) {
        ret = PedDevice2_ped_Device(next);
        return (PyObject *) ret;
    }
    else {
        PyErr_SetNone(PyExc_IndexError);
        return NULL;
    }
}
示例#4
0
_ped_Geometry *PedGeometry2_ped_Geometry(PedGeometry *geometry) {
    _ped_Geometry *ret = NULL;
    _ped_Device *dev = NULL;
    PyObject *args = NULL;

    if (geometry == NULL) {
        PyErr_SetString(PyExc_TypeError, "Empty PedGeometry()");
        return NULL;
    }

    ret = (_ped_Geometry *) _ped_Geometry_Type_obj.tp_new(&_ped_Geometry_Type_obj, NULL, NULL);
    if (!ret)
        return (_ped_Geometry *) PyErr_NoMemory();

    if ((dev = PedDevice2_ped_Device(geometry->dev)) == NULL)
        goto error;

    args = Py_BuildValue("OLLL", dev, geometry->start, geometry->length, geometry->end);
    if (args == NULL) {
        goto error;
    }

    if (_ped_Geometry_Type_obj.tp_init((PyObject *) ret, args, NULL)) {
        goto error;
    }

    Py_DECREF(args);
    Py_DECREF(dev);

    return ret;

error:
    Py_XDECREF(args);
    Py_XDECREF(dev);
    Py_DECREF(ret);
    return NULL;
}