#include <Python.h>
#include <pakfire/archive.h>
+#include <pakfire/filelist.h>
#include <pakfire/package.h>
#include <pakfire/repo.h>
#include <pakfire/util.h>
#include "archive.h"
#include "errors.h"
-#include "file.h"
#include "key.h"
#include "package.h"
+#include "util.h"
PyObject* new_archive(PyTypeObject* type, struct pakfire_archive* archive) {
ArchiveObject* self = (ArchiveObject *)type->tp_alloc(type, 0);
}
static PyObject* Archive_get_filelist(ArchiveObject* self) {
- int r;
-
// Fetch the filelist
struct pakfire_filelist* filelist = pakfire_archive_get_filelist(self->archive);
if (!filelist) {
return NULL;
}
- const size_t size = pakfire_filelist_size(filelist);
-
- // Create a new Python list
- PyObject* list = PyList_New(0);
- if (!list)
- goto ERROR;
-
- for (unsigned int i = 0; i < size; i++) {
- struct pakfire_file* file = pakfire_filelist_get(filelist, i);
- if (!file)
- goto ERROR;
-
- // Create a new File object
- PyObject* obj = new_file(file);
- if (!obj)
- goto ERROR;
-
- // Append the new object to the list
- r = PyList_Append(list, obj);
- Py_DECREF(obj);
-
- // If we could not append to the list, we will break
- if (r)
- goto ERROR;
-
- // Free file
- pakfire_file_unref(file);
- }
-
- goto OUT;
+ // Convert to filelist
+ PyObject* _filelist = PyList_FromFileList(filelist);
-ERROR:
- if (list) {
- Py_DECREF(list);
- list = NULL;
- }
-
-OUT:
- if (filelist)
- pakfire_filelist_unref(filelist);
+ // Cleanup
+ pakfire_filelist_unref(filelist);
- return list;
+ return _filelist;
}
static struct PyMethodDef Archive_methods[] = {
#include <time.h>
#include <unistd.h>
+#include <pakfire/filelist.h>
#include <pakfire/package.h>
#include <pakfire/packagelist.h>
+#include "file.h"
#include "package.h"
#include "util.h"
return list;
}
+
+PyObject* PyList_FromFileList(struct pakfire_filelist* filelist) {
+ struct pakfire_file* file = NULL;
+ PyObject* f = NULL;
+ int r;
+
+ PyObject* list = PyList_New(0);
+ if (!list)
+ goto ERROR;
+
+ // Fetch size
+ const size_t size = pakfire_filelist_size(filelist);
+
+ for (unsigned int i = 0; i < size; i++) {
+ file = pakfire_filelist_get(filelist, i);
+ if (!file)
+ goto ERROR;
+
+ // Create a new File object
+ f = new_file(file);
+ if (!f)
+ goto ERROR;
+
+ // Append the new object to the list
+ r = PyList_Append(list, f);
+ Py_DECREF(f);
+
+ // If we could not append to the list, we will break
+ if (r)
+ goto ERROR;
+
+ // Free file
+ pakfire_file_unref(file);
+ }
+
+ return list;
+
+ERROR:
+ Py_XDECREF(list);
+ return NULL;
+}
#include <Python.h>
+#include <pakfire/filelist.h>
#include <pakfire/packagelist.h>
extern PyObject* performance_index(PyObject* self, PyObject* args);
PyObject* PyList_FromPackageList(struct pakfire_packagelist* packagelist);
+PyObject* PyList_FromFileList(struct pakfire_filelist* filelist);
#endif /* PYTHON_PAKFIRE_UTIL_H */