diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/acquire.cc | 274 | ||||
| -rw-r--r-- | python/apt_instmodule.cc | 38 | ||||
| -rw-r--r-- | python/apt_pkgmodule.cc | 7 | ||||
| -rw-r--r-- | python/apt_pkgmodule.h | 16 | ||||
| -rw-r--r-- | python/cache.cc | 27 | ||||
| -rw-r--r-- | python/cdrom.cc | 6 | ||||
| -rw-r--r-- | python/depcache.cc | 79 | ||||
| -rw-r--r-- | python/indexfile.cc | 92 | ||||
| -rw-r--r-- | python/makefile | 3 | ||||
| -rw-r--r-- | python/pkgmanager.cc | 135 | ||||
| -rw-r--r-- | python/pkgrecords.cc | 18 | ||||
| -rw-r--r-- | python/pkgrecords.h | 10 | ||||
| -rw-r--r-- | python/pkgsrcrecords.cc | 31 | ||||
| -rw-r--r-- | python/progress.cc | 42 | ||||
| -rw-r--r-- | python/sourcelist.cc | 57 | ||||
| -rw-r--r-- | python/tar.cc | 4 |
16 files changed, 779 insertions, 60 deletions
diff --git a/python/acquire.cc b/python/acquire.cc new file mode 100644 index 00000000..65f8f2d7 --- /dev/null +++ b/python/acquire.cc @@ -0,0 +1,274 @@ +// 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 "progress.h" + +#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()); + // constants + else if (strcmp("StatIdle",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Item::StatIdle); + else if (strcmp("StatFetching",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Item::StatFetching); + else if (strcmp("StatDone",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Item::StatDone); + else if (strcmp("StatError",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Item::StatError); + else if (strcmp("StatAuthError",Name) == 0) + return Py_BuildValue("i", pkgAcquire::Item::StatAuthError); + + + 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: " + "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); +} + + +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) +{ + pkgAcquire *fetcher = GetCpp<pkgAcquire*>(Self); + + int pulseInterval = 500000; + if (PyArg_ParseTuple(Args, "|i", &pulseInterval) == 0) + return 0; + + pkgAcquire::RunResult run = fetcher->Run(pulseInterval); + + return HandleErrors(Py_BuildValue("i",run)); +} + +static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args) +{ + pkgAcquire *fetcher = GetCpp<pkgAcquire*>(Self); + + if (PyArg_ParseTuple(Args, "") == 0) + return 0; + + fetcher->Shutdown(); + + Py_INCREF(Py_None); + return HandleErrors(Py_None); +} + +static PyMethodDef PkgAcquireMethods[] = +{ + {"Run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, + {"Shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"}, + {} +}; + + +static PyObject *AcquireAttr(PyObject *Self,char *Name) +{ + pkgAcquire *fetcher = GetCpp<pkgAcquire*>(Self); + + if(strcmp("TotalNeeded",Name) == 0) + return Py_BuildValue("d", fetcher->TotalNeeded()); + if(strcmp("FetchNeeded",Name) == 0) + return Py_BuildValue("d", fetcher->FetchNeeded()); + if(strcmp("PartialPresent",Name) == 0) + return Py_BuildValue("d", fetcher->PartialPresent()); + if(strcmp("Items",Name) == 0) + { + PyObject *List = PyList_New(0); + for (pkgAcquire::ItemIterator I = fetcher->ItemsBegin(); + I != 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); + 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(CppPyObject<pkgAcquire*>), // tp_basicsize + 0, // tp_itemsize + // Methods + CppDealloc<pkgAcquire*>, // 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; + + PyObject *pyFetchProgressInst = NULL; + if (PyArg_ParseTuple(Args,"|O",&pyFetchProgressInst) == 0) + return 0; + + if (pyFetchProgressInst != NULL) { + // FIXME: memleak? + PyFetchProgress *progress = new PyFetchProgress(); + progress->setCallbackInst(pyFetchProgressInst); + fetcher = new pkgAcquire(progress); + } else { + fetcher = new pkgAcquire(); + } + + CppPyObject<pkgAcquire*> *FetcherObj = + CppPyObject_NEW<pkgAcquire*>(&PkgAcquireType, fetcher); + + return FetcherObj; +} + + + + + +// pkgAcquireFile + +static PyObject *AcquireFileAttr(PyObject *Self,char *Name) +{ + pkgAcqFile *acqFile = GetCpp<pkgAcqFile*>(Self); + + PyErr_SetString(PyExc_AttributeError,Name); + return 0; +} + + + + +PyTypeObject PkgAcquireFileType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "pkgAcquireFile", // tp_name + sizeof(CppPyObject<pkgAcqFile*>),// tp_basicsize + 0, // tp_itemsize + // Methods + CppDealloc<pkgAcqFile*>, // tp_dealloc + 0, // tp_print + AcquireFileAttr, // 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 *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) +{ + PyObject *pyfetcher; + char *uri, *md5, *descr, *shortDescr, *destDir, *destFile; + int size = 0; + uri = md5 = descr = shortDescr = destDir = destFile = ""; + + char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortDescr", + NULL}; + + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|siss", kwlist, + &PkgAcquireType, &pyfetcher, &uri, &md5, + &size, &descr, &shortDescr) == 0) + return 0; + + pkgAcquire *fetcher = GetCpp<pkgAcquire*>(pyfetcher); + pkgAcqFile *af = new pkgAcqFile(fetcher, // owner + uri, // uri + md5, // md5 + size, // size + descr, // descr + shortDescr); // short-desc + CppPyObject<pkgAcqFile*> *AcqFileObj = CppPyObject_NEW<pkgAcqFile*>(&PkgAcquireFileType); + AcqFileObj->Object = af; + + return AcqFileObj; +} + + + /*}}}*/ diff --git a/python/apt_instmodule.cc b/python/apt_instmodule.cc index 96bd029b..d672a40a 100644 --- a/python/apt_instmodule.cc +++ b/python/apt_instmodule.cc @@ -66,6 +66,43 @@ static PyObject *debExtractControl(PyObject *Self,PyObject *Args) } /*}}}*/ +// debExtractArchive - Exctract the archive /*{{{*/ +// --------------------------------------------------------------------- +static char *doc_debExtractArchive = +"debExtractArchve(File,rootdir) -> Bool\n" +"Extracts the Archive into the given root dir"; +static PyObject *debExtractArchive(PyObject *Self,PyObject *Args) +{ + char *Rootdir = NULL; + PyObject *File; + if (PyArg_ParseTuple(Args,"O!|s",&PyFile_Type,&File,&Rootdir) == 0) + return 0; + + // Subscope makes sure any clean up errors are properly handled. + bool res = false; + { + if(Rootdir != NULL) + { + chdir(Rootdir); + } + + // Open the file and associate the .deb + FileFd Fd(fileno(PyFile_AsFile(File)),false); + debDebFile Deb(Fd); + if (_error->PendingError() == true) + return HandleErrors(); + + // extracts relative to the current dir + pkgDirStream Extract; + res = Deb.ExtractArchive(Extract); + + if (res == false) + return HandleErrors(); + } + return HandleErrors(Py_BuildValue("b",res)); +} + /*}}}*/ + // initapt_inst - Core Module Initialization /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -73,6 +110,7 @@ static PyMethodDef methods[] = { // Stuff {"debExtractControl",debExtractControl,METH_VARARGS,doc_debExtractControl}, + {"debExtractArchive",debExtractArchive,METH_VARARGS,doc_debExtractArchive}, {"tarExtract",tarExtract,METH_VARARGS,doc_tarExtract}, {"debExtract",debExtract,METH_VARARGS,doc_debExtract}, diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index ce337f0f..e73628c3 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -396,6 +396,13 @@ static PyMethodDef methods[] = // Cdrom {"GetCdrom",GetCdrom,METH_VARARGS,"GetCdrom() -> Cdrom"}, + // Acquire + {"GetAcquire",GetAcquire,METH_VARARGS,"GetAcquire() -> Acquire"}, + {"GetPkgAcqFile",(PyCFunction)GetPkgAcqFile,METH_KEYWORDS|METH_VARARGS,"GetPkgAcquireFile() -> pkgAcquireFile"}, + + // PkgManager + {"GetPackageManager",GetPkgManager,METH_VARARGS,"GetPackageManager() -> PackageManager"}, + {} }; diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index eefa6ca7..fe7dfe88 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -72,11 +72,27 @@ 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); +PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject *kwds); + +// 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); +// pkgSourceList +extern PyTypeObject PackageIndexFileType; + + #endif diff --git a/python/cache.cc b/python/cache.cc index 5c1760d4..174423c2 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -231,6 +231,17 @@ static PyObject *CacheMapOp(PyObject *Self,PyObject *Arg) return CppOwnedPyObject_NEW<pkgCache::PkgIterator>(Self,&PackageType,Pkg); } +// we need a special dealloc here to make sure that the CacheFile +// is closed before deallocation the cache (otherwise we have a bad) +// memory leak +void PkgCacheFileDealloc(PyObject *Self) +{ + PyObject *CacheFilePy = GetOwner<pkgCache*>(Self); + pkgCacheFile *CacheF = GetCpp<pkgCacheFile*>(CacheFilePy); + CacheF->Close(); + CppOwnedDealloc<pkgCache *>(Self); +} + static PyMappingMethods CacheMap = {0,CacheMapOp,0}; PyTypeObject PkgCacheType = { @@ -240,7 +251,7 @@ PyTypeObject PkgCacheType = sizeof(CppOwnedPyObject<pkgCache *>), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc<pkgCache *>, // tp_dealloc + PkgCacheFileDealloc, // tp_dealloc 0, // tp_print CacheAttr, // tp_getattr 0, // tp_setattr @@ -452,7 +463,17 @@ static PyObject *MakeDepends(PyObject *Owner,pkgCache::VerIterator &Ver, // Switch/create a new dict entry if (LastDepType != Start->Type || LastDep != 0) { - PyObject *Dep = PyString_FromString(Start.DepType()); + // must be in sync with pkgCache::DepType in libapt + // it sucks to have it here duplicated, but we get it + // translated from libapt and that is certainly not what + // we want in a programing interface + const char *Types[] = + { + "", "Depends","PreDepends","Suggests", + "Recommends","Conflicts","Replaces", + "Obsoletes" + }; + PyObject *Dep = PyString_FromString(Types[Start->Type]); LastDepType = Start->Type; LastDep = PyDict_GetItem(Dict,Dep); if (LastDep == 0) @@ -637,8 +658,6 @@ static PyObject *PackageFileAttr(PyObject *Self,char *Name) return Py_BuildValue("i",(File->Flags & pkgCache::Flag::NotAutomatic) != 0); else if (strcmp("ID",Name) == 0) return Py_BuildValue("i",File->ID); - /* mtime is really a cookie these days and has no meaning outside the - list handlers */ PyErr_SetString(PyExc_AttributeError,Name); return 0; diff --git a/python/cdrom.cc b/python/cdrom.cc index 13889b31..aca1be26 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -30,10 +30,9 @@ static PyObject *PkgCdromAdd(PyObject *Self,PyObject *Args) PyCdromProgress progress; progress.setCallbackInst(pyCdromProgressInst); - Struct.cdrom.Add(&progress); + bool res = Struct.cdrom.Add(&progress); - Py_INCREF(Py_None); - return HandleErrors(Py_None); + return HandleErrors(Py_BuildValue("b", res)); } static PyObject *PkgCdromIdent(PyObject *Self,PyObject *Args) @@ -69,7 +68,6 @@ static PyObject *CdromAttr(PyObject *Self,char *Name) { PkgCdromStruct &Struct = GetCpp<PkgCdromStruct>(Self); - return Py_FindMethod(PkgCdromMethods,Self,Name); } diff --git a/python/depcache.cc b/python/depcache.cc index c78d0077..60bbc1a4 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -116,17 +116,25 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) bool Failed = false; for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++) { + + //std::cout << "looking at: " << (*I)->DestFile + // << " status: " << (*I)->Status << std::endl; + if ((*I)->Status == pkgAcquire::Item::StatDone && (*I)->Complete == true) continue; if ((*I)->Status == pkgAcquire::Item::StatIdle) { + //std::cout << "transient failure" << std::endl; + Transient = true; - // Failed = true; + //Failed = true; continue; } + //std::cout << "something is wrong!" << std::endl; + _error->Warning(_("Failed to fetch %s %s\n"),(*I)->DescURI().c_str(), (*I)->ErrorText.c_str()); Failed = true; @@ -135,6 +143,7 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) if (Transient == true && Failed == true) { _error->Error(_("--fix-missing and media swapping is not currently supported")); + Py_INCREF(Py_None); return HandleErrors(Py_None); } @@ -143,27 +152,33 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) { //std::cerr << "Unable to correct missing packages." << std::endl; _error->Error("Aborting install."); + Py_INCREF(Py_None); return HandleErrors(Py_None); } - _system->UnLock(); + // fail if something else went wrong + //FIXME: make this more flexible, e.g. with a failedDl handler + if(Failed) + return Py_BuildValue("b", false); + _system->UnLock(true); pkgPackageManager::OrderResult Res = iprogress.Run(PM); - //FIXME: return usefull values here + //std::cout << "iprogress.Run() returned: " << (int)Res << std::endl; + if (Res == pkgPackageManager::Failed || _error->PendingError() == true) { - result = Py_BuildValue("b", false); - return result; + return HandleErrors(Py_BuildValue("b", false)); } if (Res == pkgPackageManager::Completed) { - result = Py_BuildValue("b", true); - return result; + //std::cout << "iprogress.Run() returned Completed " << std::endl; + return Py_BuildValue("b", true); } + //std::cout << "looping again, install unfinished" << std::endl; + // Reload the fetcher object and loop again for media swapping Fetcher.Shutdown(); if (PM->GetArchives(&Fetcher,&List,&Recs) == false) { - result = Py_BuildValue("b", false); - return result; + return Py_BuildValue("b", false); } _system->Lock(); } @@ -218,15 +233,30 @@ static PyObject *PkgDepCacheUpgrade(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"|b",&distUpgrade) == 0) return 0; + bool res; if(distUpgrade) - pkgDistUpgrade(*depcache); + res = pkgDistUpgrade(*depcache); else - pkgAllUpgrade(*depcache); + res = pkgAllUpgrade(*depcache); Py_INCREF(Py_None); - return HandleErrors(Py_None); + return HandleErrors(Py_BuildValue("b",res)); +} + +static PyObject *PkgDepCacheMinimizeUpgrade(PyObject *Self,PyObject *Args) +{ + pkgDepCache *depcache = GetCpp<pkgDepCache *>(Self); + + if (PyArg_ParseTuple(Args,"") == 0) + return 0; + + bool res = pkgMinimizeUpgrade(*depcache); + + Py_INCREF(Py_None); + return HandleErrors(Py_BuildValue("b",res)); } + static PyObject *PkgDepCacheReadPinFile(PyObject *Self,PyObject *Args) { pkgDepCache *depcache = GetCpp<pkgDepCache *>(Self); @@ -249,14 +279,15 @@ static PyObject *PkgDepCacheReadPinFile(PyObject *Self,PyObject *Args) static PyObject *PkgDepCacheFixBroken(PyObject *Self,PyObject *Args) { pkgDepCache *depcache = GetCpp<pkgDepCache *>(Self); - + + bool res=true; if (PyArg_ParseTuple(Args,"") == 0) return 0; - pkgFixBroken(*depcache); + res &=pkgFixBroken(*depcache); + res &=pkgMinimizeUpgrade(*depcache); - Py_INCREF(Py_None); - return HandleErrors(Py_None); + return HandleErrors(Py_BuildValue("b",res)); } @@ -339,6 +370,20 @@ static PyObject *PkgDepCacheIsUpgradable(PyObject *Self,PyObject *Args) return HandleErrors(Py_BuildValue("b",state.Upgradable())); } +static PyObject *PkgDepCacheIsGarbage(PyObject *Self,PyObject *Args) +{ + pkgDepCache *depcache = GetCpp<pkgDepCache *>(Self); + + PyObject *PackageObj; + if (PyArg_ParseTuple(Args,"O!",&PackageType,&PackageObj) == 0) + return 0; + + pkgCache::PkgIterator &Pkg = GetCpp<pkgCache::PkgIterator>(PackageObj); + pkgDepCache::StateCache &state = (*depcache)[Pkg]; + + return HandleErrors(Py_BuildValue("b",state.Garbage)); +} + static PyObject *PkgDepCacheIsNowBroken(PyObject *Self,PyObject *Args) { pkgDepCache *depcache = GetCpp<pkgDepCache *>(Self); @@ -466,6 +511,7 @@ static PyMethodDef PkgDepCacheMethods[] = {"Upgrade",PkgDepCacheUpgrade,METH_VARARGS,"Perform Upgrade (optional boolean argument if dist-upgrade should be performed)"}, {"FixBroken",PkgDepCacheFixBroken,METH_VARARGS,"Fix broken packages"}, {"ReadPinFile",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, + {"MinimizeUpgrade",PkgDepCacheMinimizeUpgrade, METH_VARARGS,"Go over the entire set of packages and try to keep each package marked for upgrade. If a conflict is generated then the package is restored."}, // Manipulators {"MarkKeep",PkgDepCacheMarkKeep,METH_VARARGS,"Mark package for keep"}, {"MarkDelete",PkgDepCacheMarkDelete,METH_VARARGS,"Mark package for delete (optional boolean argument if it should be purged)"}, @@ -475,6 +521,7 @@ static PyMethodDef PkgDepCacheMethods[] = {"IsUpgradable",PkgDepCacheIsUpgradable,METH_VARARGS,"Is pkg upgradable"}, {"IsNowBroken",PkgDepCacheIsNowBroken,METH_VARARGS,"Is pkg is now broken"}, {"IsInstBroken",PkgDepCacheIsInstBroken,METH_VARARGS,"Is pkg broken on the current install"}, + {"IsGarbage",PkgDepCacheIsGarbage,METH_VARARGS,"Is pkg garbage (mark-n-sweep)"}, {"MarkedInstall",PkgDepCacheMarkedInstall,METH_VARARGS,"Is pkg marked for install"}, {"MarkedUpgrade",PkgDepCacheMarkedUpgrade,METH_VARARGS,"Is pkg marked for upgrade"}, {"MarkedDelete",PkgDepCacheMarkedDelete,METH_VARARGS,"Is pkg marked for delete"}, diff --git a/python/indexfile.cc b/python/indexfile.cc new file mode 100644 index 00000000..ef6ffc8a --- /dev/null +++ b/python/indexfile.cc @@ -0,0 +1,92 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +// $Id: indexfile.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $ +/* ###################################################################### + + pkgIndexFile - Wrapper for the pkgIndexFilefunctions + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include "generic.h" +#include "apt_pkgmodule.h" + +#include <apt-pkg/indexfile.h> + +#include <Python.h> + +static PyObject *PackageIndexFileArchiveURI(PyObject *Self,PyObject *Args) +{ + pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self); + char *path; + + if (PyArg_ParseTuple(Args, "s",&path) == 0) + return 0; + + return HandleErrors(Safe_FromString(File->ArchiveURI(path).c_str())); +} + +static PyMethodDef PackageIndexFileMethods[] = +{ + {"ArchiveURI",PackageIndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"}, + {} +}; + + +static PyObject *PackageIndexFileAttr(PyObject *Self,char *Name) +{ + pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self); + if (strcmp("Label",Name) == 0) + return Safe_FromString(File->GetType()->Label); + else if (strcmp("Describe",Name) == 0) + return Safe_FromString(File->Describe().c_str()); + else if (strcmp("Exists",Name) == 0) + return Py_BuildValue("i",(File->Exists())); + else if (strcmp("HasPackages",Name) == 0) + return Py_BuildValue("i",(File->HasPackages())); + else if (strcmp("Size",Name) == 0) + return Py_BuildValue("i",(File->Size())); + else if (strcmp("IsTrusted",Name) == 0) + return Py_BuildValue("i",(File->IsTrusted())); + + return Py_FindMethod(PackageIndexFileMethods,Self,Name); +} + +static PyObject *PackageIndexFileRepr(PyObject *Self) +{ + pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self); + + char S[300]; + snprintf(S,sizeof(S),"<pkIndexFile object: " + "Label:'%s' Describe='%s' Exists='%i' " + "HasPackages='%i' Size='%i' " + "IsTrusted='%i' ArchiveURI='%s'>", + File->GetType()->Label, File->Describe().c_str(), File->Exists(), + File->HasPackages(), File->Size(), + File->IsTrusted(), File->ArchiveURI("").c_str()); + return PyString_FromString(S); +} + +PyTypeObject PackageIndexFileType = +{ + PyObject_HEAD_INIT(&PyType_Type) + 0, // ob_size + "pkgIndexFile", // tp_name + sizeof(CppOwnedPyObject<pkgIndexFile*>), // tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc<pkgIndexFile*>, // tp_dealloc + 0, // tp_print + PackageIndexFileAttr, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + PackageIndexFileRepr, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash +}; + + + + diff --git a/python/makefile b/python/makefile index 16bfcd88..24ef3238 100644 --- a/python/makefile +++ b/python/makefile @@ -11,7 +11,8 @@ 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 \ + indexfile.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..bcd4c45b --- /dev/null +++ b/python/pkgmanager.cc @@ -0,0 +1,135 @@ +// 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 "pkgrecords.h" + +#include <apt-pkg/packagemanager.h> +#include <apt-pkg/pkgsystem.h> +#include <apt-pkg/sourcelist.h> +#include <apt-pkg/error.h> +#include <apt-pkg/acquire.h> +#include <iostream> + + +static PyObject *PkgManagerGetArchives(PyObject *Self,PyObject *Args) +{ + pkgPackageManager *pm = GetCpp<pkgPackageManager*>(Self); + PyObject *fetcher, *list, *recs; + + if (PyArg_ParseTuple(Args, "O!O!O!", + &PkgAcquireType,&fetcher, + &PkgSourceListType, &list, + &PkgRecordsType, &recs) == 0) + return 0; + + pkgAcquire *s_fetcher = GetCpp<pkgAcquire*>(fetcher); + pkgSourceList *s_list = GetCpp<pkgSourceList*>(list); + PkgRecordsStruct &s_records = GetCpp<PkgRecordsStruct>(recs); + + bool res = pm->GetArchives(s_fetcher, s_list, + &s_records.Records); + + return HandleErrors(Py_BuildValue("b",res)); +} + +static PyObject *PkgManagerDoInstall(PyObject *Self,PyObject *Args) +{ + //PkgManagerStruct &Struct = GetCpp<PkgManagerStruct>(Self); + pkgPackageManager *pm = GetCpp<pkgPackageManager*>(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<PkgManagerStruct>(Self); + pkgPackageManager *pm = GetCpp<pkgPackageManager*>(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<PkgManagerStruct>(Self); + pkgPackageManager *pm = GetCpp<pkgPackageManager*>(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(CppPyObject<pkgPackageManager*>), // tp_basicsize + 0, // tp_itemsize + // Methods + CppDealloc<pkgPackageManager*>, // 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 +}; + +#include <apt-pkg/init.h> +#include <apt-pkg/configuration.h> + +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)); + + CppPyObject<pkgPackageManager*> *PkgManagerObj = + CppPyObject_NEW<pkgPackageManager*>(&PkgManagerType,pm); + + return PkgManagerObj; +} + + + + + /*}}}*/ diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 7f5aa0e2..ec78f554 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 /*{{{*/ // --------------------------------------------------------------------- @@ -54,7 +46,7 @@ static PyObject *PkgRecordsLookup(PyObject *Self,PyObject *Args) // always return true (to make it consistent with the pkgsrcrecords object return Py_BuildValue("i", 1); } - + static PyMethodDef PkgRecordsMethods[] = { {"Lookup",PkgRecordsLookup,METH_VARARGS,"Changes to a new package"}, @@ -81,6 +73,12 @@ static PyObject *PkgRecordsAttr(PyObject *Self,char *Name) return CppPyString(Struct.Last->LongDesc()); else if (strcmp("Name",Name) == 0) return CppPyString(Struct.Last->Name()); + else if (strcmp("Record", Name) == 0) + { + const char *start, *stop; + Struct.Last->GetRec(start, stop); + return PyString_FromStringAndSize(start,stop-start); + } } return Py_FindMethod(PkgRecordsMethods,Self,Name); 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/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 252810c7..5e04f5fc 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -43,7 +43,6 @@ static PyObject *PkgSrcRecordsLookup(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"s",&Name) == 0) return 0; - Struct.Records->Restart(); Struct.Last = Struct.Records->Find(Name, false); if (Struct.Last == 0) { Struct.Records->Restart(); @@ -54,9 +53,25 @@ static PyObject *PkgSrcRecordsLookup(PyObject *Self,PyObject *Args) return Py_BuildValue("i", 1); } +static char *doc_PkgSrcRecordsRestart = "Start Lookup from the begining"; +static PyObject *PkgSrcRecordsRestart(PyObject *Self,PyObject *Args) +{ + PkgSrcRecordsStruct &Struct = GetCpp<PkgSrcRecordsStruct>(Self); + + char *Name = 0; + if (PyArg_ParseTuple(Args,"") == 0) + return 0; + + Struct.Records->Restart(); + + Py_INCREF(Py_None); + return HandleErrors(Py_None); +} + static PyMethodDef PkgSrcRecordsMethods[] = { {"Lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, + {"Restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, {} }; @@ -81,8 +96,10 @@ static PyObject *PkgSrcRecordsAttr(PyObject *Self,char *Name) *b != 0; ++b) PyList_Append(List, CppPyString(*b)); - return List; // todo + } else if (strcmp("Index",Name) == 0) { + const pkgIndexFile &tmp = Struct.Last->Index(); + return CppOwnedPyObject_NEW<pkgIndexFile*>(Self,&PackageIndexFileType, (pkgIndexFile*)&tmp); } else if (strcmp("Files",Name) == 0) { PyObject *List = PyList_New(0); @@ -126,10 +143,10 @@ PyTypeObject PkgSrcRecordsType = PyObject_HEAD_INIT(&PyType_Type) 0, // ob_size "pkgSrcRecords", // tp_name - sizeof(CppOwnedPyObject<PkgSrcRecordsStruct>), // tp_basicsize + sizeof(CppPyObject<PkgSrcRecordsStruct>), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc<PkgSrcRecordsStruct>, // tp_dealloc + CppDealloc<PkgSrcRecordsStruct>, // tp_dealloc 0, // tp_print PkgSrcRecordsAttr, // tp_getattr 0, // tp_setattr @@ -145,11 +162,17 @@ PyTypeObject PkgSrcRecordsType = PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args) { +#if 0 PyObject *Owner; if (PyArg_ParseTuple(Args,"O!",&PkgCacheType,&Owner) == 0) return 0; return HandleErrors(CppOwnedPyObject_NEW<PkgSrcRecordsStruct>(Owner, &PkgSrcRecordsType)); +#endif + if (PyArg_ParseTuple(Args,"") == 0) + return 0; + + return HandleErrors(CppPyObject_NEW<PkgSrcRecordsStruct>(&PkgSrcRecordsType)); } diff --git a/python/progress.cc b/python/progress.cc index 12f9c7a8..f00058c9 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -218,7 +218,7 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) // support custom fork methods if(PyObject_HasAttrString(callbackInst, "fork")) { PyObject *method = PyObject_GetAttrString(callbackInst, "fork"); - //std::cerr << "custom fork found" << std::endl; + std::cerr << "custom fork found" << std::endl; PyObject *arglist = Py_BuildValue("()"); PyObject *result = PyEval_CallObject(method, arglist); Py_DECREF(arglist); @@ -227,9 +227,11 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) PyErr_Print(); return pkgPackageManager::Failed; } - if(!PyArg_Parse(result, "i", &child_id) ) + if(!PyArg_Parse(result, "i", &child_id) ) { std::cerr << "custom fork() result could not be parsed?"<< std::endl; - //std::cerr << "got: " << child_id << std::endl; + return pkgPackageManager::Failed; + } + std::cerr << "got pid: " << child_id << std::endl; } else { //std::cerr << "using build-in fork()" << std::endl; child_id = fork(); @@ -251,15 +253,39 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) } else { res = pm->DoInstall(); } + //std::cout << "res: " << res << std::endl; _exit(res); } StartUpdate(); - while (waitpid(child_id, &ret, WNOHANG) == 0) - UpdateInterface(); - res = (pkgPackageManager::OrderResult) WEXITSTATUS(ret); + if(PyObject_HasAttrString(callbackInst, "waitChild")) { + PyObject *method = PyObject_GetAttrString(callbackInst, "waitChild"); + //std::cerr << "custom waitChild found" << std::endl; + PyObject *arglist = Py_BuildValue("(i)",child_id); + PyObject *result = PyEval_CallObject(method, arglist); + Py_DECREF(arglist); + if (result == NULL) { + std::cerr << "waitChild method invalid" << std::endl; + PyErr_Print(); + return pkgPackageManager::Failed; + } + int child_res; + if(!PyArg_Parse(result, "i", &res) ) { + std::cerr << "custom waitChild() result could not be parsed?"<< std::endl; + return pkgPackageManager::Failed; + } + //std::cerr << "got child_res: " << res << std::endl; + } else { + //std::cerr << "using build-in waitpid()" << std::endl; + + while (waitpid(child_id, &ret, WNOHANG) == 0) + UpdateInterface(); + + res = (pkgPackageManager::OrderResult) WEXITSTATUS(ret); + //std::cerr << "build-in waitpid() got: " << res << std::endl; + } FinishUpdate(); @@ -273,6 +299,10 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) void PyCdromProgress::Update(string text, int current) { PyObject *arglist = Py_BuildValue("(si)", text.c_str(), current); + + PyObject *o = Py_BuildValue("i", totalSteps); + PyObject_SetAttrString(callbackInst, "totalSteps", o); + RunSimpleCallback("update", arglist); } diff --git a/python/sourcelist.cc b/python/sourcelist.cc index e2343e1c..16e51368 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -3,7 +3,7 @@ // $Id: sourcelist.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $ /* ###################################################################### - Package Records - Wrapper for the package records functions + SourcesList - Wrapper for the SourcesList functions ##################################################################### */ /*}}}*/ @@ -16,10 +16,7 @@ #include <Python.h> /*}}}*/ -struct PkgSourceListStruct -{ - pkgSourceList List; -}; + // PkgsourceList Class /*{{{*/ // --------------------------------------------------------------------- @@ -27,23 +24,57 @@ struct PkgSourceListStruct static char *doc_PkgSourceListFindIndex = "xxx"; static PyObject *PkgSourceListFindIndex(PyObject *Self,PyObject *Args) { - PkgSourceListStruct &Struct = GetCpp<PkgSourceListStruct>(Self); - return Py_BuildValue("i", 1); + pkgSourceList *list = GetCpp<pkgSourceList*>(Self); + PyObject *pyPkgFileIter; + PyObject *pyPkgIndexFile; + + if (PyArg_ParseTuple(Args, "O!", &PackageFileType,&pyPkgFileIter) == 0) + return 0; + + pkgCache::PkgFileIterator &i = GetCpp<pkgCache::PkgFileIterator>(pyPkgFileIter); + pkgIndexFile *index; + if(list->FindIndex(i, index)) + { + pyPkgIndexFile = CppOwnedPyObject_NEW<pkgIndexFile*>(pyPkgFileIter,&PackageIndexFileType,index); + return pyPkgIndexFile; + } + + //&PackageIndexFileType,&pyPkgIndexFile) + + Py_INCREF(Py_None); + return Py_None; } static char *doc_PkgSourceListReadMainList = "xxx"; static PyObject *PkgSourceListReadMainList(PyObject *Self,PyObject *Args) { - PkgSourceListStruct &Struct = GetCpp<PkgSourceListStruct>(Self); - Struct.List.ReadMainList(); + pkgSourceList *list = GetCpp<pkgSourceList*>(Self); + bool res = list->ReadMainList(); - return Py_None; + return HandleErrors(Py_BuildValue("b",res)); +} + +static char *doc_PkgSourceListGetIndexes = "Load the indexes into the fetcher"; +static PyObject *PkgSourceListGetIndexes(PyObject *Self,PyObject *Args) +{ + pkgSourceList *list = GetCpp<pkgSourceList*>(Self); + + PyObject *pyFetcher; + + if (PyArg_ParseTuple(Args, "O!",&PkgAcquireType,&pyFetcher) == 0) + return 0; + + pkgAcquire *fetcher = GetCpp<pkgAcquire*>(pyFetcher); + bool res = list->GetIndexes(fetcher); + + return HandleErrors(Py_BuildValue("b",res)); } static PyMethodDef PkgSourceListMethods[] = { {"FindIndex",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, {"ReadMainList",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, + {"GetIndexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListReadMainList}, {} }; @@ -56,10 +87,10 @@ PyTypeObject PkgSourceListType = PyObject_HEAD_INIT(&PyType_Type) 0, // ob_size "pkgSourceList", // tp_name - sizeof(CppPyObject<PkgSourceListStruct>), // tp_basicsize + sizeof(CppPyObject<pkgSourceList*>), // tp_basicsize 0, // tp_itemsize // Methods - CppDealloc<PkgSourceListStruct>, // tp_dealloc + CppDealloc<pkgSourceList*>, // tp_dealloc 0, // tp_print PkgSourceListAttr, // tp_getattr 0, // tp_setattr @@ -73,6 +104,6 @@ PyTypeObject PkgSourceListType = PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args) { - return CppPyObject_NEW<PkgSourceListStruct>(&PkgSourceListType); + return CppPyObject_NEW<pkgSourceList*>(&PkgSourceListType,new pkgSourceList()); } diff --git a/python/tar.cc b/python/tar.cc index 20fb1f5f..22c0327e 100644 --- a/python/tar.cc +++ b/python/tar.cc @@ -88,7 +88,7 @@ bool ProcessTar::DoItem(Item &Itm,int &Fd) // --------------------------------------------------------------------- /* */ char *doc_tarExtract = -"tarExtract(File,Func,Comp) -> None" +"tarExtract(File,Func,Comp) -> None\n" "The tar file referenced by the file object File, Func called for each\n" "Tar member. Comp must be the string \"gzip\" (gzip is automatically invoked) \n"; PyObject *tarExtract(PyObject *Self,PyObject *Args) @@ -128,7 +128,7 @@ PyObject *tarExtract(PyObject *Self,PyObject *Args) // --------------------------------------------------------------------- /* */ char *doc_debExtract = -"debExtract(File,Func,Chunk) -> None" +"debExtract(File,Func,Chunk) -> None\n" "The deb referenced by the file object File is examined. The AR member\n" "given by Chunk is treated as a tar.gz and fed through Func like\n" "tarExtract\n"; |
