From f398b1a5833fdf50f8c0c541958d5770ea767be8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2005 11:21:49 +0000 Subject: * fix in the pkgmanager.cc code (/me needs to be hit with a clue-stick) --- python/acquire.cc | 8 ++++++-- python/pkgmanager.cc | 56 ++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 15 deletions(-) (limited to 'python') diff --git a/python/acquire.cc b/python/acquire.cc index 91d75a6b..87f2717a 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -60,8 +60,12 @@ static PyObject *AcquireItemRepr(PyObject *Self) char S[300]; snprintf(S,sizeof(S),"", - (*I)->DestFile.c_str(),(*I)->ID); + "Status: %i Complete: %i Local: %i IsTrusted: %i " + "FileSize: %i DestFile:'%s' " + "DescURI: '%s' ID:%i ErrorText: '%s'>", + (*I)->Status, (*I)->Complete, (*I)->Local, (*I)->IsTrusted(), + (*I)->FileSize, (*I)->DestFile.c_str(), (*I)->DescURI().c_str(), + (*I)->ID,(*I)->ErrorText.c_str()); return PyString_FromString(S); } diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 9504fd94..b4c64d3e 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -14,18 +14,14 @@ #include #include +#include #include -struct PkgManagerStruct -{ - pkgPackageManager pm; -}; - static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) { - PkgManagerStruct &Struct = GetCpp(Self); + pkgPackageManager *pm = GetCpp(Self); PyObject *fetcher, *list, *recs; if (PyArg_ParseTuple(Args, "O!O!O!", @@ -38,24 +34,53 @@ static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) PkgSourceListStruct &s_list = GetCpp(list); PkgRecordsStruct &s_records = GetCpp(recs); - bool res = Struct.pm.GetArchives(&s_fetcher.fetcher, + bool res = pm->GetArchives(&s_fetcher.fetcher, &s_list.List, &s_records.Records); - return HandleErrors(Py_None); + return HandleErrors(Py_BuildValue("b",res)); +} + +static PyObject *PkgManagerDoInstall(PyObject *Self,PyObject *Args) +{ + //PkgManagerStruct &Struct = GetCpp(Self); + pkgPackageManager *pm = GetCpp(Self); + int status_fd = -1; + + if (PyArg_ParseTuple(Args, "|i", &status_fd) == 0) + return 0; + + pkgPackageManager::OrderResult res = pm->DoInstall(status_fd); + + return HandleErrors(Py_BuildValue("i",res)); } +static PyObject *PkgManagerFixMissing(PyObject *Self,PyObject *Args) +{ + //PkgManagerStruct &Struct = GetCpp(Self); + pkgPackageManager *pm = GetCpp(Self); + + if (PyArg_ParseTuple(Args, "") == 0) + return 0; + + bool res = pm->FixMissing(); + + return HandleErrors(Py_BuildValue("b",res)); +} static PyMethodDef PkgManagerMethods[] = { {"GetArchives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archvies into the fetcher"}, + {"DoInstall",PkgManagerDoInstall,METH_VARARGS,"Do the actual install"}, + {"FixMissing",PkgManagerFixMissing,METH_VARARGS,"Fix the install if a pkg couldn't be downloaded"}, {} }; static PyObject *PkgManagerAttr(PyObject *Self,char *Name) { - PkgManagerStruct &Struct = GetCpp(Self); + //PkgManagerStruct &Struct = GetCpp(Self); + pkgPackageManager *pm = GetCpp(Self); // some constants if(strcmp("ResultCompleted",Name) == 0) @@ -74,10 +99,10 @@ PyTypeObject PkgManagerType = PyObject_HEAD_INIT(&PyType_Type) 0, // ob_size "PackageManager", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize + sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppOwnedDealloc, // tp_dealloc 0, // tp_print PkgManagerAttr, // tp_getattr 0, // tp_setattr @@ -89,6 +114,9 @@ PyTypeObject PkgManagerType = 0, // tp_hash }; +#include +#include + PyObject *GetPkgManager(PyObject *Self,PyObject *Args) { PyObject *Owner; @@ -97,9 +125,11 @@ PyObject *GetPkgManager(PyObject *Self,PyObject *Args) pkgPackageManager *pm = _system->CreatePM(GetCpp(Owner)); - CppOwnedPyObject *PkgManagerObj = - CppOwnedPyObject_NEW(0,&PkgManagerType, *pm); + CppPyObject *PkgManagerObj = + CppPyObject_NEW(&PkgManagerType,pm); + // FIXME: mem-leak??? + Py_INCREF(PkgManagerObj); return PkgManagerObj; } -- cgit v1.2.3