#include "key.h"
#include "pakfire.h"
#include "repo.h"
+#include "util.h"
static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
PakfireObject* self = (PakfireObject *)type->tp_alloc(type, 0);
return _import_keylist(self, keys);
}
+static PyObject* Pakfire_whatprovides(PakfireObject* self, PyObject* args, PyObject* kwds) {
+ char* kwlist[] = {"provides", "glob", "icase", "name_only", NULL};
+
+ const char* provides;
+ int glob = 0;
+ int icase = 0;
+ int name_only = 0;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|iii", kwlist, &provides, &glob, &icase, &name_only))
+ return NULL;
+
+ int flags = 0;
+ if (glob)
+ flags |= PAKFIRE_GLOB;
+ if (icase)
+ flags |= PAKFIRE_ICASE;
+ if (name_only)
+ flags |= PAKFIRE_NAME_ONLY;
+
+ PakfirePackageList list = pakfire_whatprovides(self->pakfire, provides, flags);
+
+ return PyList_FromPackageList(self, list);
+}
+
+static PyObject* Pakfire_search(PakfireObject* self, PyObject* args) {
+ const char* what;
+
+ if (!PyArg_ParseTuple(args, "s", &what))
+ return NULL;
+
+ PakfirePackageList list = pakfire_search(self->pakfire, what, 0);
+ return PyList_FromPackageList(self, list);
+}
+
+static PyObject* Pakfire_version_compare(PakfireObject* self, PyObject* args) {
+ const char* evr1 = NULL;
+ const char* evr2 = NULL;
+
+ if (!PyArg_ParseTuple(args, "ss", &evr1, &evr2))
+ return NULL;
+
+ int cmp = pakfire_version_compare(self->pakfire, evr1, evr2);
+
+ return PyLong_FromLong(cmp);
+}
+
static struct PyMethodDef Pakfire_methods[] = {
{
"generate_key",
METH_VARARGS,
NULL
},
+ {
+ "search",
+ (PyCFunction)Pakfire_search,
+ METH_VARARGS,
+ NULL
+ },
+ {
+ "version_compare",
+ (PyCFunction)Pakfire_version_compare,
+ METH_VARARGS,
+ NULL
+ },
+ {
+ "whatprovides",
+ (PyCFunction)Pakfire_whatprovides,
+ METH_VARARGS|METH_KEYWORDS,
+ NULL
+ },
{ NULL },
};
return 0;
}
-static PyObject* Pool_version_compare(PoolObject* self, PyObject* args) {
- const char* evr1 = NULL;
- const char* evr2 = NULL;
-
- if (!PyArg_ParseTuple(args, "ss", &evr1, &evr2))
- return NULL;
-
- int cmp = pakfire_pool_version_compare(self->pool, evr1, evr2);
- return PyLong_FromLong(cmp);
-}
-
static Py_ssize_t Pool_len(PoolObject* self) {
return pakfire_pool_count(self->pool);
}
return 0;
}
-static PyObject* Pool_whatprovides(PoolObject* self, PyObject* args, PyObject* kwds) {
- char* kwlist[] = {"provides", "glob", "icase", "name_only", NULL};
-
- const char* provides;
- int glob = 0;
- int icase = 0;
- int name_only = 0;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|iii", kwlist, &provides, &glob, &icase, &name_only))
- return NULL;
-
- int flags = 0;
- if (glob)
- flags |= PAKFIRE_GLOB;
- if (icase)
- flags |= PAKFIRE_ICASE;
- if (name_only)
- flags |= PAKFIRE_NAME_ONLY;
-
- PakfirePackageList list = pakfire_pool_whatprovides(self->pool, provides, flags);
-
- return PyList_FromPackageList(self, list);
-}
-
-static PyObject* Pool_search(PoolObject* self, PyObject* args) {
- const char* what;
-
- if (!PyArg_ParseTuple(args, "s", &what))
- return NULL;
-
- PakfirePackageList list = pakfire_pool_search(self->pool, what, 0);
- return PyList_FromPackageList(self, list);
-}
-
-static struct PyMethodDef Pool_methods[] = {
- {
- "search",
- (PyCFunction)Pool_search,
- METH_VARARGS,
- NULL
- },
- {
- "version_compare",
- (PyCFunction)Pool_version_compare,
- METH_VARARGS,
- NULL
- },
- {
- "whatprovides",
- (PyCFunction)Pool_whatprovides,
- METH_VARARGS|METH_KEYWORDS,
- NULL
- },
- { NULL }
-};
-
static struct PyGetSetDef Pool_getsetters[] = {
{
"cache_path",
tp_dealloc: (destructor)Pool_dealloc,
tp_init: (initproc)Pool_init,
tp_doc: "Pool object",
- tp_methods: Pool_methods,
tp_getset: Pool_getsetters,
tp_as_sequence: &Pool_sequence,
};
return PyLong_FromUnsignedLong(iterations);
}
-PyObject* PyList_FromPackageList(PoolObject* pool, PakfirePackageList packagelist) {
+PyObject* PyList_FromPackageList(PakfireObject* pakfire, PakfirePackageList packagelist) {
PyObject* list = PyList_New(0);
int count = pakfire_packagelist_count(packagelist);
for (int i = 0; i < count; i++) {
PakfirePackage package = pakfire_packagelist_get(packagelist, i);
- PyObject* item = new_package(pool, pakfire_package_id(package));
+ PyObject* item = new_package(pakfire, pakfire_package_id(package));
PyList_Append(list, item);
pakfire_package_unref(package);
#include <pakfire/types.h>
#include <solv/evr.h>
-#include "pool.h"
+#include "pakfire.h"
extern PyObject *_personality(PyObject *self, PyObject *args);
extern PyObject *_sync(PyObject *self, PyObject *args);
extern PyObject *version_compare(PyObject *self, PyObject *args);
extern PyObject* performance_index(PyObject* self, PyObject* args);
-PyObject* PyList_FromPackageList(PoolObject* pool, PakfirePackageList packagelist);
+PyObject* PyList_FromPackageList(PakfireObject* pakfire, PakfirePackageList packagelist);
#endif /* PYTHON_PAKFIRE_UTIL_H */
PakfirePool pakfire_get_pool(Pakfire pakfire);
+int pakfire_version_compare(Pakfire pakfire, const char* evr1, const char* evr2);
+
PakfireRepo pakfire_get_installed_repo(Pakfire pakfire);
void pakfire_set_installed_repo(Pakfire pakfire, PakfireRepo repo);
+PakfirePackageList pakfire_whatprovides(Pakfire pakfire, const char* provides, int flags);
+PakfirePackageList pakfire_search(Pakfire pakfire, const char* what, int flags);
+
#ifdef PAKFIRE_PRIVATE
#include <solv/pool.h>
+void pakfire_pool_has_changed(Pakfire pakfire);
+void pakfire_pool_apply_changes(Pakfire pakfire);
+
Pool* pakfire_get_solv_pool(Pakfire pakfire);
#endif
Pool* pakfire_pool_get_solv_pool(PakfirePool pool);
char* pakfire_pool_tmpdup(Pool* pool, const char* s);
-void pakfire_pool_has_changed(PakfirePool pool);
-void pakfire_pool_apply_changes(PakfirePool pool);
-
Queue* pakfire_pool_get_installonly_queue(PakfirePool pool);
#endif
pakfire_get_path;
pakfire_get_pool;
pakfire_ref;
+ pakfire_search;
pakfire_set_installed_repo;
pakfire_unref;
+ pakfire_version_compare;
+ pakfire_whatprovides;
# archive
pakfire_archive_count_signatures;
# #
#############################################################################*/
+#include <solv/evr.h>
#include <solv/pool.h>
+#include <solv/poolarch.h>
+#include <solv/queue.h>
#include <pakfire/logging.h>
+#include <pakfire/package.h>
+#include <pakfire/packagelist.h>
#include <pakfire/pakfire.h>
#include <pakfire/pool.h>
#include <pakfire/private.h>
struct _Pakfire {
char* path;
char* arch;
- PakfirePool pool;
+
+ // Pool stuff
+ PakfirePool _pool;
+ Pool* pool;
+ int pool_ready;
+ Queue installonly;
// Logging
pakfire_log_function_t log_function;
int log_priority;
+ // Cache
+ PakfireCache cache;
+
int nrefs;
};
DEBUG(" path = %s\n", pakfire_get_path(pakfire));
// Initialize the pool
- pakfire->pool = pakfire_pool_create(pakfire);
+ pakfire->_pool = pakfire_pool_create(pakfire);
+ pakfire->pool = pool_create();
+
+ // Set architecture of the pool
+ pool_setarch(pakfire->pool, pakfire->arch);
}
return pakfire;
return pakfire;
}
+static void pakfire_pool_free_repos(Pool* pool) {
+ Repo* repo;
+ int i;
+
+ FOR_REPOS(i, repo) {
+ PakfireRepo r = repo->appdata;
+ if (r == NULL)
+ continue;
+
+ pakfire_repo_unref(r);
+ }
+}
+
PAKFIRE_EXPORT Pakfire pakfire_unref(Pakfire pakfire) {
if (!pakfire)
return NULL;
if (--pakfire->nrefs > 0)
return pakfire;
- pakfire_pool_unref(pakfire->pool);
+ pakfire_pool_unref(pakfire->_pool);
+ pakfire_pool_free_repos(pakfire->pool);
+ pool_free(pakfire->pool);
+ queue_free(&pakfire->installonly);
pakfire_free(pakfire->path);
pakfire_free(pakfire->arch);
}
PAKFIRE_EXPORT PakfirePool pakfire_get_pool(Pakfire pakfire) {
- return pakfire_pool_ref(pakfire->pool);
+ return pakfire_pool_ref(pakfire->_pool);
+}
+
+PAKFIRE_EXPORT int pakfire_version_compare(Pakfire pakfire, const char* evr1, const char* evr2) {
+ return pool_evrcmp_str(pakfire->pool, evr1, evr2, EVRCMP_COMPARE);
}
Pool* pakfire_get_solv_pool(Pakfire pakfire) {
- return pakfire_pool_get_solv_pool(pakfire->pool);
+ return pakfire->pool;
+}
+
+void pakfire_pool_has_changed(Pakfire pakfire) {
+ pakfire->pool_ready = 0;
+}
+
+void pakfire_pool_apply_changes(Pakfire pakfire) {
+ if (!pakfire->pool_ready) {
+ pool_addfileprovides(pakfire->pool);
+ pool_createwhatprovides(pakfire->pool);
+ pakfire->pool_ready = 1;
+ }
}
PAKFIRE_EXPORT PakfireRepo pakfire_get_installed_repo(Pakfire pakfire) {
- Pool* p = pakfire_pool_get_solv_pool(pakfire->pool);
- if (!p->installed)
+ if (!pakfire->pool->installed)
return NULL;
- return pakfire_repo_create_from_repo(pakfire, p->installed);
+ return pakfire_repo_create_from_repo(pakfire, pakfire->pool->installed);
}
PAKFIRE_EXPORT void pakfire_set_installed_repo(Pakfire pakfire, PakfireRepo repo) {
- Pool* p = pakfire_pool_get_solv_pool(pakfire->pool);
-
if (!repo) {
- pool_set_installed(p, NULL);
+ pool_set_installed(pakfire->pool, NULL);
+ return;
+ }
+
+ pool_set_installed(pakfire->pool, pakfire_repo_get_repo(repo));
+}
+
+PAKFIRE_EXPORT const char** pakfire_get_installonly(Pakfire pakfire) {
+ Queue q;
+ queue_init_clone(&q, &pakfire->installonly);
+
+ const char** installonly = pakfire_malloc(sizeof(const char*) * (q.count + 1));
+
+ int i = 0;
+ while (q.count) {
+ installonly[i++] = pool_id2str(pakfire->pool, queue_shift(&q));
+ }
+ installonly[i] = NULL;
+
+ queue_free(&q);
+
+ return installonly;
+}
+
+Queue* pakfire_get_installonly_queue(Pakfire pakfire) {
+ return &pakfire->installonly;
+}
+
+PAKFIRE_EXPORT void pakfire_set_installonly(Pakfire pakfire, const char** installonly) {
+ queue_empty(&pakfire->installonly);
+
+ if (installonly == NULL)
return;
+
+ const char* name;
+ while ((name = *installonly++) != NULL)
+ queue_pushunique(&pakfire->installonly, pool_str2id(pakfire->pool, name, 1));
+}
+
+static PakfirePackageList pakfire_pool_dataiterator(Pakfire pakfire, const char* what, int key, int flags) {
+ PakfirePackageList list = pakfire_packagelist_create();
+ pakfire_pool_apply_changes(pakfire);
+
+ int di_flags = 0;
+ if (flags & PAKFIRE_SUBSTRING)
+ di_flags |= SEARCH_SUBSTRING;
+ else
+ di_flags |= SEARCH_STRING;
+
+ if (flags & PAKFIRE_ICASE)
+ di_flags |= SEARCH_NOCASE;
+ if (flags & PAKFIRE_GLOB)
+ di_flags |= SEARCH_GLOB;
+
+ Dataiterator di;
+ dataiterator_init(&di, pakfire->pool, 0, 0, key, what, di_flags);
+ while (dataiterator_step(&di)) {
+ PakfirePackage pkg = pakfire_package_create(pakfire, di.solvid);
+ pakfire_packagelist_push_if_not_exists(list, pkg);
}
+ dataiterator_free(&di);
+
+ return list;
+}
+
+static PakfirePackageList pakfire_search_name(Pakfire pakfire, const char* name, int flags) {
+ if (!flags) {
+ PakfirePackageList list = pakfire_packagelist_create();
+ pakfire_pool_apply_changes(pakfire);
+
+ Id id = pool_str2id(pakfire->pool, name, 0);
+ if (id == 0)
+ return list;
+
+ Id p, pp;
+ Pool* pool = pakfire->pool;
+ FOR_PROVIDES(p, pp, id) {
+ Solvable* s = pool_id2solvable(pakfire->pool, p);
+
+ if (s->name == id) {
+ PakfirePackage pkg = pakfire_package_create(pakfire, p);
+ pakfire_packagelist_push_if_not_exists(list, pkg);
+ }
+ }
+
+ return list;
+ }
+
+ return pakfire_pool_dataiterator(pakfire, name, SOLVABLE_NAME, flags);
+}
+
+static PakfirePackageList pakfire_search_provides(Pakfire pakfire, const char* provides, int flags) {
+ if (!flags) {
+ PakfirePackageList list = pakfire_packagelist_create();
+ pakfire_pool_apply_changes(pakfire);
+
+ Id id = pool_str2id(pakfire->pool, provides, 0);
+ if (id == 0)
+ return list;
+
+ Id p, pp;
+ Pool* pool = pakfire->pool;
+ FOR_PROVIDES(p, pp, id) {
+ PakfirePackage pkg = pakfire_package_create(pakfire, p);
+ pakfire_packagelist_push_if_not_exists(list, pkg);
+ }
+
+ return list;
+ }
+
+ return pakfire_pool_dataiterator(pakfire, provides, SOLVABLE_PROVIDES, flags);
+}
+
+PAKFIRE_EXPORT PakfirePackageList pakfire_whatprovides(Pakfire pakfire, const char* what, int flags) {
+ if (flags & PAKFIRE_NAME_ONLY) {
+ flags &= ~PAKFIRE_NAME_ONLY;
+
+ return pakfire_search_name(pakfire, what, flags);
+ } else {
+ return pakfire_search_provides(pakfire, what, flags);
+ }
+}
- pool_set_installed(p, pakfire_repo_get_repo(repo));
+PAKFIRE_EXPORT PakfirePackageList pakfire_search(Pakfire pakfire, const char* what, int flags) {
+ return pakfire_pool_dataiterator(pakfire, what, 0, PAKFIRE_SUBSTRING);
}
#include <assert.h>
-#include <solv/evr.h>
#include <solv/pool.h>
-#include <solv/poolarch.h>
#include <solv/queue.h>
#include <solv/repo.h>
#include <pakfire/types.h>
#include <pakfire/util.h>
-struct _PakfirePool {
- Pool* pool;
- int provides_ready;
- Queue installonly;
+// This is just being left here for compatibility
+struct _PakfirePool {
+ Pakfire pakfire;
PakfireCache cache;
int nrefs;
};
DEBUG("Allocated Pool at %p\n", pool);
pool->nrefs = 1;
- // Initialize pool
- pool->pool = pool_create();
- queue_init(&pool->installonly);
-
- // Self-reference this object in libsolv
- pool->pool->appdata = pool;
-
- // Set architecture
- const char* arch = pakfire_get_arch(pakfire);
- pool_setarch(pool->pool, arch);
+ pool->pakfire = pakfire_ref(pakfire);
}
return pool;
}
-static void pakfire_pool_free_repos(Pool* pool) {
- Repo* repo;
- int i;
-
- FOR_REPOS(i, repo) {
- PakfireRepo r = repo->appdata;
- if (r == NULL)
- continue;
-
- pakfire_repo_unref(r);
- }
-}
-
static void pakfire_pool_free(PakfirePool pool) {
- pakfire_pool_free_repos(pool->pool);
-
- queue_free(&pool->installonly);
-
- pool_free(pool->pool);
+ pakfire_unref(pool->pakfire);
pakfire_free(pool);
DEBUG("Released Pool at %p\n", pool);
}
Pool* pakfire_pool_get_solv_pool(PakfirePool pool) {
- return pool->pool;
+ return pakfire_get_solv_pool(pool->pakfire);
}
PAKFIRE_EXPORT int pakfire_pool_version_compare(PakfirePool pool, const char* evr1, const char* evr2) {
- return pool_evrcmp_str(pool->pool, evr1, evr2, EVRCMP_COMPARE);
+ return pakfire_version_compare(pool->pakfire, evr1, evr2);
}
PAKFIRE_EXPORT int pakfire_pool_count(PakfirePool pool) {
+ Pool* p = pakfire_get_solv_pool(pool->pakfire);
int cnt = 0;
- for (int i = 2; i < pool->pool->nsolvables; i++) {
- Solvable* s = pool->pool->solvables + i;
+ for (int i = 2; i < p->nsolvables; i++) {
+ Solvable* s = p->solvables + i;
if (s->repo)
cnt++;
}
return cnt;
}
-void pakfire_pool_has_changed(PakfirePool pool) {
- pool->provides_ready = 0;
-}
-
-void pakfire_pool_apply_changes(PakfirePool pool) {
- if (!pool->provides_ready) {
- pool_addfileprovides(pool->pool);
- pool_createwhatprovides(pool->pool);
- pool->provides_ready = 1;
- }
-}
-
PAKFIRE_EXPORT const char** pakfire_pool_get_installonly(PakfirePool pool) {
- Queue q;
- queue_init_clone(&q, &pool->installonly);
-
- const char** installonly = pakfire_malloc(sizeof(const char*) * (q.count + 1));
-
- int i = 0;
- while (q.count) {
- installonly[i++] = pool_id2str(pool->pool, queue_shift(&q));
- }
- installonly[i] = NULL;
-
- queue_free(&q);
-
- return installonly;
+ return pakfire_get_installonly(pool->pakfire);
}
Queue* pakfire_pool_get_installonly_queue(PakfirePool pool) {
- return &pool->installonly;
+ return pakfire_get_installonly_queue(pool->pakfire);
}
PAKFIRE_EXPORT void pakfire_pool_set_installonly(PakfirePool pool, const char** installonly) {
- queue_empty(&pool->installonly);
-
- if (installonly == NULL)
- return;
-
- const char* name;
- while ((name = *installonly++) != NULL)
- queue_pushunique(&pool->installonly, pool_str2id(pool->pool, name, 1));
+ pakfire_set_installonly(pool->pakfire, installonly);
}
PAKFIRE_EXPORT const char* pakfire_pool_get_cache_path(PakfirePool pool) {
return NULL;
}
-static PakfirePackageList pakfire_pool_dataiterator(PakfirePool pool, const char* what, int key, int flags) {
- PakfirePackageList list = pakfire_packagelist_create();
- pakfire_pool_apply_changes(pool);
-
- int di_flags = 0;
- if (flags & PAKFIRE_SUBSTRING)
- di_flags |= SEARCH_SUBSTRING;
- else
- di_flags |= SEARCH_STRING;
-
- if (flags & PAKFIRE_ICASE)
- di_flags |= SEARCH_NOCASE;
- if (flags & PAKFIRE_GLOB)
- di_flags |= SEARCH_GLOB;
-
- Dataiterator di;
- dataiterator_init(&di, pool->pool, 0, 0, key, what, di_flags);
- while (dataiterator_step(&di)) {
- PakfirePackage pkg = pakfire_package_create(pool, di.solvid);
- pakfire_packagelist_push_if_not_exists(list, pkg);
- }
- dataiterator_free(&di);
-
- return list;
-}
-
-static PakfirePackageList pakfire_pool_search_name(PakfirePool _pool, const char* name, int flags) {
- if (!flags) {
- PakfirePackageList list = pakfire_packagelist_create();
- pakfire_pool_apply_changes(_pool);
-
- Pool* pool = _pool->pool;
- Id id = pool_str2id(pool, name, 0);
- if (id == 0)
- return list;
-
- Id p, pp;
- FOR_PROVIDES(p, pp, id) {
- Solvable* s = pool_id2solvable(pool, p);
-
- if (s->name == id) {
- PakfirePackage pkg = pakfire_package_create(_pool, p);
- pakfire_packagelist_push_if_not_exists(list, pkg);
- }
- }
-
- return list;
- }
-
- return pakfire_pool_dataiterator(_pool, name, SOLVABLE_NAME, flags);
-}
-
-static PakfirePackageList pakfire_pool_search_provides(PakfirePool _pool, const char* provides, int flags) {
- if (!flags) {
- PakfirePackageList list = pakfire_packagelist_create();
- pakfire_pool_apply_changes(_pool);
-
- Pool* pool = _pool->pool;
- Id id = pool_str2id(pool, provides, 0);
- if (id == 0)
- return list;
-
- Id p, pp;
- FOR_PROVIDES(p, pp, id) {
- PakfirePackage pkg = pakfire_package_create(_pool, p);
- pakfire_packagelist_push_if_not_exists(list, pkg);
- }
-
- return list;
- }
-
- return pakfire_pool_dataiterator(_pool, provides, SOLVABLE_PROVIDES, flags);
-}
-
-PAKFIRE_EXPORT PakfirePackageList pakfire_pool_whatprovides(PakfirePool pool, const char* what, int flags) {
- assert((flags & ~(PAKFIRE_ICASE|PAKFIRE_NAME_ONLY|PAKFIRE_GLOB)) == 0);
-
- if (flags & PAKFIRE_NAME_ONLY) {
- flags &= ~PAKFIRE_NAME_ONLY;
-
- return pakfire_pool_search_name(pool, what, flags);
- } else {
- return pakfire_pool_search_provides(pool, what, flags);
- }
+PakfirePackageList pakfire_pool_whatprovides(PakfirePool pool, const char* provides, int flags) {
+ return pakfire_whatprovides(pool->pakfire, provides, flags);
}
-PAKFIRE_EXPORT PakfirePackageList pakfire_pool_search(PakfirePool pool, const char* what, int flags) {
- return pakfire_pool_dataiterator(pool, what, 0, PAKFIRE_SUBSTRING);
+PakfirePackageList pakfire_pool_search(PakfirePool pool, const char* what, int flags) {
+ return pakfire_search(pool->pakfire, what, flags);
}
PAKFIRE_EXPORT char* pakfire_pool_tmpdup(Pool* pool, const char* s) {