diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2005-11-18 01:01:37 +0000 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2005-11-18 01:01:37 +0000 |
| commit | c187e828e1661d09a8437214b2f90dcc25c05c99 (patch) | |
| tree | a08f97e80e66887baafa5bd41384ab78ff92b082 /python/acquire.cc | |
| parent | 4da233eef44c921152daf224a043ab8e2181ef9f (diff) | |
| download | python-apt-c187e828e1661d09a8437214b2f90dcc25c05c99.tar.gz | |
* basic pkgAcquire + pkgPackageManager support added
Diffstat (limited to 'python/acquire.cc')
| -rw-r--r-- | python/acquire.cc | 106 |
1 files changed, 106 insertions, 0 deletions
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; +} + + + + + /*}}}*/ |
