summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2005-04-08 11:55:14 +0000
committerMichael Vogt <michael.vogt@ubuntu.com>2005-04-08 11:55:14 +0000
commit08ea34d6a28b4b17d0146535e85d61ab7bda341d (patch)
tree468c9348b1ee62208fdc60be8ad23a769e02e2b7 /python
parent8f914ef267ab1bbcbda1c6694edd2e4c9b6401ec (diff)
downloadpython-apt-08ea34d6a28b4b17d0146535e85d61ab7bda341d.tar.gz
* simple InstallProgress interface added
Diffstat (limited to 'python')
-rw-r--r--python/depcache.cc7
-rw-r--r--python/progress.cc58
-rw-r--r--python/progress.h10
3 files changed, 74 insertions, 1 deletions
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 <iostream>
+#include <sys/types.h>
+#include <sys/wait.h>
#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 <apt-pkg/progress.h>
#include <apt-pkg/acquire.h>
+#include <apt-pkg/packagemanager.h>
#include <Python.h>
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