Exemple #1
0
int
repo_converter(PyObject *o, HyRepo *repo_ptr)
{
    HyRepo repo = repoFromPyObject(o);
    if (repo == NULL)
        return 0;
    *repo_ptr = repo;
    return 1;
}
static PyObject *
load_repo(_SackObject *self, PyObject *args, PyObject *kwds)
{
    const char *kwlist[] = {"repo", "build_cache", "load_filelists", "load_presto",
                      "load_updateinfo", "load_other", NULL};

    PyObject * repoPyObj = NULL;
    int build_cache = 0, load_filelists = 0, load_presto = 0, load_updateinfo = 0, load_other = 0;
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iiiii", (char**) kwlist,
                                     &repoPyObj,
                                     &build_cache, &load_filelists,
                                     &load_presto, &load_updateinfo, &load_other))
        return 0;

    // Is it old deprecated _hawkey.Repo object?
    libdnf::Repo * crepo = repoFromPyObject(repoPyObj);

    // Or is it swig object?
    if (!crepo) {
        auto repoSwigPyObj = reinterpret_cast<RepoSwigPyObject *>(PyObject_GetAttrString(repoPyObj, "this"));
        if (!repoSwigPyObj) {
            PyErr_SetString(PyExc_SystemError, "Unable to parse repoSwigPyObject");
            return NULL;
        }

        crepo = repoSwigPyObj->ptr;
        if (!crepo) {
            PyErr_SetString(PyExc_SystemError, "Unable to parse repo swig object");
            return NULL;
        }
    }

    int flags = 0;
    gboolean ret = 0;
    g_autoptr(GError) error = NULL;
    if (build_cache)
        flags |= DNF_SACK_LOAD_FLAG_BUILD_CACHE;
    if (load_filelists)
        flags |= DNF_SACK_LOAD_FLAG_USE_FILELISTS;
    if (load_presto)
        flags |= DNF_SACK_LOAD_FLAG_USE_PRESTO;
    if (load_updateinfo)
        flags |= DNF_SACK_LOAD_FLAG_USE_UPDATEINFO;
    if (load_other)
        flags |= DNF_SACK_LOAD_FLAG_USE_OTHER;
    Py_BEGIN_ALLOW_THREADS;
    ret = dnf_sack_load_repo(self->sack, crepo, flags, &error);
    Py_END_ALLOW_THREADS;
    if (!ret)
        return op_error2exc(error);
    Py_RETURN_NONE;
}
static PyObject *
load_system_repo(_SackObject *self, PyObject *args, PyObject *kwds)
{
    g_autoptr(GError) error = NULL;
    const char *kwlist[] = {"repo", "build_cache", "load_filelists", "load_presto",
                      NULL};

    PyObject * repoPyObj = NULL;
    libdnf::Repo * crepo = NULL;
    int build_cache = 0, unused_1 = 0, unused_2 = 0;
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oiii", (char**) kwlist,
                                     &repoPyObj,
                                     &build_cache, &unused_1, &unused_2))
        return 0;

    if (repoPyObj) {

        // Is it old deprecated _hawkey.Repo object?
        crepo = repoFromPyObject(repoPyObj);

        // Or is it swig object?
        if (!crepo) {
            auto repoSwigPyObj = reinterpret_cast<RepoSwigPyObject *>(PyObject_GetAttrString(repoPyObj, "this"));
            if (!repoSwigPyObj) {
                PyErr_SetString(PyExc_SystemError, "Unable to parse repoSwigPyObject");
                return NULL;
            }

            crepo = repoSwigPyObj->ptr;
            if (!crepo) {
                PyErr_SetString(PyExc_SystemError, "Unable to parse repo swig object");
                return NULL;
            }
        }
    }

    int flags = 0;
    if (build_cache)
        flags |= DNF_SACK_LOAD_FLAG_BUILD_CACHE;

    gboolean ret = dnf_sack_load_system_repo(self->sack, crepo, flags, &error);
    if (!ret)
        return op_error2exc(error);
    Py_RETURN_NONE;
}