From 08ea34d6a28b4b17d0146535e85d61ab7bda341d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 8 Apr 2005 11:55:14 +0000 Subject: * simple InstallProgress interface added --- python/depcache.cc | 7 ++++++- python/progress.cc | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ python/progress.h | 10 ++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/depcache.cc b/python/depcache.cc index 2a57a41a..89974358 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -109,6 +109,9 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) std::cout << "PM created" << std::endl; + PyInstallProgress iprogress; + iprogress.setCallbackInst(pyInstallProgressInst); + // Run it while (1) { @@ -152,7 +155,9 @@ static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) #endif _system->UnLock(); - pkgPackageManager::OrderResult Res = PM->DoInstall(); + + pkgPackageManager::OrderResult Res = iprogress.Run(PM); + //FIXME: return usefull values here if (Res == pkgPackageManager::Failed || _error->PendingError() == true) return Py_None/*false;*/; if (Res == pkgPackageManager::Completed) diff --git a/python/progress.cc b/python/progress.cc index 673d7c0d..310d9569 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -7,6 +7,8 @@ ##################################################################### */ #include +#include +#include #include "progress.h" // generic @@ -144,3 +146,59 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) // this can be canceld by returning false return true; } + + + +// install progress + +void PyInstallProgress::StartUpdate() +{ + RunSimpleCallback("StartUpdate"); +} + +void PyInstallProgress::UpdateInterface() +{ + RunSimpleCallback("UpdateInterface"); +} + +void PyInstallProgress::FinishUpdate() +{ + RunSimpleCallback("FinishUpdate"); +} + +pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) +{ + void *dummy; + pkgPackageManager::OrderResult res; + int ret; + pid_t _child_id; + +#if 0 // FIXME: this needs to be merged into apt to support medium swaping + res = pm->DoInstallPreFork(); + if (res == pkgPackageManager::Failed) + return res; +#endif + + _child_id = fork(); + +#if 0 // FIXME: this needs to be merged into apt to support medium swaping + if (_child_id == 0) { + res = pm->DoInstallPostFork(); + _exit(res); + } +#endif + if (_child_id == 0) { + res = pm->DoInstall(); + _exit(res); + } + + StartUpdate(); + while (waitpid(_child_id, &ret, WNOHANG) == 0) + UpdateInterface(); + + res = (pkgPackageManager::OrderResult) WEXITSTATUS(ret); + + FinishUpdate(); + + return res; +} diff --git a/python/progress.h b/python/progress.h index a39ae41a..2514623a 100644 --- a/python/progress.h +++ b/python/progress.h @@ -11,6 +11,7 @@ #include #include +#include #include class PyCallbackObj { @@ -58,6 +59,15 @@ struct PyFetchProgress : public pkgAcquireStatus, public PyCallbackObj }; +struct PyInstallProgress : public PyCallbackObj +{ + void StartUpdate(); + void UpdateInterface(); + void FinishUpdate(); + + pkgPackageManager::OrderResult Run(pkgPackageManager *pm); + PyInstallProgress() : PyCallbackObj() {}; +}; #endif -- cgit v1.2.3