summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2005-11-18 01:01:37 +0000
committerMichael Vogt <michael.vogt@ubuntu.com>2005-11-18 01:01:37 +0000
commitc187e828e1661d09a8437214b2f90dcc25c05c99 (patch)
treea08f97e80e66887baafa5bd41384ab78ff92b082
parent4da233eef44c921152daf224a043ab8e2181ef9f (diff)
downloadpython-apt-c187e828e1661d09a8437214b2f90dcc25c05c99.tar.gz
* basic pkgAcquire + pkgPackageManager support added
-rw-r--r--debian/changelog3
-rw-r--r--doc/examples/acquire.py24
-rw-r--r--python/acquire.cc106
-rw-r--r--python/acquire.h6
-rw-r--r--python/apt_pkgmodule.cc6
-rw-r--r--python/apt_pkgmodule.h11
-rw-r--r--python/makefile2
-rw-r--r--python/pkgmanager.cc109
-rw-r--r--python/pkgrecords.cc10
-rw-r--r--python/pkgrecords.h10
-rw-r--r--python/sourcelist.cc7
-rw-r--r--python/sourcelist.h6
12 files changed, 283 insertions, 17 deletions
diff --git a/debian/changelog b/debian/changelog
index 1eb5022a..b0fe307f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,7 +1,8 @@
-python-apt (0.6.14.1) unstable; urgency=low
+python-apt (0.6.15) unstable; urgency=low
* fix a invalid return from cache.commit(), fail if a download failed
* apt.Package.candidateOrigin returns a class now
+ * added basic pkgAcquire and pkgPackageManager support
-- Michael Vogt <michael.vogt@ubuntu.com> Thu, 17 Nov 2005 13:00:14 +0100
diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py
new file mode 100644
index 00000000..12727232
--- /dev/null
+++ b/doc/examples/acquire.py
@@ -0,0 +1,24 @@
+import apt_pkg
+
+apt_pkg.init()
+
+cache = apt_pkg.GetCache()
+depcache = apt_pkg.GetDepCache(cache)
+
+recs = apt_pkg.GetPkgRecords(cache)
+list = apt_pkg.GetPkgSourceList()
+list.ReadMainList()
+
+pkg = cache["3ddesktop"]
+depcache.MarkInstall(pkg)
+
+fetcher = apt_pkg.GetAcquire()
+pm = apt_pkg.GetPackageManager(depcache)
+
+print pm
+print fetcher
+
+pm.GetArchives(fetcher,list,recs)
+
+fetcher.Run()
+
diff --git a/python/acquire.cc b/python/acquire.cc
new file mode 100644
index 00000000..550deb0e
--- /dev/null
+++ b/python/acquire.cc
@@ -0,0 +1,106 @@
+// Description /*{{{*/
+// $Id: acquire.cc,v 1.1 2003/06/03 03:03:23 mvo Exp $
+/* ######################################################################
+
+ Acquire - Wrapper for the acquire code
+
+ ##################################################################### */
+
+#include "generic.h"
+#include "apt_pkgmodule.h"
+#include "acquire.h"
+
+#include <apt-pkg/acquire-item.h>
+
+
+static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args)
+{
+ PkgAcquireStruct &Struct = GetCpp<PkgAcquireStruct>(Self);
+
+ if (PyArg_ParseTuple(Args, "") == 0)
+ return 0;
+
+ //FIXME: add pulse interval here
+ pkgAcquire::RunResult run = Struct.fetcher.Run();
+
+ return HandleErrors(Py_BuildValue("i",run));
+}
+
+static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args)
+{
+ PkgAcquireStruct &Struct = GetCpp<PkgAcquireStruct>(Self);
+
+ if (PyArg_ParseTuple(Args, "") == 0)
+ return 0;
+
+ Struct.fetcher.Shutdown();
+
+ Py_INCREF(Py_None);
+ return HandleErrors(Py_None);
+}
+
+static PyMethodDef PkgAcquireMethods[] =
+{
+ {"Run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"},
+ {}
+};
+
+
+static PyObject *AcquireAttr(PyObject *Self,char *Name)
+{
+ PkgAcquireStruct &Struct = GetCpp<PkgAcquireStruct>(Self);
+
+ if(strcmp("TotalNeeded",Name) == 0)
+ return Py_BuildValue("l", Struct.fetcher.TotalNeeded());
+ if(strcmp("FetchNeeded",Name) == 0)
+ return Py_BuildValue("l", Struct.fetcher.FetchNeeded());
+ if(strcmp("PartialPresent",Name) == 0)
+ return Py_BuildValue("l", Struct.fetcher.PartialPresent());
+ // some constants
+ if(strcmp("ResultContinue",Name) == 0)
+ return Py_BuildValue("i", pkgAcquire::Continue);
+ if(strcmp("ResultFailed",Name) == 0)
+ return Py_BuildValue("i", pkgAcquire::Failed);
+ if(strcmp("ResultCancelled",Name) == 0)
+ return Py_BuildValue("i", pkgAcquire::Cancelled);
+
+ return Py_FindMethod(PkgAcquireMethods,Self,Name);
+}
+
+
+
+
+PyTypeObject PkgAcquireType =
+{
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, // ob_size
+ "Acquire", // tp_name
+ sizeof(CppOwnedPyObject<PkgAcquireStruct>), // tp_basicsize
+ 0, // tp_itemsize
+ // Methods
+ CppOwnedDealloc<PkgAcquireStruct>, // tp_dealloc
+ 0, // tp_print
+ AcquireAttr, // 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 *GetAcquire(PyObject *Self,PyObject *Args)
+{
+ pkgAcquire *fetcher = new pkgAcquire();
+
+ CppOwnedPyObject<pkgAcquire> *FetcherObj =
+ CppOwnedPyObject_NEW<pkgAcquire>(0,&PkgAcquireType, *fetcher);
+
+ return FetcherObj;
+}
+
+
+
+
+ /*}}}*/
diff --git a/python/acquire.h b/python/acquire.h
new file mode 100644
index 00000000..1afcfff3
--- /dev/null
+++ b/python/acquire.h
@@ -0,0 +1,6 @@
+#include <apt-pkg/acquire-item.h>
+
+struct PkgAcquireStruct
+{
+ pkgAcquire fetcher;
+};
diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc
index ce337f0f..5731cae4 100644
--- a/python/apt_pkgmodule.cc
+++ b/python/apt_pkgmodule.cc
@@ -396,6 +396,12 @@ static PyMethodDef methods[] =
// Cdrom
{"GetCdrom",GetCdrom,METH_VARARGS,"GetCdrom() -> Cdrom"},
+ // Acquire
+ {"GetAcquire",GetAcquire,METH_VARARGS,"GetAcquire() -> Acquire"},
+
+ // PkgManager
+ {"GetPackageManager",GetPkgManager,METH_VARARGS,"GetPackageManager() -> PackageManager"},
+
{}
};
diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h
index eefa6ca7..93112f89 100644
--- a/python/apt_pkgmodule.h
+++ b/python/apt_pkgmodule.h
@@ -72,11 +72,22 @@ PyObject *GetPkgProblemResolver(PyObject *Self, PyObject *Args);
extern PyTypeObject PkgCdromType;
PyObject *GetCdrom(PyObject *Self,PyObject *Args);
+// acquire
+extern PyTypeObject PkgAcquireType;
+PyObject *GetAcquire(PyObject *Self,PyObject *Args);
+
+// packagemanager
+extern PyTypeObject PkgManagerType;
+PyObject *GetPkgManager(PyObject *Self,PyObject *Args);
+
// PkgRecords Stuff
extern PyTypeObject PkgRecordsType;
PyObject *GetPkgRecords(PyObject *Self,PyObject *Args);
PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args);
+
+// pkgSourceList
+extern PyTypeObject PkgSourceListType;
PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args);
#endif
diff --git a/python/makefile b/python/makefile
index 16bfcd88..7fb1d756 100644
--- a/python/makefile
+++ b/python/makefile
@@ -11,7 +11,7 @@ SLIBS = -lapt-pkg
LIB_MAKES = apt-pkg/makefile
APT_PKG_SRC = apt_pkgmodule.cc configuration.cc generic.cc tag.cc string.cc \
cache.cc pkgrecords.cc pkgsrcrecords.cc sourcelist.cc \
- depcache.cc progress.cc cdrom.cc
+ depcache.cc progress.cc cdrom.cc acquire.cc pkgmanager.cc
SOURCE := $(APT_PKG_SRC)
include $(PYTHON_H) progress.h
diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc
new file mode 100644
index 00000000..9504fd94
--- /dev/null
+++ b/python/pkgmanager.cc
@@ -0,0 +1,109 @@
+// Description /*{{{*/
+// $Id: acquire.cc,v 1.1 2003/06/03 03:03:23 mvo Exp $
+/* ######################################################################
+
+ PkgManager - Wrapper for the pkgPackageManager code
+
+ ##################################################################### */
+
+#include "generic.h"
+#include "apt_pkgmodule.h"
+#include "acquire.h"
+#include "sourcelist.h"
+#include "pkgrecords.h"
+
+#include <apt-pkg/packagemanager.h>
+#include <apt-pkg/pkgsystem.h>
+
+#include <iostream>
+
+
+struct PkgManagerStruct
+{
+ pkgPackageManager pm;
+};
+
+static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args)
+{
+ PkgManagerStruct &Struct = GetCpp<PkgManagerStruct>(Self);
+ PyObject *fetcher, *list, *recs;
+
+ if (PyArg_ParseTuple(Args, "O!O!O!",
+ &PkgAcquireType,&fetcher,
+ &PkgSourceListType, &list,
+ &PkgRecordsType, &recs) == 0)
+ return 0;
+
+ PkgAcquireStruct &s_fetcher = GetCpp<PkgAcquireStruct>(fetcher);
+ PkgSourceListStruct &s_list = GetCpp<PkgSourceListStruct>(list);
+ PkgRecordsStruct &s_records = GetCpp<PkgRecordsStruct>(recs);
+
+ bool res = Struct.pm.GetArchives(&s_fetcher.fetcher,
+ &s_list.List,
+ &s_records.Records);
+
+ return HandleErrors(Py_None);
+}
+
+
+static PyMethodDef PkgManagerMethods[] =
+{
+ {"GetArchives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archvies into the fetcher"},
+ {}
+};
+
+
+static PyObject *PkgManagerAttr(PyObject *Self,char *Name)
+{
+ PkgManagerStruct &Struct = GetCpp<PkgManagerStruct>(Self);
+
+ // some constants
+ if(strcmp("ResultCompleted",Name) == 0)
+ return Py_BuildValue("i", pkgPackageManager::Completed);
+ if(strcmp("ResultFailed",Name) == 0)
+ return Py_BuildValue("i", pkgPackageManager::Failed);
+ if(strcmp("ResultIncomplete",Name) == 0)
+ return Py_BuildValue("i", pkgPackageManager::Incomplete);
+
+ return Py_FindMethod(PkgManagerMethods,Self,Name);
+}
+
+
+PyTypeObject PkgManagerType =
+{
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, // ob_size
+ "PackageManager", // tp_name
+ sizeof(CppOwnedPyObject<PkgManagerStruct>), // tp_basicsize
+ 0, // tp_itemsize
+ // Methods
+ CppOwnedDealloc<PkgManagerStruct>, // tp_dealloc
+ 0, // tp_print
+ PkgManagerAttr, // 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 *GetPkgManager(PyObject *Self,PyObject *Args)
+{
+ PyObject *Owner;
+ if (PyArg_ParseTuple(Args,"O!",&PkgDepCacheType,&Owner) == 0)
+ return 0;
+
+ pkgPackageManager *pm = _system->CreatePM(GetCpp<pkgDepCache*>(Owner));
+
+ CppOwnedPyObject<pkgPackageManager> *PkgManagerObj =
+ CppOwnedPyObject_NEW<pkgPackageManager>(0,&PkgManagerType, *pm);
+
+ return PkgManagerObj;
+}
+
+
+
+
+ /*}}}*/
diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc
index 7f5aa0e2..a85b570a 100644
--- a/python/pkgrecords.cc
+++ b/python/pkgrecords.cc
@@ -10,20 +10,12 @@
// Include Files /*{{{*/
#include "generic.h"
#include "apt_pkgmodule.h"
+#include "pkgrecords.h"
-#include <apt-pkg/pkgrecords.h>
#include <Python.h>
/*}}}*/
-struct PkgRecordsStruct
-{
- pkgRecords Records;
- pkgRecords::Parser *Last;
-
- PkgRecordsStruct(pkgCache *Cache) : Records(*Cache), Last(0) {};
- PkgRecordsStruct() : Records(*(pkgCache *)0) {abort();}; // G++ Bug..
-};
// PkgRecords Class /*{{{*/
// ---------------------------------------------------------------------
diff --git a/python/pkgrecords.h b/python/pkgrecords.h
new file mode 100644
index 00000000..78787eab
--- /dev/null
+++ b/python/pkgrecords.h
@@ -0,0 +1,10 @@
+#include <apt-pkg/pkgrecords.h>
+
+struct PkgRecordsStruct
+{
+ pkgRecords Records;
+ pkgRecords::Parser *Last;
+
+ PkgRecordsStruct(pkgCache *Cache) : Records(*Cache), Last(0) {};
+ PkgRecordsStruct() : Records(*(pkgCache *)0) {abort();}; // G++ Bug..
+};
diff --git a/python/sourcelist.cc b/python/sourcelist.cc
index e2343e1c..06cf58a2 100644
--- a/python/sourcelist.cc
+++ b/python/sourcelist.cc
@@ -10,16 +10,11 @@
// Include Files /*{{{*/
#include "generic.h"
#include "apt_pkgmodule.h"
-
-#include <apt-pkg/sourcelist.h>
+#include "sourcelist.h"
#include <Python.h>
/*}}}*/
-struct PkgSourceListStruct
-{
- pkgSourceList List;
-};
// PkgsourceList Class /*{{{*/
// ---------------------------------------------------------------------
diff --git a/python/sourcelist.h b/python/sourcelist.h
new file mode 100644
index 00000000..98684c54
--- /dev/null
+++ b/python/sourcelist.h
@@ -0,0 +1,6 @@
+#include <apt-pkg/sourcelist.h>
+
+struct PkgSourceListStruct
+{
+ pkgSourceList List;
+};