示例#1
0
文件: pyunit.c 项目: g2p/pyparted
PyObject *py_ped_unit_parse_custom(PyObject *s, PyObject *args) {
    int ret;
    char *str = NULL;
    PedDevice *out_dev = NULL;
    int unit;
    PedSector sector;
    PyObject *in_geom = NULL;
    PedGeometry *out_geom = NULL;

    if (!PyArg_ParseTuple(args, "ziLO!", &str, &unit, &sector,
                          &_ped_Geometry_Type_obj, &in_geom)) {
        return NULL;
    }

    if (unit < PED_UNIT_FIRST || unit > PED_UNIT_LAST) {
        PyErr_SetString(PyExc_ValueError, "Invalid unit provided.");
        return NULL;
    }

    out_dev = _ped_Device2PedDevice(s);
    if (out_dev == NULL) {
        return NULL;
    }

    out_geom = _ped_Geometry2PedGeometry(in_geom);
    if (out_geom == NULL) {
        return NULL;
    }

    ret = ped_unit_parse_custom(str, out_dev, unit, &sector, &out_geom);

    if (ret) {
        Py_RETURN_TRUE;
    } else {
        Py_RETURN_FALSE;
    }
}
示例#2
0
文件: unit.c 项目: Excito/parted
/**
 * If \p str contains a valid description of a location on \p dev,
 * then \p *sector is modified to describe the location and a geometry
 * is created in \p *range describing a 2 units large area centered on
 * \p *sector.  If the \p range as described here would be partially outside
 * the device \p dev, the geometry returned is the intersection between the
 * former and the whole	device geometry.  If no units are specified, then the
 * default unit is assumed.
 *
 * \return \c 1 if \p str is a valid location description, \c 0 otherwise
 */
int
ped_unit_parse (const char* str, const PedDevice* dev, PedSector *sector,
		PedGeometry** range)
{
	return ped_unit_parse_custom (str, dev, default_unit, sector, range);
}