diff options
| author | Julian Andres Klode <jak@debian.org> | 2010-02-27 13:27:54 +0100 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2010-02-27 13:27:54 +0100 |
| commit | 83521b397a31165de60ad50fe73e684290c52a43 (patch) | |
| tree | a5b8947695c6a0f69211dd1eb9377d16d936147c | |
| parent | 930f6a2899b0b410777397fb206a8eba8c99100c (diff) | |
| parent | e5237896629a9fc7ba123b6248eff19d6440cf19 (diff) | |
| download | python-apt-83521b397a31165de60ad50fe73e684290c52a43.tar.gz | |
Merge the mvo branch
[ Michael Vogt ]
* apt/cache.py:
- call install_progress.startUpdate()/finishUpdate() to keep
compatibility with older code
* apt/progress/base.py:
- restore "self.statusfd, self.writefd" type, provide additional
self.status_stream and self.write_stream file like objects
* python/progress.cc:
- try to call compatibility functions first, then new functions
| -rw-r--r-- | apt/cache.py | 9 | ||||
| -rw-r--r-- | apt/progress/base.py | 19 | ||||
| -rw-r--r-- | apt/progress/old.py | 1 | ||||
| -rw-r--r-- | debian/changelog | 11 | ||||
| -rw-r--r-- | python/progress.cc | 59 |
5 files changed, 57 insertions, 42 deletions
diff --git a/apt/cache.py b/apt/cache.py index 24d63361..b5733d98 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -328,15 +328,16 @@ class Cache(object): The second parameter *install_progress* refers to an InstallProgress() object of the module apt.progress. """ + # compat with older API try: - install_progress.start_update() - except AttributeError: install_progress.startUpdate() + except AttributeError: + install_progress.start_update() res = install_progress.run(pm) try: - install_progress.finish_update() - except AttributeError: install_progress.finishUpdate() + except AttributeError: + install_progress.finish_update() return res @deprecated_args diff --git a/apt/progress/base.py b/apt/progress/base.py index 6636cccc..8075f790 100644 --- a/apt/progress/base.py +++ b/apt/progress/base.py @@ -28,6 +28,7 @@ import re import select import apt_pkg +from apt.deprecation import function_deprecated_by __all__ = ['AcquireProgress', 'CdromProgress', 'InstallProgress', 'OpProgress'] @@ -139,9 +140,9 @@ class InstallProgress(object): percent, select_timeout, status = 0.0, 0.1, "" def __init__(self): - (read, write) = os.pipe() - self.writefd = os.fdopen(write, "w") - self.statusfd = os.fdopen(read, "r") + (self.statusfd, self.writefd) = os.pipe() + self.write_stream = os.fdopen(self.writefd, "w") + self.status_stream = os.fdopen(self.statusfd, "r") fcntl.fcntl(self.statusfd, fcntl.F_SETFL, os.O_NONBLOCK) def start_update(self): @@ -158,6 +159,9 @@ class InstallProgress(object): def status_change(self, pkg, percent, status): """(Abstract) Called when the APT status changed.""" + # compat with 0.7 + if apt_pkg._COMPAT_0_7 and hasattr(self, "statusChange"): + self.statusChange(pkg, percent, status) def dpkg_status_change(self, pkg, status): """(Abstract) Called when the dpkg status changed.""" @@ -190,10 +194,10 @@ class InstallProgress(object): # and the execution continues in the # parent code leading to very confusing bugs try: - os._exit(obj.do_install(self.writefd.fileno())) + os._exit(obj.do_install(self.write_stream.fileno())) except AttributeError: os._exit(os.spawnlp(os.P_WAIT, "dpkg", "dpkg", "--status-fd", - str(self.writefd.fileno()), "-i", obj)) + str(self.write_stream.fileno()), "-i", obj)) except Exception: os._exit(apt_pkg.PackageManager.RESULT_FAILED) @@ -208,7 +212,7 @@ class InstallProgress(object): def update_interface(self): """Update the interface.""" try: - line = self.statusfd.readline() + line = self.status_stream.readline() except IOError, err: # resource temporarly unavailable is ignored if err.errno != errno.EAGAIN and err.errno != errno.EWOULDBLOCK: @@ -222,7 +226,6 @@ class InstallProgress(object): (status, pkgname, percent, status_str) = line.split(":", 3) except ValueError: # silently ignore lines that can't be parsed - self.read = "" return elif line.startswith('status'): try: @@ -263,7 +266,7 @@ class InstallProgress(object): (pid, res) = (0, 0) while True: try: - select.select([self.statusfd], [], [], self.select_timeout) + select.select([self.status_stream], [], [], self.select_timeout) except select.error, (errno_, errstr): if errno_ != errno.EINTR: raise diff --git a/apt/progress/old.py b/apt/progress/old.py index c2d95b85..15ead890 100644 --- a/apt/progress/old.py +++ b/apt/progress/old.py @@ -191,6 +191,7 @@ class InstallProgress(DumbInstallProgress, base.InstallProgress): selectTimeout = AttributeDeprecatedBy('select_timeout') statusChange = function_deprecated_by(base.InstallProgress.status_change) + updateInterface = function_deprecated_by(base.InstallProgress.update_interface) waitChild = function_deprecated_by(base.InstallProgress.wait_child) diff --git a/debian/changelog b/debian/changelog index 4b93dddc..ddb94ecf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ python-apt (0.7.93.2) UNRELEASED; urgency=low + [ Julian Andres Klode ] * Fix some places where the old API was still used: - apt/utils.py: Completely ported, previous one was old-API from Ubuntu. - apt/cache.py: Use the new progress classes instead of the old ones. @@ -21,6 +22,16 @@ python-apt (0.7.93.2) UNRELEASED; urgency=low - aptsources/distinfo.py: Support relative filenames for MirrorsFile. * debian/rules: - Run tests during build time. + + [ Michael Vogt ] + * apt/cache.py: + - call install_progress.startUpdate()/finishUpdate() to keep + compatibility with older code + * apt/progress/base.py: + - restore "self.statusfd, self.writefd" type, provide additional + self.status_stream and self.write_stream file like objects + * python/progress.cc: + - try to call compatibility functions first, then new functions -- Julian Andres Klode <jak@debian.org> Sun, 07 Feb 2010 19:58:40 +0100 diff --git a/python/progress.cc b/python/progress.cc index bedad935..18081690 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -134,10 +134,10 @@ bool PyFetchProgress::MediaChange(string Media, string Drive) PyObject *arglist = Py_BuildValue("(ss)", Media.c_str(), Drive.c_str()); PyObject *result; - if(PyObject_HasAttrString(callbackInst, "media_change")) - RunSimpleCallback("media_change", arglist, &result); - else + if(PyObject_HasAttrString(callbackInst, "mediaChange")) RunSimpleCallback("mediaChange", arglist, &result); + else + RunSimpleCallback("media_change", arglist, &result); bool res = true; if(!PyArg_Parse(result, "b", &res)) { @@ -170,10 +170,10 @@ void PyFetchProgress::UpdateStatus(pkgAcquire::ItemDesc &Itm, int status) arglist = Py_BuildValue("(sssi)", Itm.URI.c_str(), Itm.Description.c_str(), Itm.ShortDesc.c_str(), status); - if(PyObject_HasAttrString(callbackInst, "update_status")) - RunSimpleCallback("update_status", arglist); - else + if(PyObject_HasAttrString(callbackInst, "updateStatus")) RunSimpleCallback("updateStatus", arglist); + else + RunSimpleCallback("update_status", arglist); } void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) @@ -415,24 +415,24 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) void PyInstallProgress::StartUpdate() { - if (!RunSimpleCallback("start_update")) - RunSimpleCallback("startUpdate"); + if (!RunSimpleCallback("startUpdate")) + RunSimpleCallback("start_update"); PyCbObj_BEGIN_ALLOW_THREADS } void PyInstallProgress::UpdateInterface() { PyCbObj_END_ALLOW_THREADS - if (!RunSimpleCallback("update_interface")) - RunSimpleCallback("updateInterface"); + if (!RunSimpleCallback("updateInterface")) + RunSimpleCallback("update_interface"); PyCbObj_BEGIN_ALLOW_THREADS } void PyInstallProgress::FinishUpdate() { PyCbObj_END_ALLOW_THREADS - if (!RunSimpleCallback("finish_update")) - RunSimpleCallback("finishUpdate"); + if (!RunSimpleCallback("finishUpdate")) + RunSimpleCallback("finish_update"); } pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) @@ -496,10 +496,10 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) if(PyObject_HasAttrString(callbackInst, "waitChild") || PyObject_HasAttrString(callbackInst, "wait_child")) { PyObject *method; - if (PyObject_HasAttrString(callbackInst, "wait_child")) - method = PyObject_GetAttrString(callbackInst, "wait_child"); - else + if (PyObject_HasAttrString(callbackInst, "waitChild")) method = PyObject_GetAttrString(callbackInst, "waitChild"); + else + method = PyObject_GetAttrString(callbackInst, "wait_child"); //std::cerr << "custom waitChild found" << std::endl; PyObject *arglist = Py_BuildValue("(i)",child_id); PyObject *result = PyObject_CallObject(method, arglist); @@ -553,10 +553,10 @@ bool PyCdromProgress::ChangeCdrom() { PyObject *arglist = Py_BuildValue("()"); PyObject *result; - if (PyObject_HasAttrString(callbackInst, "change_cdrom")) - RunSimpleCallback("change_cdrom", arglist, &result); - else + if (PyObject_HasAttrString(callbackInst, "changeCdrom")) RunSimpleCallback("changeCdrom", arglist, &result); + else + RunSimpleCallback("change_cdrom", arglist, &result); bool res = true; if(!PyArg_Parse(result, "b", &res)) @@ -573,25 +573,24 @@ bool PyCdromProgress::AskCdromName(string &Name) bool res; PyObject *result; + // Old style: (True, name) on success, (False, name) on failure. + if (PyObject_HasAttrString(callbackInst, "askAdromName")) { + RunSimpleCallback("askAdromName", arglist, &result); + if(!PyArg_Parse(result, "(bs)", &res, &new_name)) + std::cerr << "AskCdromName: result could not be parsed" << std::endl; + // set the new name + Name = string(new_name); + return res; + } // New style: String on success, None on failure. - if (PyObject_HasAttrString(callbackInst, "ask_cdrom_name")) { + else { RunSimpleCallback("ask_cdrom_name", arglist, &result); if(result == Py_None) return false; if(!PyArg_Parse(result, "s", &new_name)) - std::cerr << "AskCdromName: result could not be parsed" << std::endl; + std::cerr << "ask_cdrom_name: result could not be parsed" << std::endl; else Name = string(new_name); return true; - } - // Old style: (True, name) on success, (False, name) on failure. - else { - RunSimpleCallback("askCdromName", arglist, &result); - if(!PyArg_Parse(result, "(bs)", &res, &new_name)) - std::cerr << "AskCdromName: result could not be parsed" << std::endl; - // set the new name - Name = string(new_name); - - return res; } } |
