summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/examples/inst.py4
-rw-r--r--doc/examples/progress.py23
-rw-r--r--python/depcache.cc7
-rw-r--r--python/progress.cc58
-rw-r--r--python/progress.h10
5 files changed, 98 insertions, 4 deletions
diff --git a/doc/examples/inst.py b/doc/examples/inst.py
index 3854805b..3269900f 100644
--- a/doc/examples/inst.py
+++ b/doc/examples/inst.py
@@ -5,7 +5,7 @@ import apt_pkg
import sys
import copy
-from progress import OpProgress, FetchProgress
+from progress import OpProgress, FetchProgress, InstallProgress
# init
@@ -22,7 +22,7 @@ depcache.Init(progress)
# do something
fprogress = FetchProgress()
-iprogress = "lala"
+iprogress = InstallProgress()
iter = cache["base-config"]
print "\n%s"%iter
diff --git a/doc/examples/progress.py b/doc/examples/progress.py
index f6cf1495..0dec95d1 100644
--- a/doc/examples/progress.py
+++ b/doc/examples/progress.py
@@ -1,5 +1,6 @@
import apt_pkg
import sys
+import time
class OpProgress:
def __init__(self):
@@ -20,6 +21,13 @@ class OpProgress:
class FetchProgress:
def __init__(self):
pass
+
+ def Start(self):
+ pass
+
+ def Stop(self):
+ pass
+
def UpdateStatus(self, uri, descr, shortDescr, status):
print "UpdateStatus: '%s' '%s' '%s' '%i'" % (uri,descr,shortDescr, status)
def Pulse(self):
@@ -27,4 +35,17 @@ class FetchProgress:
def MediaChange(self, medium, drive):
print "Please insert medium %s in drive %s" % (medium, drive)
- sys.stdin.readline() \ No newline at end of file
+ sys.stdin.readline()
+
+
+class InstallProgress:
+ def __init__(self):
+ pass
+ def StartUpdate(self):
+ print "StartUpdate"
+ def FinishUpdate(self):
+ print "FinishUpdate"
+ def UpdateInterface(self):
+ # usefull to e.g. redraw a GUI
+ time.sleep(0.1)
+
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