summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2011-04-27 13:08:20 +0200
committerJulian Andres Klode <jak@debian.org>2011-04-27 13:08:20 +0200
commit6282a925c2e32aeaa342b789470a01b6dcf70890 (patch)
tree8d1e2dd556810263df517a6eed9ad615d8a98532 /python
parent58cebce48503e2478f59cbfe0e1f9849156d6337 (diff)
downloadpython-apt-6282a925c2e32aeaa342b789470a01b6dcf70890.tar.gz
apt_pkg: Add OrderList, wanted for mancoosi (Closes: #623485)
Diffstat (limited to 'python')
-rw-r--r--python/apt_pkgmodule.cc18
-rw-r--r--python/apt_pkgmodule.h3
-rw-r--r--python/orderlist.cc317
-rw-r--r--python/python-apt-helpers.cc1
-rw-r--r--python/python-apt.h8
5 files changed, 346 insertions, 1 deletions
diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc
index a8b8d2f4..139ff016 100644
--- a/python/apt_pkgmodule.cc
+++ b/python/apt_pkgmodule.cc
@@ -24,6 +24,7 @@
#include <apt-pkg/sha256.h>
#include <apt-pkg/init.h>
#include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/orderlist.h>
#include <sys/stat.h>
#include <libintl.h>
@@ -734,7 +735,10 @@ static struct _PyAptPkgAPIStruct API = {
&PyVersion_ToCpp, // version_tocpp
&PyGroup_Type, // group_type
&PyGroup_FromCpp, // group_fromcpp
- &PyGroup_ToCpp // group_tocpp
+ &PyGroup_ToCpp, // group_tocpp
+ &PyOrderList_Type, // orderlist_type
+ &PyOrderList_FromCpp, // orderlist_fromcpp
+ &PyOrderList_ToCpp // orderlist_tocpp
};
@@ -843,6 +847,7 @@ extern "C" void initapt_pkg()
ADDTYPE(Module,"AcquireItemDesc",&PyAcquireItemDesc_Type);
ADDTYPE(Module,"SystemLock",&PySystemLock_Type);
ADDTYPE(Module,"FileLock",&PyFileLock_Type);
+ ADDTYPE(Module,"OrderList",&PyOrderList_Type);
// Tag file constants
PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER",
CharCharToList(TFRewritePackageOrder));
@@ -850,6 +855,16 @@ extern "C" void initapt_pkg()
PyModule_AddObject(Module,"REWRITE_SOURCE_ORDER",
CharCharToList(TFRewriteSourceOrder));
+ PyDict_SetItemString(PyOrderList_Type.tp_dict, "FLAG_ADDED", MkPyNumber(pkgOrderList::Added));
+ PyDict_SetItemString(PyOrderList_Type.tp_dict, "FLAG_ADD_PENDIG", MkPyNumber(pkgOrderList::AddPending));
+ PyDict_SetItemString(PyOrderList_Type.tp_dict, "FLAG_IMMEDIATE", MkPyNumber(pkgOrderList::Immediate));
+ PyDict_SetItemString(PyOrderList_Type.tp_dict, "FLAG_LOOP", MkPyNumber(pkgOrderList::Loop));
+ PyDict_SetItemString(PyOrderList_Type.tp_dict, "FLAG_UNPACKED", MkPyNumber(pkgOrderList::UnPacked));
+ PyDict_SetItemString(PyOrderList_Type.tp_dict, "FLAG_CONFIGURED", MkPyNumber(pkgOrderList::Configured));
+ PyDict_SetItemString(PyOrderList_Type.tp_dict, "FLAG_REMOVED", MkPyNumber(pkgOrderList::Removed));
+ PyDict_SetItemString(PyOrderList_Type.tp_dict, "FLAG_IN_LIST", MkPyNumber(pkgOrderList::InList));
+ PyDict_SetItemString(PyOrderList_Type.tp_dict, "FLAG_AFTER", MkPyNumber(pkgOrderList::After));
+ PyDict_SetItemString(PyOrderList_Type.tp_dict, "FLAG_STATES_MASK", MkPyNumber(pkgOrderList::States));
// Acquire constants.
// some constants
@@ -983,6 +998,7 @@ extern "C" void initapt_pkg()
PyModule_AddIntConstant(Module,"INSTSTATE_HOLD",pkgCache::State::Hold);
PyModule_AddIntConstant(Module,"INSTSTATE_HOLD_REINSTREQ",pkgCache::State::HoldReInstReq);
+
// DEPRECATED API
#ifdef COMPAT_0_7
PyModule_AddObject(Module,"RewritePackageOrder",
diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h
index 7a04204c..89179551 100644
--- a/python/apt_pkgmodule.h
+++ b/python/apt_pkgmodule.h
@@ -134,6 +134,7 @@ extern PyTypeObject PyAcquireItemDesc_Type;
extern PyTypeObject PyAcquireWorker_Type;
extern PyTypeObject PySystemLock_Type;
extern PyTypeObject PyFileLock_Type;
+extern PyTypeObject PyOrderList_Type;
// Functions to be exported in the public API.
@@ -159,6 +160,7 @@ extern PyTypeObject PyFileLock_Type;
# define PyPackage_ToCpp GetCpp<pkgCache::PkgIterator>
# define PyPackageFile_ToCpp GetCpp<pkgCache::PkgFileIterator>
# define PyIndexFile_ToCpp GetCpp<pkgIndexFile*>
+# define PyOrderList_ToCpp GetCpp<pkgOrderList*>
# define PyPackageList_ToCpp GetCpp<PkgListStruct> // TODO
# define PyPackageManager_ToCpp GetCpp<pkgPackageManager*>
# define PyPackageRecords_ToCpp GetCpp<PkgRecordsStruct> // TODO
@@ -191,6 +193,7 @@ PyObject* PyMetaIndex_FromCpp(metaIndex* const &obj, bool Delete, PyObject *Owne
PyObject* PyPackage_FromCpp(pkgCache::PkgIterator const &obj, bool Delete, PyObject *Owner);
PyObject* PyGroup_FromCpp(pkgCache::GrpIterator const &obj, bool Delete, PyObject *Owner);
PyObject* PyIndexFile_FromCpp(pkgIndexFile* const &obj, bool Delete, PyObject *Owner);
+PyObject* PyOrderList_FromCpp(pkgOrderList* const &obj, bool Delete, PyObject *Owner);
PyObject* PyPackageFile_FromCpp(pkgCache::PkgFileIterator const &obj, bool Delete, PyObject *Owner);
//PyObject* PyPackageList_FromCpp(PkgListStruct const &obj, bool Delete, PyObject *Owner);
PyObject* PyPackageManager_FromCpp(pkgPackageManager* const &obj, bool Delete, PyObject *Owner);
diff --git a/python/orderlist.cc b/python/orderlist.cc
new file mode 100644
index 00000000..9fbed5f2
--- /dev/null
+++ b/python/orderlist.cc
@@ -0,0 +1,317 @@
+/*
+ * orderlist.cc - Wrapper around pkgOrderList
+ *
+ * Copyright 2011 Julian Andres Klode <jak@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <Python.h>
+#include "apt_pkgmodule.h"
+#include "generic.h"
+#include <apt-pkg/orderlist.h>
+
+struct PyOrderList : CppPyObject<pkgOrderList*> {
+ pkgCache::PkgIterator current;
+ int nextIndex;
+};
+
+static PyObject *order_list_new(PyTypeObject *type,PyObject *args,
+ PyObject *kwds)
+{
+ PyObject *pyDepCache = NULL;
+ char *kwlist[] = {"depcache", NULL};
+ if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", kwlist,
+ &PyDepCache_Type, &pyDepCache)
+ == 0)
+ return 0;
+
+ pkgDepCache *depCache = PyDepCache_ToCpp(pyDepCache);
+ return PyOrderList_FromCpp(new pkgOrderList(depCache), true,
+ pyDepCache);
+}
+
+static const char order_list_append_doc[] =
+ "append(pkg: Package)\n\n"
+ "Append a package to the end of the list.";
+static PyObject *order_list_append(PyObject *self,PyObject *args)
+{
+ pkgOrderList *list = GetCpp<pkgOrderList*>(self);
+ PyObject *pyPackage = NULL;
+ if (PyArg_ParseTuple(args, "O!", &PyPackage_Type, &pyPackage) == 0)
+ return 0;
+
+ list->push_back(PyPackage_ToCpp(pyPackage));
+ Py_RETURN_NONE;
+}
+
+static const char order_list_score_doc[] =
+ "score(pkg: Package) -> int\n\n"
+ "Return the score of the package.";
+static PyObject *order_list_score(PyObject *self,PyObject *args)
+{
+ pkgOrderList *list = GetCpp<pkgOrderList*>(self);
+ PyObject *pyPackage = NULL;
+ if (PyArg_ParseTuple(args, "O!", &PyPackage_Type, &pyPackage) == 0)
+ return 0;
+
+ return MkPyNumber(list->Score(PyPackage_ToCpp(pyPackage)));
+}
+
+static const char order_list_order_critical_doc[] =
+ "order_critical()\n\n"
+ "Order by PreDepends only (critical unpack order).";
+static PyObject *order_list_order_critical(PyObject *self,PyObject *args)
+{
+ pkgOrderList *list = GetCpp<pkgOrderList*>(self);
+ if (PyArg_ParseTuple(args, "") == 0)
+ return 0;
+
+ list->OrderCritical();
+
+ Py_INCREF(Py_None);
+ return HandleErrors(Py_None);
+}
+
+static const char order_list_order_unpack_doc[] =
+ "order_unpack()\n\n"
+ "Order the packages for unpacking (see Debian Policy).";
+static PyObject *order_list_order_unpack(PyObject *self,PyObject *args)
+{
+ pkgOrderList *list = GetCpp<pkgOrderList*>(self);
+ if (PyArg_ParseTuple(args, "") == 0)
+ return 0;
+
+ list->OrderUnpack();
+ Py_INCREF(Py_None);
+ return HandleErrors(Py_None);
+}
+
+static const char order_list_order_configure_doc[] =
+ "order_configure()\n\n"
+ "Order the packages for configuration (see Debian Policy).";
+static PyObject *order_list_order_configure(PyObject *self,PyObject *args)
+{
+ pkgOrderList *list = GetCpp<pkgOrderList*>(self);
+ if (PyArg_ParseTuple(args, "") == 0)
+ return 0;
+
+ list->OrderConfigure();
+
+ Py_INCREF(Py_None);
+ return HandleErrors(Py_None);
+}
+
+static bool valid_flags(unsigned int flags) {
+ return (flags & ~pkgOrderList::Added
+ & ~pkgOrderList::AddPending
+ & ~pkgOrderList::Immediate
+ & ~pkgOrderList::Loop
+ & ~pkgOrderList::UnPacked
+ & ~pkgOrderList::Configured
+ & ~pkgOrderList::Removed
+ & ~pkgOrderList::InList
+ & ~pkgOrderList::After
+ & ~pkgOrderList::States) == 0;
+}
+
+static const char order_list_flag_doc[] =
+ "flag(pkg: Package, flag: int[, unset_flags: int])\n\n"
+ "Flag the package, set flags in 'flag' and remove flags in\n"
+ "'unset_flags'.";
+static PyObject *order_list_flag(PyObject *self,PyObject *args)
+{
+ pkgOrderList *list = GetCpp<pkgOrderList*>(self);
+
+ PyObject *pyPkg = NULL;
+ unsigned int flags = 0;
+ unsigned int unset_flags = 0;
+ if (PyArg_ParseTuple(args, "O!I|I", &PyPackage_Type, &pyPkg,
+ &flags, &unset_flags) == 0)
+ return 0;
+
+ if (!valid_flags(flags))
+ return PyErr_Format(PyExc_ValueError, "flags (%u) is"
+ " not a valid combination of flags.",
+ flags);
+ if (!valid_flags(unset_flags))
+ return PyErr_Format(PyExc_ValueError, "unset_flags (%u) is"
+ " not a valid combination of flags.",
+ unset_flags);
+
+ list->Flag(PyPackage_ToCpp(pyPkg), flags, unset_flags);
+
+ Py_RETURN_NONE;
+}
+
+static const char order_list_is_flag_doc[] =
+ "is_flag(pkg: Package, flag: int)\n\n"
+ "Check if the flag(s) are set.";
+static PyObject *order_list_is_flag(PyObject *self,PyObject *args)
+{
+ pkgOrderList *list = GetCpp<pkgOrderList*>(self);
+ PyObject *pyPkg = NULL;
+ unsigned int flags = 0;
+ if (PyArg_ParseTuple(args, "O!I", &PyPackage_Type, &pyPkg,
+ &flags) == 0)
+ return 0;
+
+ if (!valid_flags(flags))
+ return PyErr_Format(PyExc_ValueError, "flags (%u) is"
+ " not a valid combination of flags.",
+ flags);
+
+ return PyBool_FromLong(list->IsFlag(PyPackage_ToCpp(pyPkg), flags));
+}
+
+static const char order_list_wipe_flags_doc[] =
+ "wipe_flags(flags: int)\n\n"
+ "Remove the flags in 'flags' from all packages in this list";
+static PyObject *order_list_wipe_flags(PyObject *self,PyObject *args)
+{
+ pkgOrderList *list = GetCpp<pkgOrderList*>(self);
+ unsigned int flags = 0;
+ if (PyArg_ParseTuple(args, "I", &flags) == 0)
+ return 0;
+
+ if (!valid_flags(flags))
+ return PyErr_Format(PyExc_ValueError, "flags (%u) is"
+ " not a valid combination of flags.",
+ flags);
+
+ list->WipeFlags(flags);
+ Py_RETURN_NONE;
+}
+
+static const char order_list_is_now_doc[] =
+ "is_now(pkg: Package)\n\n"
+ "Check if the package is flagged for any state but removal.";
+static PyObject *order_list_is_now(PyObject *self,PyObject *args)
+{
+ pkgOrderList *list = GetCpp<pkgOrderList*>(self);
+ PyObject *pyPkg = NULL;
+ if (PyArg_ParseTuple(args, "O!", &PyPackage_Type, &pyPkg) == 0)
+ return 0;
+
+ return PyBool_FromLong(list->IsNow(PyPackage_ToCpp(pyPkg)));
+}
+
+static const char order_list_is_missing_doc[] =
+ "is_now(pkg: Package)\n\n"
+ "Check if the package is marked for install.";
+static PyObject *order_list_is_missing(PyObject *self,PyObject *args)
+{
+ pkgOrderList *list = GetCpp<pkgOrderList*>(self);
+ PyObject *pyPkg = NULL;
+ if (PyArg_ParseTuple(args, "O!", &PyPackage_Type, &pyPkg) == 0)
+ return 0;
+
+ return PyBool_FromLong(list->IsMissing(PyPackage_ToCpp(pyPkg)));
+}
+
+
+#define METHOD(name) {#name, order_list_##name, METH_VARARGS,\
+ order_list_##name##_doc}
+
+static PyMethodDef order_list_methods[] = {
+ METHOD(append),
+ METHOD(score),
+ METHOD(order_critical),
+ METHOD(order_unpack),
+ METHOD(order_configure),
+ METHOD(flag),
+ METHOD(is_flag),
+ METHOD(is_now),
+ METHOD(is_missing),
+ METHOD(wipe_flags),
+ {}
+};
+
+static PyObject *order_list_seq_item(PyObject *self,Py_ssize_t index)
+{
+ pkgOrderList *list = GetCpp<pkgOrderList*>(self);
+ PyObject *owner = GetOwner<pkgOrderList*>(self);
+ PyObject *pycache = GetOwner<pkgOrderList*>(owner);
+ pkgCache *cache = PyCache_ToCpp(pycache);
+
+ if (index < 0 || index >= list->size())
+ return PyErr_Format(PyExc_IndexError, "Out of range: %zd", index);
+
+ return PyPackage_FromCpp(pkgCache::PkgIterator(*cache,
+ *(list->begin() + index)),
+ true, owner);
+}
+
+Py_ssize_t order_list_seq_length(PyObject *self)
+{
+ return GetCpp<pkgOrderList*>(self)->size();
+}
+
+static PySequenceMethods order_list_as_sequence =
+{
+ order_list_seq_length, // sq_length
+ 0, // sq_concat
+ 0, // sq_repeat
+ order_list_seq_item, // sq_item
+ 0, // sq_ass_item
+ 0, // sq_contains
+ 0, // sq_inplace_concat
+ 0 // sq_inplace_repeat
+};
+
+static const char order_list_doc[] = "OrderList(depcache: DepCache)\n\n"
+ "Sequence type for packages with special ordering methods.";
+PyTypeObject PyOrderList_Type = {
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ "apt_pkg.OrderList", // tp_name
+ sizeof(CppPyObject<pkgOrderList*>), // tp_basicsize
+ 0, // tp_itemsize
+ // Methods
+ CppDeallocPtr<pkgOrderList*>, // tp_dealloc
+ 0, // tp_print
+ 0, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ &order_list_as_sequence, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+ 0, // tp_call
+ 0, // tp_str
+ 0, // tp_getattro
+ 0, // tp_setattro
+ 0, // tp_as_buffer
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ order_list_doc, // tp_doc
+ 0, // tp_traverse
+ 0, // tp_clear
+ 0, // tp_richcompare
+ 0, // tp_weaklistoffset
+ 0, // tp_iter
+ 0, // tp_iternext
+ order_list_methods, // tp_methods
+ 0, // tp_members
+ 0, // tp_getset
+ 0, // tp_base
+ 0, // tp_dict
+ 0, // tp_descr_get
+ 0, // tp_descr_set
+ 0, // tp_dictoffset
+ 0, // tp_init
+ 0, // tp_alloc
+ order_list_new, // tp_new
+};
diff --git a/python/python-apt-helpers.cc b/python/python-apt-helpers.cc
index f50f62c4..079b93cf 100644
--- a/python/python-apt-helpers.cc
+++ b/python/python-apt-helpers.cc
@@ -54,6 +54,7 @@ NEW_FROM(PyMetaIndex_FromCpp,&PyMetaIndex_Type,metaIndex*)
NEW_FROM(PyPackage_FromCpp,&PyPackage_Type,pkgCache::PkgIterator)
NEW_FROM(PyGroup_FromCpp,&PyGroup_Type,pkgCache::GrpIterator)
NEW_FROM(PyIndexFile_FromCpp,&PyIndexFile_Type,pkgIndexFile*)
+NEW_FROM(PyOrderList_FromCpp,&PyOrderList_Type,pkgOrderList*)
NEW_FROM(PyPackageFile_FromCpp,&PyPackageFile_Type,pkgCache::PkgFileIterator)
//NEW_FROM(PyPackageList_FromCpp,&PyPackageList_Type,PkgListStruct)
NEW_FROM(PyPackageManager_FromCpp,&PyPackageManager_Type,pkgPackageManager*)
diff --git a/python/python-apt.h b/python/python-apt.h
index ca8b557b..6f2a02df 100644
--- a/python/python-apt.h
+++ b/python/python-apt.h
@@ -170,6 +170,10 @@ struct _PyAptPkgAPIStruct {
PyTypeObject *group_type;
PyObject* (*group_fromcpp)(pkgCache::GrpIterator const &obj, bool Delete, PyObject *Owner);
pkgCache::GrpIterator& (*group_tocpp)(PyObject *self);
+
+ PyTypeObject *orderlist_type;
+ PyObject* (*orderlist_fromcpp)(pkgOrderList* const &obj, bool Delete, PyObject *Owner);
+ pkgOrderList*& (*orderlist_tocpp)(PyObject *self);
};
// Checking macros.
@@ -228,6 +232,7 @@ struct _PyAptPkgAPIStruct {
# define PyPackage_CheckExact(op) (op->op_type == &PyPackage_Type)
# define PyPackageFile_CheckExact(op) (op->op_type == &PyPackageFile_Type)
# define PyIndexFile_CheckExact(op) (op->op_type == &PyIndexFile_Type)
+# define PyOrderList_CheckExact(op) (op->op_type == &PyOrderList_Type)
# define PyPackageList_CheckExact(op) (op->op_type == &PyPackageList_Type)
# define PyPackageManager_CheckExact(op) (op->op_type == &PyPackageManager_Type)
# define PyPackageRecords_CheckExact(op) (op->op_type == &PyPackageRecords_Type)
@@ -273,6 +278,7 @@ static int import_apt_pkg(void) {
# define PyPackage_Type *(_PyAptPkg_API->package_type)
# define PyPackageFile_Type *(_PyAptPkg_API->packagefile_type)
# define PyIndexFile_Type *(_PyAptPkg_API->packageindexfile_type)
+# define PyOrderList_Type *(_PyAptPkg_API->orderlist_type)
# define PyPackageList_Type *(_PyAptPkg_API->packagelist_type)
# define PyPackageManager_Type *(_PyAptPkg_API->packagemanager_type)
# define PyPackageRecords_Type *(_PyAptPkg_API->packagerecords_type)
@@ -306,6 +312,7 @@ static int import_apt_pkg(void) {
# define PyPackage_ToCpp _PyAptPkg_API->package_tocpp
# define PyPackageFile_ToCpp _PyAptPkg_API->packagefile_tocpp
# define PyIndexFile_ToCpp _PyAptPkg_API->packageindexfile_tocpp
+# define PyOrderList_ToCpp _PyAptPkg_API->orderlist_tocpp // NULL
# define PyPackageList_ToCpp _PyAptPkg_API->packagelist_tocpp // NULL
# define PyPackageManager_ToCpp _PyAptPkg_API->packagemanager_tocpp
# define PyPackageRecords_ToCpp _PyAptPkg_API->packagerecords_tocpp
@@ -339,6 +346,7 @@ static int import_apt_pkg(void) {
# define PyPackage_FromCpp _PyAptPkg_API->package_fromcpp
# define PyPackageFile_FromCpp _PyAptPkg_API->packagefile_fromcpp
# define PyIndexFile_FromCpp _PyAptPkg_API->packageindexfile_fromcpp
+# define PyOrderList_FromCpp _PyAptPkg_API->orderlist_fromcpp // NULL
# define PyPackageList_FromCpp _PyAptPkg_API->packagelist_fromcpp // NULL
# define PyPackageManager_FromCpp _PyAptPkg_API->packagemanager_fromcpp
# define PyPackageRecords_FromCpp _PyAptPkg_API->packagerecords_fromcpp