summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2005-03-14 15:39:53 +0000
committerMichael Vogt <michael.vogt@ubuntu.com>2005-03-14 15:39:53 +0000
commite85acde9ac66221e7dae0ead2bb9d79140a1826b (patch)
treee0d53b23afc9b9c0d877eb62c94c77a2904c1b9d /python
parentd06566c40340c80db43e47b171ceda579291ef66 (diff)
downloadpython-apt-e85acde9ac66221e7dae0ead2bb9d79140a1826b.tar.gz
* basic fetch interface, mostly stubs right now
Diffstat (limited to 'python')
-rw-r--r--python/cache.cc61
-rw-r--r--python/progress.cc78
-rw-r--r--python/progress.h27
3 files changed, 162 insertions, 4 deletions
diff --git a/python/cache.cc b/python/cache.cc
index 7ba53fd9..aff5854a 100644
--- a/python/cache.cc
+++ b/python/cache.cc
@@ -14,6 +14,9 @@
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/cachefile.h>
#include <apt-pkg/sptr.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/error.h>
#include <Python.h>
#include "progress.h"
@@ -66,6 +69,57 @@ static PyObject *CreateProvides(PyObject *Owner,pkgCache::PrvIterator I)
// Cache Class /*{{{*/
// ---------------------------------------------------------------------
+static PyObject *PkgCacheUpdate(PyObject *Self,PyObject *Args)
+{
+ pkgCacheFile *Cache = GetCpp<pkgCacheFile *>(Self);
+
+ PyObject *pyOpProgressInst = 0;
+ PyObject *pyFetchProgressInst = 0;
+ if (PyArg_ParseTuple(Args, "O|O", &pyFetchProgressInst,&pyOpProgressInst) == 0)
+ return 0;
+
+ FileFd Lock;
+ if (_config->FindB("Debug::NoLocking", false) == false) {
+ Lock.Fd(GetLock(_config->FindDir("Dir::State::Lists") + "lock"));
+ if (_error->PendingError() == true)
+ return HandleErrors();
+ }
+
+ pkgSourceList List;
+ if(!List.ReadMainList())
+ return HandleErrors(Py_None);
+
+ PyFetchProgress progress;
+ progress.setCallbackInst(pyFetchProgressInst);
+
+ pkgAcquire Fetcher(&progress);
+ if (!List.GetIndexes(&Fetcher))
+ return HandleErrors();
+ if (Fetcher.Run() == pkgAcquire::Failed)
+ return HandleErrors(Py_None);
+
+
+
+ if(pyOpProgressInst != 0) {
+ PyOpProgress progress;
+ progress.setCallbackInst(pyOpProgressInst);
+ if (Cache->Open(progress,false) == false)
+ return HandleErrors();
+ } else {
+ OpTextProgress Prog;
+ if (Cache->Open(Prog,false) == false)
+ return HandleErrors(Py_None);
+ }
+
+ return HandleErrors(Py_None);
+}
+
+
+static PyMethodDef PkgCacheMethods[] =
+{
+ {"Update",PkgCacheUpdate,METH_VARARGS,"Update the cache"},
+};
+
static PyObject *CacheAttr(PyObject *Self,char *Name)
{
pkgCache *Cache = GetCpp<pkgCache *>(Self);
@@ -96,9 +150,8 @@ static PyObject *CacheAttr(PyObject *Self,char *Name)
}
return List;
}
-
- PyErr_SetString(PyExc_AttributeError,Name);
- return 0;
+
+ return Py_FindMethod(PkgCacheMethods,Self,Name);
}
// Map access, operator []
@@ -766,6 +819,6 @@ PyObject *TmpGetCache(PyObject *Self,PyObject *Args)
CppOwnedPyObject_NEW<pkgCache *>(CacheFileObj,&PkgCacheType,
(pkgCache *)(*Cache));
- Py_DECREF(CacheFileObj);
+ //Py_DECREF(CacheFileObj);
return CacheObj;
}
diff --git a/python/progress.cc b/python/progress.cc
index d414ca15..75c531fe 100644
--- a/python/progress.cc
+++ b/python/progress.cc
@@ -6,9 +6,12 @@
##################################################################### */
+#include <iostream>
#include "progress.h"
+// OpProgress interface
+// FIXME: add "string Op, string SubOp" as attribute to the callbackInst
void PyOpProgress::Update()
{
if(callbackInst == 0)
@@ -33,6 +36,7 @@ void PyOpProgress::Update()
return;
};
+
void PyOpProgress::Done()
{
if(callbackInst == 0)
@@ -53,3 +57,77 @@ void PyOpProgress::Done()
Py_XDECREF(method);
Py_DECREF(arglist);
}
+
+
+
+// fetcher interface
+// PyFetchProgress::
+
+// apt interface
+bool PyFetchProgress::MediaChange(string Media, string Drive)
+{
+ std::cout << "MediaChange" << std::endl;
+}
+
+void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm)
+{
+ std::cout << "IMSHit" << std::endl;
+}
+
+void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm)
+{
+ std::cout << "Fetch" << std::endl;
+}
+
+void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm)
+{
+ std::cout << "Done" << std::endl;
+}
+
+void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm)
+{
+ std::cout << "Fail" << std::endl;
+}
+
+void PyFetchProgress::Start()
+{
+ std::cout << "Start" << std::endl;
+ pkgAcquireStatus::Start();
+
+}
+
+void PyFetchProgress::Stop()
+{
+ std::cout << "Stop" << std::endl;
+ pkgAcquireStatus::Stop();
+}
+
+// FIXME: it should just set the attribute for
+// CurrentCPS, Current...
+bool PyFetchProgress::Pulse(pkgAcquire * Owner)
+{
+ pkgAcquireStatus::Pulse(Owner);
+
+ //std::cout << "Pulse" << std::endl;
+ if(callbackInst == 0)
+ return false;
+
+ // Build up the argument list...
+ PyObject *arglist = Py_BuildValue("(ffi)", CurrentCPS, CurrentBytes, CurrentItems);
+
+ // ...for calling the Python compare function.
+ PyObject *method = PyObject_GetAttrString(callbackInst, "Pulse");
+ if(method == NULL) {
+ // FIXME: make this silent
+ Py_DECREF(arglist);
+ return false;
+ }
+ PyObject *result = PyEval_CallObject(method,arglist);
+
+ Py_XDECREF(result);
+ Py_XDECREF(method);
+ Py_DECREF(arglist);
+
+ // this can be canceld by returning false
+ return true;
+}
diff --git a/python/progress.h b/python/progress.h
index b18778b1..6ea0b16b 100644
--- a/python/progress.h
+++ b/python/progress.h
@@ -10,6 +10,7 @@
#define PROGRESS_H
#include <apt-pkg/progress.h>
+#include <apt-pkg/acquire.h>
#include <Python.h>
struct PyOpProgress : public OpProgress
@@ -26,4 +27,30 @@ struct PyOpProgress : public OpProgress
PyOpProgress() : OpProgress(), callbackInst(0) {};
};
+
+struct PyFetchProgress : public pkgAcquireStatus
+{
+ PyObject *callbackInst;
+
+ void setCallbackInst(PyObject *o) {
+ callbackInst = o;
+ }
+
+
+ void updateStatus(pkgAcquire::ItemDesc & Itm, int status);
+
+ // apt interface
+ virtual bool MediaChange(string Media, string Drive);
+ virtual void IMSHit(pkgAcquire::ItemDesc &Itm);
+ virtual void Fetch(pkgAcquire::ItemDesc &Itm);
+ virtual void Done(pkgAcquire::ItemDesc &Itm);
+ virtual void Fail(pkgAcquire::ItemDesc &Itm);
+ virtual void Start();
+ virtual void Stop();
+
+ bool Pulse(pkgAcquire * Owner);
+};
+
+
+
#endif