_ped_Constraint *PedConstraint2_ped_Constraint(PedConstraint *constraint) { _ped_Constraint *ret = NULL; _ped_Alignment *start_align = NULL; _ped_Alignment *end_align = NULL; _ped_Geometry *start_range = NULL; _ped_Geometry *end_range = NULL; PyObject *args = NULL; if (constraint == NULL) { PyErr_SetString(PyExc_TypeError, "Empty PedConstraint()"); return NULL; } ret = (_ped_Constraint *) _ped_Constraint_Type_obj.tp_new(&_ped_Constraint_Type_obj, NULL, NULL); if (!ret) return (_ped_Constraint *) PyErr_NoMemory(); if ((start_align = PedAlignment2_ped_Alignment(constraint->start_align)) == NULL) goto error; if ((end_align = PedAlignment2_ped_Alignment(constraint->end_align)) == NULL) goto error; if ((start_range = PedGeometry2_ped_Geometry(constraint->start_range)) == NULL) goto error; if ((end_range = PedGeometry2_ped_Geometry(constraint->end_range)) == NULL) goto error; args = Py_BuildValue("OOOOLL", start_align, end_align, start_range, end_range, constraint->min_size, constraint->max_size); if (args == NULL) { goto error; } if (_ped_Constraint_Type_obj.tp_init((PyObject *) ret, args, NULL)) { goto error; } Py_DECREF(args); Py_DECREF(start_align); Py_DECREF(end_align); Py_DECREF(start_range); Py_DECREF(end_range); return ret; error: Py_XDECREF(args); Py_XDECREF(start_align); Py_XDECREF(end_align); Py_XDECREF(start_range); Py_XDECREF(end_range); Py_DECREF(ret); return NULL; }
/* 1:1 function mappings for geom.h in libparted */ PyObject *py_ped_geometry_duplicate(PyObject *s, PyObject *args) { PedGeometry *geometry = NULL, *geom = NULL; _ped_Geometry *ret = NULL; geometry = _ped_Geometry2PedGeometry(s); if (geometry == NULL) { return NULL; } geom = ped_geometry_duplicate(geometry); if (geom) { ret = PedGeometry2_ped_Geometry(geom); } else { if (partedExnRaised) { partedExnRaised = 0; if (!PyErr_ExceptionMatches(PartedException) && !PyErr_ExceptionMatches(PyExc_NotImplementedError)) PyErr_SetString(CreateException, partedExnMessage); } else PyErr_SetString(CreateException, "Could not duplicate geometry"); return NULL; } return (PyObject *) ret; }
PyObject *py_ped_constraint_solve_max(PyObject *s, PyObject *args) { PedConstraint *constraint = NULL; PedGeometry *geometry = NULL; _ped_Geometry *ret = NULL; constraint = _ped_Constraint2PedConstraint(s); if (constraint == NULL) { return NULL; } geometry = ped_constraint_solve_max(constraint); ped_constraint_destroy(constraint); if (geometry) { ret = PedGeometry2_ped_Geometry(geometry); } else { if (partedExnRaised) { partedExnRaised = 0; if (!PyErr_ExceptionMatches(PartedException) && !PyErr_ExceptionMatches(PyExc_NotImplementedError)) PyErr_SetString(ConstraintException, partedExnMessage); } else PyErr_SetString(PyExc_ArithmeticError, "Could not find largest region satisfying constraint"); return NULL; } return (PyObject *) ret; }
_ped_Partition *PedPartition2_ped_Partition(PedPartition *part, _ped_Disk *pydisk) { _ped_Partition *ret = NULL; if (part == NULL) { PyErr_SetString(PyExc_TypeError, "Empty PedPartition()"); return NULL; } if (pydisk == NULL) { PyErr_SetString(PyExc_TypeError, "Empty _ped_Disk()"); return NULL; } ret = (_ped_Partition *) _ped_Partition_Type_obj.tp_new(&_ped_Partition_Type_obj, NULL, NULL); if (!ret) return (_ped_Partition *) PyErr_NoMemory(); ret->disk = (PyObject *)pydisk; Py_INCREF(ret->disk); ret->geom = (PyObject *)PedGeometry2_ped_Geometry(&part->geom); if (!ret->geom) goto error; if (part->fs_type == NULL) { ret->fs_type = Py_None; Py_INCREF(ret->fs_type); } else { ret->fs_type = (PyObject *)PedFileSystemType2_ped_FileSystemType(part->fs_type); if (!ret->fs_type) goto error; } ret->type = part->type; ret->ped_partition = part; return ret; error: Py_DECREF(ret); return NULL; }
_ped_FileSystem *PedFileSystem2_ped_FileSystem(PedFileSystem *fs) { _ped_FileSystem *ret = NULL; _ped_FileSystemType *type = NULL; _ped_Geometry *geom = NULL; PyObject *args = NULL; if (fs == NULL) { PyErr_SetString(PyExc_TypeError, "Empty PedFileSystem()"); return NULL; } ret = (_ped_FileSystem *) _ped_FileSystem_Type_obj.tp_new(&_ped_FileSystem_Type_obj, NULL, NULL); if (!ret) return (_ped_FileSystem *) PyErr_NoMemory(); if ((type = PedFileSystemType2_ped_FileSystemType(fs->type)) == NULL) goto error; if ((geom = PedGeometry2_ped_Geometry(fs->geom)) == NULL) goto error; args = Py_BuildValue("OOi", type, geom, fs->checked); if (args == NULL) { goto error; } if (_ped_FileSystem_Type_obj.tp_init((PyObject *) ret, args, NULL)) { goto error; } Py_DECREF(args); Py_DECREF(type); Py_DECREF(geom); return ret; error: Py_XDECREF(args); Py_XDECREF(type); Py_XDECREF(geom); Py_DECREF(ret); return NULL; }
PyObject *py_ped_file_system_probe_specific(PyObject *s, PyObject *args) { PyObject *in_geom = NULL, *in_fstype = NULL; PedFileSystemType *fstype = NULL; PedGeometry *out_geom = NULL, *geom = NULL; _ped_Geometry *ret = NULL; if (!PyArg_ParseTuple(args, "O!O!", &_ped_FileSystemType_Type_obj, &in_fstype, &_ped_Geometry_Type_obj, &in_geom)) { return NULL; } fstype = _ped_FileSystemType2PedFileSystemType(in_fstype); if (!fstype) { return NULL; } out_geom = _ped_Geometry2PedGeometry(in_geom); if (!out_geom) { return NULL; } geom = ped_file_system_probe_specific(fstype, out_geom); if (geom) { ret = PedGeometry2_ped_Geometry(geom); } else { /* libparted swallows exceptions here (I think) and just returns * NULL if the match is not made. Reset exception flag and return * None. */ if (partedExnRaised) { partedExnRaised = 0; } Py_INCREF(Py_None); return Py_None; } return (PyObject *) ret; }
PyObject *py_ped_geometry_intersect(PyObject *s, PyObject *args) { PyObject *in_b = NULL; PedGeometry *out_a = NULL, *out_b = NULL, *geom = NULL; _ped_Geometry *ret = NULL; if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_b)) { return NULL; } out_a = _ped_Geometry2PedGeometry(s); if (out_a == NULL) { return NULL; } out_b = _ped_Geometry2PedGeometry(in_b); if (out_b == NULL) { return NULL; } geom = ped_geometry_intersect (out_a, out_b); if (geom) { ret = PedGeometry2_ped_Geometry(geom); } else { if (partedExnRaised) { partedExnRaised = 0; if (!PyErr_ExceptionMatches(PartedException) && !PyErr_ExceptionMatches(PyExc_NotImplementedError)) PyErr_SetString(CreateException, partedExnMessage); } else PyErr_SetString(PyExc_ArithmeticError, "Could not find geometry intersection"); return NULL; } return (PyObject *) ret; }
PyObject *py_ped_constraint_solve_nearest(PyObject *s, PyObject *args) { PyObject *in_geometry = NULL; PedConstraint *constraint = NULL; PedGeometry *out_geometry = NULL; PedGeometry *geometry = NULL; _ped_Geometry *ret = NULL; if (!PyArg_ParseTuple(args, "O!", &_ped_Geometry_Type_obj, &in_geometry)) { return NULL; } constraint = _ped_Constraint2PedConstraint(s); if (constraint == NULL) { return NULL; } out_geometry = _ped_Geometry2PedGeometry(in_geometry); if (out_geometry == NULL) { ped_constraint_destroy(constraint); return NULL; } geometry = ped_constraint_solve_nearest(constraint, out_geometry); ped_constraint_destroy(constraint); if (geometry) { ret = PedGeometry2_ped_Geometry(geometry); } else { PyErr_SetString(PyExc_ArithmeticError, "Could not find region nearest to constraint for given geometry"); return NULL; } return (PyObject *) ret; }