Exemple #1
0
static int
set_installonly(_SackObject *self, PyObject *obj, void *unused)
{
    if (!PySequence_Check(obj)) {
        PyErr_SetString(PyExc_AttributeError, "Expected a sequence.");
        return -1;
    }

    const int len = PySequence_Length(obj);
    const char *strings[len + 1];
    PyObject *tmp_py_str[len];

    for (int i = 0; i < len; ++i) {
        PyObject *item = PySequence_GetItem(obj, i);
        tmp_py_str[i] = NULL;
        strings[i] = NULL;
        if (PyUnicode_Check(item) || PyString_Check(item)) {
            strings[i] = pycomp_get_string(item, &tmp_py_str[i]);
        }
        Py_DECREF(item);
        if (strings[i] == NULL) {
            pycomp_free_tmp_array(tmp_py_str, i);
            return -1;
        }
    }
    strings[len] = NULL;

    HifSack *sack = self->sack;
    hif_sack_set_installonly(sack, strings);
    pycomp_free_tmp_array(tmp_py_str, len - 1);

    return 0;
}
Exemple #2
0
static int
reldep_init(_ReldepObject *self, PyObject *args, PyObject *kwds)
{
    PyObject *sack;
    const char *reldep_str = NULL;
    PyObject *tmp_py_str = NULL;
    PyObject *reldep_str_py = NULL;
    if (!PyArg_ParseTuple(args, "O!O", &sack_Type, &sack, &reldep_str_py))
        return -1;
    DnfSack *csack = sackFromPyObject(sack);
    if (csack == NULL)
        return -1;
    reldep_str = pycomp_get_string(reldep_str_py, &tmp_py_str);
    if (reldep_str == NULL)
        return -1;

    self->reldep = reldep_from_str (csack, reldep_str);
    if (self->reldep == NULL) {
        PyErr_Format(HyExc_Value, "Wrong reldep format: %s", reldep_str);
        Py_XDECREF(tmp_py_str);
        return -1;
    }

    Py_XDECREF(tmp_py_str);
    return 0;
}
Exemple #3
0
static int
subject_init(_SubjectObject *self, PyObject *args, PyObject *kwds)
{
    PyObject *py_pattern = NULL;
    PyObject *tmp_py_str = NULL;
    if (!PyArg_ParseTuple(args, "O", &py_pattern))
        return -1;
    const char * pattern = pycomp_get_string(py_pattern, &tmp_py_str);
    self->pattern = g_strdup(pattern);
    Py_XDECREF(tmp_py_str);
    return 0;
}
Exemple #4
0
/* helpers */
static PyObject *
repo_enabled(_SackObject *self, PyObject *reponame, int enabled)
{
    PyObject *tmp_py_str = NULL;
    const char *cname = pycomp_get_string(reponame, &tmp_py_str);

    if (cname == NULL) {
        Py_XDECREF(tmp_py_str);
        return NULL;
    }
    hif_sack_repo_enabled(self->sack, cname, enabled);
    Py_XDECREF(tmp_py_str);
    Py_RETURN_NONE;
}
static PyObject *
get_delta_from_evr(_PackageObject *self, PyObject *evr_str)
{
    PyObject *tmp_py_str = NULL;
    const char *evr = pycomp_get_string(evr_str, &tmp_py_str);
    if (evr == NULL) {
        Py_XDECREF(tmp_py_str);
        return NULL;
    }
    HyPackageDelta delta_c = hy_package_get_delta_from_evr(self->package, evr);
    Py_XDECREF(tmp_py_str);
    if (delta_c)
	return packageDeltaToPyObject(delta_c);
    Py_RETURN_NONE;
}
Exemple #6
0
static int
set_str(_RepoObject *self, PyObject *value, void *closure)
{
    intptr_t str_key = (intptr_t)closure;
    PyObject *tmp_py_str = NULL;
    const char *str_value = pycomp_get_string(value, &tmp_py_str);

    if (str_value == NULL) {
        Py_XDECREF(tmp_py_str);
        return -1;
    }
    hy_repo_set_string(self->repo, str_key, str_value);
    Py_XDECREF(tmp_py_str);

    return 0;
}
Exemple #7
0
static int
set_attr(_NevraObject *self, PyObject *value, void *closure)
{
    PyObject *tmp_py_str = NULL;
    auto str_value = pycomp_get_string(value, &tmp_py_str);

    if (str_value == NULL) {
        Py_XDECREF(tmp_py_str);
        return -1;
    }

    (self->nevra->*setMethod)(str_value);

    Py_XDECREF(tmp_py_str);
    return 0;
}
Exemple #8
0
static PyObject *
write_debugdata(_GoalObject *self, PyObject *dir_str)
{
    PyObject *tmp_py_str = NULL;
    const char *dir = pycomp_get_string(dir_str, &tmp_py_str);

    if (dir == NULL) {
	Py_XDECREF(tmp_py_str);
	return NULL;
    }

    int ret = hy_goal_write_debugdata(self->goal, dir);
    Py_XDECREF(tmp_py_str);
    if (ret2e(ret, "write_debugdata() failed"))
	return NULL;
    Py_RETURN_NONE;
}
Exemple #9
0
static PyObject *
chksum_type(PyObject *unused, PyObject *str_o)
{
    PyObject *tmp_py_str = NULL;
    const char *str = pycomp_get_string(str_o, &tmp_py_str);

    if (str == NULL) {
        Py_XDECREF(tmp_py_str);
        return NULL;
    }
    int type = hy_chksum_type(str);
    Py_XDECREF(tmp_py_str);

    if (type == 0) {
	PyErr_Format(PyExc_ValueError, "unrecognized chksum type: %s", str);
	return NULL;
    }
    return PyLong_FromLong(type);
}
Exemple #10
0
static PyObject *
write_debugdata(_GoalObject *self, PyObject *dir_str)
{
    g_autoptr(GError) error = NULL;
    PyObject *tmp_py_str = NULL;
    const char *dir = pycomp_get_string(dir_str, &tmp_py_str);

    if (dir == NULL) {
        Py_XDECREF(tmp_py_str);
        return NULL;
    }

    gboolean ret = hy_goal_write_debugdata(self->goal, dir, &error);
    Py_XDECREF(tmp_py_str);
    if (!ret) {
        op_error2exc(error);
        return NULL;
    }
    Py_RETURN_NONE;
}
Exemple #11
0
static PyObject *
add_cmdline_package(_SackObject *self, PyObject *fn_obj)
{
    HifPackage *cpkg;
    PyObject *pkg;
    PyObject *tmp_py_str = NULL;
    const char *fn = pycomp_get_string(fn_obj, &tmp_py_str);

    if (fn == NULL) {
        Py_XDECREF(tmp_py_str);
        return NULL;
    }
    cpkg = hif_sack_add_cmdline_package(self->sack, fn);
    Py_XDECREF(tmp_py_str);
    if (cpkg == NULL) {
        PyErr_Format(PyExc_IOError, "Can not load RPM file: %s.", fn);
        return NULL;
    }
    pkg = new_package((PyObject*)self, hif_package_get_id(cpkg));
    g_object_unref(cpkg);
    return pkg;
}
Exemple #12
0
static PyObject *
set(_SelectorObject *self, PyObject *args)
{
    key_t keyname;
    int cmp_type;
    PyObject *match;

    if (!PyArg_ParseTuple(args, "iiO", &keyname, &cmp_type, &match))
        return NULL;

    if (keyname == HY_PKG) {
        const DnfPackageSet *pset;
        if (queryObject_Check(match)) {
            HyQuery target = queryFromPyObject(match);
            pset = hy_query_run_set(target);
        } else if (PyList_Check(match)) {
            DnfSack *sack = sackFromPyObject(self->sack);
            assert(sack);
            pset = pyseq_to_packageset(match, sack);
        }  else {
            (ret2e(DNF_ERROR_BAD_SELECTOR, "Invalid value type: Only List and Query supported"));
            return NULL;
        }

        if (ret2e(hy_selector_pkg_set(self->sltr, keyname, cmp_type, pset),
                  "Invalid Selector spec." )) {
               return NULL;
        }
    } else {
        const char *cmatch;
        PyObject *tmp_py_str = NULL;
        cmatch = pycomp_get_string(match, &tmp_py_str);
        if (ret2e(hy_selector_set(self->sltr, keyname, cmp_type, cmatch),
                  "Invalid Selector spec." ))
            return NULL;

    }
    Py_RETURN_NONE;
}
Exemple #13
0
DnfReldepList *
pyseq_to_reldeplist(PyObject *obj, DnfSack *sack, int cmp_type)
{
    PyObject *sequence = PySequence_Fast(obj, "Expected a sequence.");
    if (sequence == NULL)
        return NULL;
    DnfReldepList *reldeplist = dnf_reldep_list_new (sack);

    const unsigned count = PySequence_Size(sequence);
    for (unsigned int i = 0; i < count; ++i) {
        PyObject *item = PySequence_Fast_GET_ITEM(sequence, i);
        if (item == NULL)
            goto fail;

    if (cmp_type == HY_GLOB) {
        DnfReldepList *g_reldeplist = NULL;
        const char *reldep_str = NULL;
        PyObject *tmp_py_str = NULL;

        reldep_str = pycomp_get_string(item, &tmp_py_str);
        if (reldep_str == NULL)
            goto fail;
        Py_XDECREF(tmp_py_str);

        g_reldeplist = reldeplist_from_str (sack, reldep_str);
        dnf_reldep_list_extend (reldeplist, g_reldeplist);
        g_object_unref (g_reldeplist);

    } else {
        DnfReldep *reldep = NULL;
        if reldepObject_Check(item)
            reldep = reldepFromPyObject(item);
        else
            reldep = reldep_from_pystr(item, sack);

        if (reldep != NULL)
            dnf_reldep_list_add (reldeplist, reldep);
    }
    }
Exemple #14
0
static PyObject *
split_nevra(PyObject *unused, PyObject *nevra_o)
{
    PyObject *tmp_py_str = NULL;
    const char *nevra = pycomp_get_string(nevra_o, &tmp_py_str);

    if (nevra == NULL) {
        Py_XDECREF(tmp_py_str);
        return NULL;
    }
    long epoch;
    char *name, *version, *release, *arch;

    int split_nevra_ret = hy_split_nevra(nevra, &name, &epoch, &version, &release, &arch);
    Py_XDECREF(tmp_py_str); // release memory after unicode string conversion

    if (ret2e(split_nevra_ret, "Failed parsing NEVRA."))
	return NULL;

    PyObject *ret = Py_BuildValue("slsss", name, epoch, version, release, arch);
    if (ret == NULL)
	return NULL;
    return ret;
}
Exemple #15
0
static int
sack_init(_SackObject *self, PyObject *args, PyObject *kwds)
{
    g_autoptr(GError) error = NULL;
    PyObject *custom_class = NULL;
    PyObject *custom_val = NULL;
    const char *cachedir = NULL;
    const char *arch = NULL;
    const char *rootdir = NULL;
    PyObject *tmp_py_str = NULL;
    PyObject *tmp2_py_str = NULL;
    PyObject *cachedir_py = NULL;
    int make_cache_dir = 0;
    const char *kwlist[] = {"cachedir", "arch", "rootdir", "pkgcls",
                      "pkginitval", "make_cache_dir", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OssOOi", (char**) kwlist,
                                     &cachedir_py, &arch, &rootdir,
                                     &custom_class, &custom_val,
                                     &make_cache_dir))
        return -1;
    if (cachedir_py != NULL)
        cachedir = pycomp_get_string(cachedir_py, &tmp_py_str);
    int flags = 0;
    if (make_cache_dir)
        flags |= HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR;
    self->sack = hif_sack_new();
    Py_XDECREF(tmp_py_str);
    Py_XDECREF(tmp2_py_str);
    if (!hif_sack_set_arch(self->sack, arch, &error)) {
        PyErr_SetString(HyExc_Arch, "Unrecognized arch for the sack.");
        return -1;
    }
    hif_sack_set_rootdir(self->sack, rootdir);
    hif_sack_set_cachedir(self->sack, cachedir);
    if (!hif_sack_setup(self->sack, flags, &error)) {
        switch (error->code) {
        case HIF_ERROR_FILE_INVALID:
            PyErr_SetString(PyExc_IOError,
                            "Failed creating working files for the Sack.");
            break;
        case HIF_ERROR_INVALID_ARCHITECTURE:
            PyErr_SetString(HyExc_Arch, "Unrecognized arch for the sack.");
            break;
        default:
            assert(0);
        }
        return -1;
    }

    if (custom_class && custom_class != Py_None) {
        if (!PyType_Check(custom_class)) {
            PyErr_SetString(PyExc_TypeError, "Expected a class object.");
            return -1;
        }
        Py_INCREF(custom_class);
        self->custom_package_class = custom_class;
    }
    if (custom_val && custom_val != Py_None) {
        Py_INCREF(custom_val);
        self->custom_package_val = custom_val;

    }
    return 0;
}