summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/examples/acquire.py19
-rw-r--r--python/acquire.cc75
2 files changed, 91 insertions, 3 deletions
diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py
index 98b70ab0..f920e5e9 100644
--- a/doc/examples/acquire.py
+++ b/doc/examples/acquire.py
@@ -11,8 +11,11 @@ recs = apt_pkg.GetPkgRecords(cache)
list = apt_pkg.GetPkgSourceList()
list.ReadMainList()
-os.mkdir("/tmp/pyapt-test")
-os.mkdir("/tmp/pyapt-test/partial")
+try:
+ os.mkdir("/tmp/pyapt-test")
+ os.mkdir("/tmp/pyapt-test/partial")
+except OSError:
+ pass
apt_pkg.Config.Set("Dir::Cache::archives","/tmp/pyapt-test")
pkg = cache["3ddesktop"]
@@ -28,5 +31,15 @@ print fetcher
pm.GetArchives(fetcher,list,recs)
-fetcher.Run()
+for item in fetcher.Items:
+ print "%s -> %s:\n Status: %s Complete: %s IsTrusted: %s" % (item.DescURI,
+ item.DestFile,
+ item.Status,
+ item.Complete,
+ item.IsTrusted)
+ print
+
+
+res = fetcher.Run()
+print "fetcher.Run() returned: %s" % res
diff --git a/python/acquire.cc b/python/acquire.cc
index ff01b659..a65b9592 100644
--- a/python/acquire.cc
+++ b/python/acquire.cc
@@ -13,6 +13,67 @@
#include <apt-pkg/acquire-item.h>
+// pkgAcquire::Item
+static PyObject *AcquireItemAttr(PyObject *Self,char *Name)
+{
+ pkgAcquire::ItemIterator &I = GetCpp<pkgAcquire::ItemIterator>(Self);
+
+ if (strcmp("ID",Name) == 0)
+ return Py_BuildValue("i",(*I)->ID);
+ else if (strcmp("Status",Name) == 0)
+ return Py_BuildValue("i",(*I)->Status);
+ else if (strcmp("Complete",Name) == 0)
+ return Py_BuildValue("i",(*I)->Complete);
+ else if (strcmp("Local",Name) == 0)
+ return Py_BuildValue("i",(*I)->Local);
+ else if (strcmp("IsTrusted",Name) == 0)
+ return Py_BuildValue("i",(*I)->IsTrusted());
+ else if (strcmp("FileSize",Name) == 0)
+ return Py_BuildValue("i",(*I)->FileSize);
+ else if (strcmp("ErrorText",Name) == 0)
+ return Safe_FromString((*I)->ErrorText.c_str());
+ else if (strcmp("DestFile",Name) == 0)
+ return Safe_FromString((*I)->DestFile.c_str());
+ else if (strcmp("DescURI",Name) == 0)
+ return Safe_FromString((*I)->DescURI().c_str());
+
+ PyErr_SetString(PyExc_AttributeError,Name);
+ return 0;
+}
+
+
+static PyObject *AcquireItemRepr(PyObject *Self)
+{
+ pkgAcquire::ItemIterator &I = GetCpp<pkgAcquire::ItemIterator>(Self);
+
+ char S[300];
+ snprintf(S,sizeof(S),"<pkgAcquire::ItemIterator object: "
+ "DestFile:'%s' ID:%i>",
+ (*I)->DestFile.c_str(),(*I)->ID);
+ return PyString_FromString(S);
+}
+
+
+PyTypeObject AcquireItemType =
+{
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, // ob_size
+ "pkgAcquire::ItemIterator", // tp_name
+ sizeof(CppOwnedPyObject<pkgAcquire::ItemIterator>), // tp_basicsize
+ 0, // tp_itemsize
+ // Methods
+ CppOwnedDealloc<pkgAcquire::ItemIterator>, // tp_dealloc
+ 0, // tp_print
+ AcquireItemAttr, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ AcquireItemRepr, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+};
+
static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args)
{
@@ -57,6 +118,20 @@ static PyObject *AcquireAttr(PyObject *Self,char *Name)
return Py_BuildValue("l", Struct.fetcher.FetchNeeded());
if(strcmp("PartialPresent",Name) == 0)
return Py_BuildValue("l", Struct.fetcher.PartialPresent());
+ if(strcmp("Items",Name) == 0)
+ {
+ PyObject *List = PyList_New(0);
+ for (pkgAcquire::ItemIterator I = Struct.fetcher.ItemsBegin();
+ I != Struct.fetcher.ItemsEnd(); I++)
+ {
+ PyObject *Obj;
+ Obj = CppOwnedPyObject_NEW<pkgAcquire::ItemIterator>(Self,&AcquireItemType,I);
+ PyList_Append(List,Obj);
+ Py_DECREF(Obj);
+
+ }
+ return List;
+ }
// some constants
if(strcmp("ResultContinue",Name) == 0)
return Py_BuildValue("i", pkgAcquire::Continue);