summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/apt_pkgmodule.cc20
-rw-r--r--python/cache.cc37
-rw-r--r--python/progress.cc9
3 files changed, 50 insertions, 16 deletions
diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc
index faea423f..f20b0c87 100644
--- a/python/apt_pkgmodule.cc
+++ b/python/apt_pkgmodule.cc
@@ -680,6 +680,26 @@ extern "C" void initapt_pkg()
PyDict_SetItemString(PyAcquire_Type.tp_dict, "ResultFailed",
Py_BuildValue("i", pkgAcquire::Failed));
#endif
+ // Dependency constants
+ PyDict_SetItemString(PyDependency_Type.tp_dict, "TYPE_DEPENDS",
+ Py_BuildValue("i", pkgCache::Dep::Depends));
+ PyDict_SetItemString(PyDependency_Type.tp_dict, "TYPE_PREDEPENDS",
+ Py_BuildValue("i", pkgCache::Dep::PreDepends));
+ PyDict_SetItemString(PyDependency_Type.tp_dict, "TYPE_SUGGESTS",
+ Py_BuildValue("i", pkgCache::Dep::Suggests));
+ PyDict_SetItemString(PyDependency_Type.tp_dict, "TYPE_RECOMMENDS",
+ Py_BuildValue("i", pkgCache::Dep::Suggests));
+ PyDict_SetItemString(PyDependency_Type.tp_dict, "TYPE_CONFLICTS",
+ Py_BuildValue("i", pkgCache::Dep::Conflicts));
+ PyDict_SetItemString(PyDependency_Type.tp_dict, "TYPE_REPLACES",
+ Py_BuildValue("i", pkgCache::Dep::Replaces));
+ PyDict_SetItemString(PyDependency_Type.tp_dict, "TYPE_OBSOLETES",
+ Py_BuildValue("i", pkgCache::Dep::Obsoletes));
+ PyDict_SetItemString(PyDependency_Type.tp_dict, "TYPE_DPKG_BREAKS",
+ Py_BuildValue("i", pkgCache::Dep::DpkgBreaks));
+ PyDict_SetItemString(PyDependency_Type.tp_dict, "TYPE_ENHANCES",
+ Py_BuildValue("i", pkgCache::Dep::Enhances));
+
// PackageManager constants
PyDict_SetItemString(PyPackageManager_Type.tp_dict, "result_completed",
diff --git a/python/cache.cc b/python/cache.cc
index 084f6d8c..6bbf0766 100644
--- a/python/cache.cc
+++ b/python/cache.cc
@@ -27,6 +27,17 @@
class pkgSourceList;
+// must be in sync with pkgCache::DepType in libapt
+// it sucks to have it here duplicated, but we get it
+// translated from libapt and that is certainly not what
+// we want in a programing interface
+const char *UntranslatedDepTypes[] =
+{
+ "", "Depends","PreDepends","Suggests",
+ "Recommends","Conflicts","Replaces",
+ "Obsoletes", "Breaks", "Enhances"
+};
+
/*}}}*/
struct PkgListStruct
{
@@ -683,17 +694,7 @@ static PyObject *MakeDepends(PyObject *Owner,pkgCache::VerIterator &Ver,
// Switch/create a new dict entry
if (LastDepType != Start->Type || LastDep != 0)
{
- // must be in sync with pkgCache::DepType in libapt
- // it sucks to have it here duplicated, but we get it
- // translated from libapt and that is certainly not what
- // we want in a programing interface
- const char *Types[] =
- {
- "", "Depends","PreDepends","Suggests",
- "Recommends","Conflicts","Replaces",
- "Obsoletes", "Breaks", "Enhances"
- };
- PyObject *Dep = PyString_FromString(Types[Start->Type]);
+ PyObject *Dep = PyString_FromString(UntranslatedDepTypes[Start->Type]);
LastDepType = Start->Type;
LastDep = PyDict_GetItem(Dict,Dep);
if (LastDep == 0)
@@ -1194,6 +1195,18 @@ static PyObject *DependencyGetDepType(PyObject *Self,void*)
return PyString_FromString(Dep.DepType());
}
+static PyObject *DependencyGetDepTypeUntranslated(PyObject *Self,void*)
+{
+ pkgCache::DepIterator &Dep = GetCpp<pkgCache::DepIterator>(Self);
+ return PyString_FromString(UntranslatedDepTypes[Dep->Type]);
+}
+
+static PyObject *DependencyGetDepTypeEnum(PyObject *Self,void*)
+{
+ pkgCache::DepIterator &Dep = GetCpp<pkgCache::DepIterator>(Self);
+ return Py_BuildValue("i", Dep->Type);
+}
+
static PyObject *DependencyGetID(PyObject *Self,void*)
{
pkgCache::DepIterator &Dep = GetCpp<pkgCache::DepIterator>(Self);
@@ -1203,6 +1216,8 @@ static PyObject *DependencyGetID(PyObject *Self,void*)
static PyGetSetDef DependencyGetSet[] = {
{"comp_type",DependencyGetCompType},
{"dep_type",DependencyGetDepType},
+ {"dep_type_untranslated",DependencyGetDepTypeUntranslated},
+ {"dep_type_enum",DependencyGetDepTypeEnum},
{"id",DependencyGetID},
{"parent_pkg",DependencyGetParentPkg},
{"parent_ver",DependencyGetParentVer},
diff --git a/python/progress.cc b/python/progress.cc
index c754dd35..30f62763 100644
--- a/python/progress.cc
+++ b/python/progress.cc
@@ -129,11 +129,10 @@ bool PyFetchProgress::MediaChange(string Media, string Drive)
RunSimpleCallback("mediaChange", arglist, &result);
bool res = true;
- if(!PyArg_Parse(result, "b", &res))
- std::cerr << "result could not be parsed" << std::endl;
-
- // FIXME: find out what it should return usually
- //std::cerr << "res is: " << res << std::endl;
+ if(!PyArg_Parse(result, "b", &res)) {
+ // no return value or None, assume false
+ return false;
+ }
PyCbObj_BEGIN_ALLOW_THREADS
return res;