summaryrefslogtreecommitdiff
path: root/python/depcache.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2005-02-23 11:07:56 +0000
committerMichael Vogt <michael.vogt@ubuntu.com>2005-02-23 11:07:56 +0000
commitc17e7730c128ea465d0e9581a2f87a4e0c4869d3 (patch)
treee1cbac1b64d1a3ac95d14ccfd9a808b6e29a0864 /python/depcache.cc
parent827b21434e032d72b8353b67b737e78d013eb0c3 (diff)
downloadpython-apt-c17e7730c128ea465d0e9581a2f87a4e0c4869d3.tar.gz
* added basic depcache support
Diffstat (limited to 'python/depcache.cc')
-rw-r--r--python/depcache.cc149
1 files changed, 149 insertions, 0 deletions
diff --git a/python/depcache.cc b/python/depcache.cc
new file mode 100644
index 00000000..ea86bf3c
--- /dev/null
+++ b/python/depcache.cc
@@ -0,0 +1,149 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: depcache.cc,v 1.5 2003/06/03 03:03:23 mdz Exp $
+/* ######################################################################
+
+ DepCache - Wrapper for the depcache related functions
+
+ ##################################################################### */
+ /*}}}*/
+// Include Files /*{{{*/
+#include "generic.h"
+#include "apt_pkgmodule.h"
+
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cachefile.h>
+#include <apt-pkg/policy.h>
+#include <apt-pkg/sptr.h>
+
+#include <Python.h>
+
+
+// DepCache Class /*{{{*/
+// ---------------------------------------------------------------------
+
+struct PkgDepCacheStruct
+{
+ pkgDepCache depcache;
+
+ PkgDepCacheStruct(pkgCache *Cache, pkgPolicy *Policy)
+ : depcache(Cache,Policy) {};
+ // FIXME: wrap pkgPolicy as well and remove this "new() memory leak"
+ PkgDepCacheStruct(pkgCache *Cache)
+ : depcache(Cache,new pkgPolicy(Cache) ) {};
+ PkgDepCacheStruct() : depcache(NULL, NULL) {abort();};
+};
+
+static PyObject *PkgDepCacheInit(PyObject *Self,PyObject *Args)
+{
+ PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self);
+
+ // FIXME: argument should be OpProgress
+#if 0
+ PyObject *PkgFObj;
+ long int Index;
+ if (PyArg_ParseTuple(Args,"(O!l)",&PackageFileType,&PkgFObj,&Index) == 0)
+ return 0;
+#endif
+
+ Struct.depcache.Init(0);
+
+ return HandleErrors(Py_None);
+}
+
+static PyObject *PkgDepCacheGetCandidateVer(PyObject *Self,PyObject *Args)
+{
+ PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self);
+ PyObject *PackageObj;
+ PyObject *CandidateObj;
+ if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0)
+ return 0;
+
+ pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj);
+ pkgCache::VerIterator I = Struct.depcache.GetCandidateVer(Pkg);
+ CandidateObj = CppOwnedPyObject_NEW<pkgCache::VerIterator>(PackageObj,&VersionType,I);
+
+ return CandidateObj;
+}
+
+static PyMethodDef PkgDepCacheMethods[] =
+{
+ {"Init",PkgDepCacheInit,METH_VARARGS,"Init the depcache"},
+ {"GetCandidateVer",PkgDepCacheGetCandidateVer,METH_VARARGS,"Get candidate version"},
+ {}
+};
+
+
+static PyObject *DepCacheAttr(PyObject *Self,char *Name)
+{
+ PkgDepCacheStruct &Struct = GetCpp<PkgDepCacheStruct>(Self);
+
+ // size querries
+ if(strcmp("KeepCount",Name) == 0)
+ return Py_BuildValue("i", Struct.depcache.KeepCount());
+ else if(strcmp("InstCount",Name) == 0)
+ return Py_BuildValue("i", Struct.depcache.InstCount());
+ else if(strcmp("DelCount",Name) == 0)
+ return Py_BuildValue("i", Struct.depcache.DelCount());
+ else if(strcmp("BrokenCount",Name) == 0)
+ return Py_BuildValue("i", Struct.depcache.BrokenCount());
+ else if(strcmp("UsrSize",Name) == 0)
+ return Py_BuildValue("i", Struct.depcache.UsrSize());
+ else if(strcmp("DebSize",Name) == 0)
+ return Py_BuildValue("i", Struct.depcache.DebSize());
+
+
+#if 0
+ if (strcmp("FileList",Name) == 0)
+ {
+ PyObject *List = PyList_New(0);
+ for (pkgCache::PkgFileIterator I = Cache->FileBegin(); I.end() == false; I++)
+ {
+ PyObject *Obj;
+ Obj = CppOwnedPyObject_NEW<pkgCache::PkgFileIterator>(Self,&PackageFileType,I);
+ PyList_Append(List,Obj);
+ Py_DECREF(Obj);
+ }
+ return List;
+ }
+#endif
+ return Py_FindMethod(PkgDepCacheMethods,Self,Name);
+}
+
+
+
+
+PyTypeObject PkgDepCacheType =
+{
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, // ob_size
+ "pkgDepCache", // tp_name
+ sizeof(CppOwnedPyObject<pkgDepCache *>), // tp_basicsize
+ 0, // tp_itemsize
+ // Methods
+ CppOwnedDealloc<pkgDepCache *>, // tp_dealloc
+ 0, // tp_print
+ DepCacheAttr, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ 0, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+};
+
+
+PyObject *GetDepCache(PyObject *Self,PyObject *Args)
+{
+ PyObject *Owner;
+ if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0)
+ return 0;
+
+ return HandleErrors(CppOwnedPyObject_NEW<PkgDepCacheStruct>(Owner,
+ &PkgDepCacheType,
+ GetCpp<pkgCache *>(Owner)));
+}
+
+
+ /*}}}*/