From 8413810c46f802490280b0be1beebaaadf1aa9f2 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 14 Apr 2009 00:47:23 +0200 Subject: * Remove any trailing whitespace --- python/progress.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index c5a1c138..bec40ce9 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -185,7 +185,7 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) bool res = true; if(!PyArg_Parse(result, "b", &res)) { - // most of the time the user who subclasses the pulse() + // most of the time the user who subclasses the pulse() // method forgot to add a return {True,False} so we just // assume he wants a True return true; -- cgit v1.2.3 From 994a13b252f97f6ae77872b5d5118ac1366b2a24 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 5 Jun 2009 19:13:20 +0200 Subject: python/progress.cc, apt/progress/*.py: Use PEP 8 naming conventions for progress This changes the progress classes to use PEP 8 names. Due to the concept of the deprecation system, this causes methods of subclasses not to be called at all. If a class implements a command with underscores, it is called. If the class also implements the version in mixedCase, this is ignored. This means that all subclasses will not work correctly, because only the method from the parent class is called. --- apt/deprecation.py | 2 +- apt/progress/__init__.py | 133 +++++++++++++++++++++++++++++++---------------- apt/progress/gtk2.py | 52 +++++++++++------- python/progress.cc | 81 +++++++++++++++++++++++------ 4 files changed, 184 insertions(+), 84 deletions(-) (limited to 'python/progress.cc') diff --git a/apt/deprecation.py b/apt/deprecation.py index 6827a8b9..0f39ad63 100644 --- a/apt/deprecation.py +++ b/apt/deprecation.py @@ -67,7 +67,7 @@ def function_deprecated_by(func, convert_names=True): This function also converts all keyword argument names from mixedCase to lowercase_with_underscores, but only if 'convert_names' is True (default). """ - warning = 'Deprecated, please use \'%s\' instead' % func.__name__ + warning = 'Deprecated, please use \'%s()\' instead' % func.__name__ def deprecated_function(*args, **kwds): """Wrapper around a deprecated function.""" diff --git a/apt/progress/__init__.py b/apt/progress/__init__.py index d2a9d497..6e4c6eec 100644 --- a/apt/progress/__init__.py +++ b/apt/progress/__init__.py @@ -33,6 +33,7 @@ import select import sys import apt_pkg +from apt.deprecation import AttributeDeprecatedBy, function_deprecated_by __all__ = ('CdromProgress', 'DpkgInstallProgress', 'DumbInstallProgress', @@ -48,7 +49,7 @@ class OpProgress(object): def __init__(self): self.op = None - self.subOp = None + self.sub_op = None def update(self, percent): """Called periodically to update the user interface.""" @@ -56,6 +57,9 @@ class OpProgress(object): def done(self): """Called once an operation has been completed.""" + if apt_pkg._COMPAT_0_7: + subOp = AttributeDeprecatedBy('sub_op') + class OpTextProgress(OpProgress): """A simple text based cache open reporting class.""" @@ -65,7 +69,7 @@ class OpTextProgress(OpProgress): def update(self, percent): """Called periodically to update the user interface.""" - sys.stdout.write("\r%s: %.2i " % (self.subOp, percent)) + sys.stdout.write("\r%s: %.2i " % (self.sub_op, percent)) sys.stdout.flush() def done(self): @@ -80,26 +84,26 @@ class FetchProgress(object): """ # download status constants - dlDone = 0 - dlQueued = 1 - dlFailed = 2 - dlHit = 3 - dlIgnored = 4 - dlStatusStr = {dlDone: "Done", - dlQueued: "Queued", - dlFailed: "Failed", - dlHit: "Hit", - dlIgnored: "Ignored"} + dl_done = 0 + dl_queued = 1 + dl_failed = 2 + dl_hit = 3 + dl_ignored = 4 + dl_status_str = {dl_done: "Done", + dl_queued: "Queued", + dl_failed: "Failed", + dl_hit: "Hit", + dl_ignored: "Ignored"} def __init__(self): self.eta = 0.0 self.percent = 0.0 # Make checking easier - self.currentBytes = 0 - self.currentItems = 0 - self.totalBytes = 0 - self.totalItems = 0 - self.currentCPS = 0 + self.current_bytes = 0 + self.current_items = 0 + self.total_bytes = 0 + self.total_items = 0 + self.current_cps = 0 def start(self): """Called when the fetching starts.""" @@ -107,7 +111,7 @@ class FetchProgress(object): def stop(self): """Called when all files have been fetched.""" - def updateStatus(self, uri, descr, shortDescr, status): + def update_status(self, uri, descr, short_descr, status): """Called when the status of an item changes. This happens eg. when the downloads fails or is completed. @@ -118,16 +122,31 @@ class FetchProgress(object): Return True to continue or False to cancel. """ - self.percent = (((self.currentBytes + self.currentItems) * 100.0) / - float(self.totalBytes + self.totalItems)) - if self.currentCPS > 0: - self.eta = ((self.totalBytes - self.currentBytes) / - float(self.currentCPS)) + self.percent = (((self.current_bytes + self.current_items) * 100.0) / + float(self.total_bytes + self.total_items)) + if self.current_cps > 0: + self.eta = ((self.total_bytes - self.current_bytes) / + float(self.current_cps)) return True - def mediaChange(self, medium, drive): + def media_change(self, medium, drive): """react to media change events.""" + if apt_pkg._COMPAT_0_7: + dlDone = AttributeDeprecatedBy('dl_done') + dlQueued = AttributeDeprecatedBy('dl_queued') + dlFailed = AttributeDeprecatedBy('dl_failed') + dlHit = AttributeDeprecatedBy('dl_hit') + dlIgnored = AttributeDeprecatedBy('dl_ignored') + dlStatusStr = AttributeDeprecatedBy('dl_status_str') + currentBytes = AttributeDeprecatedBy('current_bytes') + currentItems = AttributeDeprecatedBy('current_items') + totalBytes = AttributeDeprecatedBy('total_bytes') + totalItems = AttributeDeprecatedBy('total_items') + currentCPS = AttributeDeprecatedBy('current_cps') + updateStatus = function_deprecated_by(update_status) + mediaChange = function_deprecated_by(media_change) + class TextFetchProgress(FetchProgress): """ Ready to use progress object for terminal windows """ @@ -136,13 +155,13 @@ class TextFetchProgress(FetchProgress): FetchProgress.__init__(self) self.items = {} - def updateStatus(self, uri, descr, shortDescr, status): + def update_status(self, uri, descr, short_descr, status): """Called when the status of an item changes. This happens eg. when the downloads fails or is completed. """ - if status != self.dlQueued: - print "\r%s %s" % (self.dlStatusStr[status], descr) + if status != self.dl_queued: + print "\r%s %s" % (self.dl_status_str[status], descr) self.items[uri] = status def pulse(self): @@ -151,10 +170,10 @@ class TextFetchProgress(FetchProgress): Return True to continue or False to cancel. """ FetchProgress.pulse(self) - if self.currentCPS > 0: + if self.current_cps > 0: s = "[%2.f%%] %sB/s %s" % (self.percent, - apt_pkg.size_to_str(int(self.currentCPS)), - apt_pkg.time_to_str(int(self.eta))) + apt_pkg.size_to_str(int(self.current_cps)), + apt_pkg.time_to_str(int(self.eta))) else: s = "%2.f%% [Working]" % (self.percent) print "\r%s" % (s), @@ -165,13 +184,17 @@ class TextFetchProgress(FetchProgress): """Called when all files have been fetched.""" print "\rDone downloading " - def mediaChange(self, medium, drive): + def media_change(self, medium, drive): """react to media change events.""" print ("Media change: please insert the disc labeled " "'%s' in the drive '%s' and press enter") % (medium, drive) return raw_input() not in ('c', 'C') + if apt_pkg._COMPAT_0_7: + updateStatus = function_deprecated_by(update_status) + mediaChange = function_deprecated_by(media_change) + class DumbInstallProgress(object): """Report the install progress. @@ -179,19 +202,24 @@ class DumbInstallProgress(object): Subclass this class to implement install progress reporting. """ - def startUpdate(self): + def start_update(self): """Start update.""" def run(self, pm): """Start installation.""" return pm.do_install() - def finishUpdate(self): + def finish_update(self): """Called when update has finished.""" - def updateInterface(self): + def update_interface(self): """Called periodically to update the user interface""" + if apt_pkg._COMPAT_0_7: + startUpdate = function_deprecated_by(start_update) + finishUpdate = function_deprecated_by(finish_update) + updateInterface = function_deprecated_by(update_interface) + class InstallProgress(DumbInstallProgress): """An InstallProgress that is pretty useful. @@ -202,7 +230,7 @@ class InstallProgress(DumbInstallProgress): def __init__(self): DumbInstallProgress.__init__(self) - self.selectTimeout = 0.1 + self.select_timeout = 0.1 (read, write) = os.pipe() self.writefd = write self.statusfd = os.fdopen(read, "r") @@ -217,10 +245,10 @@ class InstallProgress(DumbInstallProgress): def conffile(self, current, new): """Called when a conffile question from dpkg is detected.""" - def statusChange(self, pkg, percent, status): + def status_change(self, pkg, percent, status): """Called when the status changed.""" - def updateInterface(self): + def update_interface(self): """Called periodically to update the interface.""" if self.statusfd is None: return @@ -253,7 +281,7 @@ class InstallProgress(DumbInstallProgress): self.conffile(match.group(1), match.group(2)) elif status == "pmstatus": if float(percent) != self.percent or status_str != self.status: - self.statusChange(pkg, float(percent), + self.status_change(pkg, float(percent), status_str.strip()) self.percent = float(percent) self.status = status_str.strip() @@ -263,11 +291,11 @@ class InstallProgress(DumbInstallProgress): """Fork.""" return os.fork() - def waitChild(self): + def wait_child(self): """Wait for child progress to exit.""" while True: - select.select([self.statusfd], [], [], self.selectTimeout) - self.updateInterface() + select.select([self.statusfd], [], [], self.select_timeout) + self.update_interface() (pid, res) = os.waitpid(self.child_pid, os.WNOHANG) if pid == self.child_pid: break @@ -281,9 +309,15 @@ class InstallProgress(DumbInstallProgress): res = pm.do_install(self.writefd) os._exit(res) self.child_pid = pid - res = self.waitChild() + res = self.wait_child() return os.WEXITSTATUS(res) + if apt_pkg._COMPAT_0_7: + selectTimeout = AttributeDeprecatedBy('select_timeout') + statusChange = function_deprecated_by(status_change) + waitChild = function_deprecated_by(wait_child) + updateInterface = function_deprecated_by(update_interface) + class CdromProgress(object): """Report the cdrom add progress. @@ -297,12 +331,16 @@ class CdromProgress(object): def update(self, text, step): """Called periodically to update the user interface.""" - def askCdromName(self): + def ask_cdrom_name(self): """Called to ask for the name of the cdrom.""" - def changeCdrom(self): + def change_cdrom(self): """Called to ask for the cdrom to be changed.""" + if apt_pkg._COMPAT_0_7: + askCdromName = function_deprecated_by(ask_cdrom_name) + changeCdrom = function_deprecated_by(change_cdrom) + class DpkgInstallProgress(InstallProgress): """Progress handler for a local Debian package installation.""" @@ -318,10 +356,10 @@ class DpkgInstallProgress(InstallProgress): (self.writefd, self.debfile)) os._exit(os.WEXITSTATUS(res)) self.child_pid = pid - res = self.waitChild() + res = self.wait_child() return res - def updateInterface(self): + def update_interface(self): """Process status messages from dpkg.""" if self.statusfd is None: return @@ -354,3 +392,6 @@ class DpkgInstallProgress(InstallProgress): else: self.status = status self.read = "" + + if apt_pkg._COMPAT_0_7: + updateInterface = function_deprecated_by(update_interface) diff --git a/apt/progress/gtk2.py b/apt/progress/gtk2.py index 06ece2d5..c0c05426 100644 --- a/apt/progress/gtk2.py +++ b/apt/progress/gtk2.py @@ -39,6 +39,7 @@ import vte import apt import apt_pkg +from apt.deprecation import function_deprecated_by def mksig(params=(), run=gobject.SIGNAL_RUN_FIRST, rettype=gobject.TYPE_NONE): @@ -113,13 +114,13 @@ class GInstallProgress(gobject.GObject, apt.progress.InstallProgress): self.time_last_update = time.time() self.term = term reaper = vte.reaper_get() - reaper.connect("child-exited", self.childExited) + reaper.connect("child-exited", self.child_exited) self.env = ["VTE_PTY_KEEP_FD=%s" % self.writefd, "DEBIAN_FRONTEND=gnome", "APT_LISTCHANGES_FRONTEND=gtk"] self._context = glib.main_context_default() - def childExited(self, term, pid, status): + def child_exited(self, term, pid, status): """Called when a child process exits""" self.apt_status = os.WEXITSTATUS(status) self.finished = True @@ -138,21 +139,21 @@ class GInstallProgress(gobject.GObject, apt.progress.InstallProgress): """ self.emit("status-conffile") - def startUpdate(self): + def start_update(self): """Called when the update starts. Emits: status-started() """ self.emit("status-started") - def finishUpdate(self): + def finish_update(self): """Called when the update finished. Emits: status-finished() """ self.emit("status-finished") - def statusChange(self, pkg, percent, status): + def status_change(self, pkg, percent, status): """Called when the status changed. Emits: status-changed(status, percent) @@ -160,12 +161,12 @@ class GInstallProgress(gobject.GObject, apt.progress.InstallProgress): self.time_last_update = time.time() self.emit("status-changed", status, percent) - def updateInterface(self): + def update_interface(self): """Called periodically to update the interface. Emits: status-timeout() [When a timeout happens] """ - apt.progress.InstallProgress.updateInterface(self) + apt.progress.InstallProgress.update_interface(self) while self._context.pending(): self._context.iteration() if self.time_last_update + self.INSTALL_TIMEOUT < time.time(): @@ -175,12 +176,20 @@ class GInstallProgress(gobject.GObject, apt.progress.InstallProgress): """Fork the process.""" return self.term.forkpty(envv=self.env) - def waitChild(self): + def wait_child(self): """Wait for the child process to exit.""" while not self.finished: - self.updateInterface() + self.update_interface() return self.apt_status + if apt_pkg._COMPAT_0_7: + updateInterface = function_deprecated_by(update_interface) + startUpdate = function_deprecated_by(start_update) + finishUpdate = function_deprecated_by(finish_update) + statusChange = function_deprecated_by(status_change) + waitChild = function_deprecated_by(wait_child) + childExited = function_deprecated_by(child_exited) + class GDpkgInstallProgress(apt.progress.DpkgInstallProgress, GInstallProgress): """An InstallProgress for local installations. @@ -199,14 +208,17 @@ class GDpkgInstallProgress(apt.progress.DpkgInstallProgress, GInstallProgress): """Install the given package.""" apt.progress.DpkgInstallProgress.run(self, debfile) - def updateInterface(self): + def update_interface(self): """Called periodically to update the interface. Emits: status-timeout() [When a timeout happens]""" - apt.progress.DpkgInstallProgress.updateInterface(self) + apt.progress.DpkgInstallProgress.update_interface(self) if self.time_last_update + self.INSTALL_TIMEOUT < time.time(): self.emit("status-timeout") + if apt_pkg._COMPAT_0_7: + updateInterface = function_deprecated_by(update_interface) + class GFetchProgress(gobject.GObject, apt.progress.FetchProgress): """A Fetch Progress with GObject signals. @@ -239,19 +251,19 @@ class GFetchProgress(gobject.GObject, apt.progress.FetchProgress): def pulse(self): apt.progress.FetchProgress.pulse(self) - currentItem = self.currentItems + 1 - if currentItem > self.totalItems: - currentItem = self.totalItems - if self.currentCPS > 0: + current_item = self.current_items + 1 + if current_item > self.total_items: + current_item = self.total_items + if self.current_cps > 0: text = (_("Downloading file %(current)li of %(total)li with " "%(speed)s/s") % \ - {"current": currentItem, - "total": self.totalItems, - "speed": apt_pkg.size_to_str(self.currentCPS)}) + {"current": current_item, + "total": self.total_items, + "speed": apt_pkg.size_to_str(self.current_cps)}) else: text = (_("Downloading file %(current)li of %(total)li") % \ - {"current": currentItem, - "total": self.totalItems}) + {"current": current_item, + "total": self.total_items}) self.emit("status-changed", text, self.percent) while self._context.pending(): self._context.iteration() diff --git a/python/progress.cc b/python/progress.cc index bec40ce9..8214a789 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -12,7 +12,6 @@ #include #include "progress.h" - // generic bool PyCallbackObj::RunSimpleCallback(const char* method_name, PyObject *arglist, @@ -58,10 +57,16 @@ void PyOpProgress::Update() PyObject_SetAttrString(callbackInst, "op", o); Py_XDECREF(o); o = Py_BuildValue("s", SubOp.c_str()); - PyObject_SetAttrString(callbackInst, "subOp", o); + if(PyObject_HasAttrString(callbackInst, "sub_op")) + PyObject_SetAttrString(callbackInst, "sub_op", o); + else + PyObject_SetAttrString(callbackInst, "subOp", o); Py_XDECREF(o); o = Py_BuildValue("b", MajorChange); - PyObject_SetAttrString(callbackInst, "majorChange", o); + if(PyObject_HasAttrString(callbackInst, "major_change")) + PyObject_SetAttrString(callbackInst, "major_change", o); + else + PyObject_SetAttrString(callbackInst, "majorChange", o); Py_XDECREF(o); // Build up the argument list... @@ -89,7 +94,10 @@ bool PyFetchProgress::MediaChange(string Media, string Drive) //std::cout << "MediaChange" << std::endl; PyObject *arglist = Py_BuildValue("(ss)", Media.c_str(), Drive.c_str()); PyObject *result; - RunSimpleCallback("mediaChange", arglist, &result); + if(PyObject_HasAttrString(callbackInst, "media_change")) + RunSimpleCallback("media_change", arglist, &result); + else + RunSimpleCallback("mediaChange", arglist, &result); bool res = true; if(!PyArg_Parse(result, "b", &res)) @@ -105,7 +113,10 @@ void PyFetchProgress::UpdateStatus(pkgAcquire::ItemDesc &Itm, int status) { //std::cout << "UpdateStatus: " << Itm.URI << " " << status << std::endl; PyObject *arglist = Py_BuildValue("(sssi)", Itm.URI.c_str(), Itm.Description.c_str(), Itm.ShortDesc.c_str(), status); - RunSimpleCallback("updateStatus", arglist); + if(PyObject_HasAttrString(callbackInst, "update_status")) + RunSimpleCallback("update_status", arglist); + else + RunSimpleCallback("updateStatus", arglist); } void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) @@ -163,19 +174,34 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) // set stats PyObject *o; o = Py_BuildValue("f", CurrentCPS); - PyObject_SetAttrString(callbackInst, "currentCPS", o); + if(PyObject_HasAttrString(callbackInst, "current_cps")) + PyObject_SetAttrString(callbackInst, "current_cps", o); + else + PyObject_SetAttrString(callbackInst, "currentCPS", o); Py_XDECREF(o); o = Py_BuildValue("f", CurrentBytes); - PyObject_SetAttrString(callbackInst, "currentBytes", o); + if(PyObject_HasAttrString(callbackInst, "current_bytes")) + PyObject_SetAttrString(callbackInst, "current_bytes", o); + else + PyObject_SetAttrString(callbackInst, "currentBytes", o); Py_XDECREF(o); o = Py_BuildValue("i", CurrentItems); - PyObject_SetAttrString(callbackInst, "currentItems", o); + if(PyObject_HasAttrString(callbackInst, "current_items")) + PyObject_SetAttrString(callbackInst, "current_items", o); + else + PyObject_SetAttrString(callbackInst, "currentItems", o); Py_XDECREF(o); o = Py_BuildValue("i", TotalItems); - PyObject_SetAttrString(callbackInst, "totalItems", o); + if(PyObject_HasAttrString(callbackInst, "total_items")) + PyObject_SetAttrString(callbackInst, "total_items", o); + else + PyObject_SetAttrString(callbackInst, "totalItems", o); Py_XDECREF(o); o = Py_BuildValue("f", TotalBytes); - PyObject_SetAttrString(callbackInst, "totalBytes", o); + if(PyObject_HasAttrString(callbackInst, "total_bytes")) + PyObject_SetAttrString(callbackInst, "total_bytes", o); + else + PyObject_SetAttrString(callbackInst, "totalBytes", o); Py_XDECREF(o); PyObject *arglist = Py_BuildValue("()"); @@ -201,17 +227,26 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) void PyInstallProgress::StartUpdate() { - RunSimpleCallback("startUpdate"); + if(PyObject_HasAttrString(callbackInst, "start_update")) + RunSimpleCallback("start_update"); + else + RunSimpleCallback("startUpdate"); } void PyInstallProgress::UpdateInterface() { - RunSimpleCallback("updateInterface"); + if(PyObject_HasAttrString(callbackInst, "update_interface")) + RunSimpleCallback("update_interface"); + else + RunSimpleCallback("updateInterface"); } void PyInstallProgress::FinishUpdate() { - RunSimpleCallback("finishUpdate"); + if(PyObject_HasAttrString(callbackInst, "finish_update")) + RunSimpleCallback("finish_update"); + else + RunSimpleCallback("finishUpdate"); } pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) @@ -272,8 +307,13 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) StartUpdate(); - if(PyObject_HasAttrString(callbackInst, "waitChild")) { - PyObject *method = PyObject_GetAttrString(callbackInst, "waitChild"); + 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 + 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); @@ -323,7 +363,10 @@ bool PyCdromProgress::ChangeCdrom() { PyObject *arglist = Py_BuildValue("()"); PyObject *result; - RunSimpleCallback("changeCdrom", arglist, &result); + if(PyObject_HasAttrString(callbackInst, "change_cdrom")) + RunSimpleCallback("change_cdrom", arglist, &result); + else + RunSimpleCallback("changeCdrom", arglist, &result); bool res = true; if(!PyArg_Parse(result, "b", &res)) @@ -337,7 +380,11 @@ bool PyCdromProgress::AskCdromName(string &Name) { PyObject *arglist = Py_BuildValue("()"); PyObject *result; - RunSimpleCallback("askCdromName", arglist, &result); + + if(PyObject_HasAttrString(callbackInst, "ask_cdrom_name")) + RunSimpleCallback("ask_cdrom_name", arglist, &result); + else + RunSimpleCallback("askCdromName", arglist, &result); const char *new_name; bool res; -- cgit v1.2.3 From 13b0eb25325d44c05ac36f6d1069fd735992bbc1 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 8 Jun 2009 18:11:10 +0200 Subject: python/progress.cc: #include "generic.h" to fix build failure with python2.4 --- python/progress.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index 39124df1..2671f6fc 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -14,6 +14,7 @@ #include #include #include "progress.h" +#include "generic.h" // generic bool PyCallbackObj::RunSimpleCallback(const char* method_name, -- cgit v1.2.3 From 498e518b22f9976c4ebcf110c05ada4c0d9bedf6 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 21 Jun 2009 11:17:08 +0200 Subject: python/progress.cc: Fix segfault related to pulse_items. --- python/progress.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index 2671f6fc..bc46b0c8 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -310,11 +310,11 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) PyObject *result; bool res = true; - - RunSimpleCallback("pulse_items", arglist, &result); - if (result != NULL && PyArg_Parse(result, "b", &res) && res == false) { - // the user returned a explicit false here, stop - return false; + if (RunSimpleCallback("pulse_items", arglist, &result)) { + if (result != NULL && PyArg_Parse(result, "b", &res) && res == false) { + // the user returned a explicit false here, stop + return false; + } } arglist = Py_BuildValue("()"); -- cgit v1.2.3 From cef5268fc12c6a4b4b8aa2b58a09494b1944e28a Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 21 Jun 2009 13:45:11 +0200 Subject: python/progress.cc: Just try to call a function and fallback. --- python/progress.cc | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index bc46b0c8..c5035e62 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -101,9 +101,7 @@ bool PyFetchProgress::MediaChange(string Media, string Drive) //std::cout << "MediaChange" << std::endl; 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(! RunSimpleCallback("media_change", arglist, &result)) RunSimpleCallback("mediaChange", arglist, &result); bool res = true; @@ -137,9 +135,7 @@ void PyFetchProgress::UpdateStatus(pkgAcquire::ItemDesc &Itm, int status) Itm.Description.c_str(), Itm.ShortDesc.c_str(), status); - if(PyObject_HasAttrString(callbackInst, "update_status")) - RunSimpleCallback("update_status", arglist); - else + if(!RunSimpleCallback("update_status", arglist)) RunSimpleCallback("updateStatus", arglist); } @@ -340,25 +336,19 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) void PyInstallProgress::StartUpdate() { - if(PyObject_HasAttrString(callbackInst, "start_update")) - RunSimpleCallback("start_update"); - else + if (!RunSimpleCallback("start_update")) RunSimpleCallback("startUpdate"); } void PyInstallProgress::UpdateInterface() { - if(PyObject_HasAttrString(callbackInst, "update_interface")) - RunSimpleCallback("update_interface"); - else + if (!RunSimpleCallback("update_interface")) RunSimpleCallback("updateInterface"); } void PyInstallProgress::FinishUpdate() { - if(PyObject_HasAttrString(callbackInst, "finish_update")) - RunSimpleCallback("finish_update"); - else + if (!RunSimpleCallback("finish_update")) RunSimpleCallback("finishUpdate"); } @@ -476,9 +466,7 @@ bool PyCdromProgress::ChangeCdrom() { PyObject *arglist = Py_BuildValue("()"); PyObject *result; - if(PyObject_HasAttrString(callbackInst, "change_cdrom")) - RunSimpleCallback("change_cdrom", arglist, &result); - else + if(!RunSimpleCallback("change_cdrom", arglist, &result)) RunSimpleCallback("changeCdrom", arglist, &result); bool res = true; @@ -494,9 +482,7 @@ bool PyCdromProgress::AskCdromName(string &Name) PyObject *arglist = Py_BuildValue("()"); PyObject *result; - if(PyObject_HasAttrString(callbackInst, "ask_cdrom_name")) - RunSimpleCallback("ask_cdrom_name", arglist, &result); - else + if (!RunSimpleCallback("ask_cdrom_name", arglist, &result)) RunSimpleCallback("askCdromName", arglist, &result); const char *new_name; -- cgit v1.2.3 From a4e69e11e544844034c3fbdc6789d5573f802117 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 25 Jun 2009 18:31:00 +0200 Subject: python: Fix some build warnings. --- python/acquire.cc | 4 ++-- python/cache.cc | 9 ++++----- python/depcache.cc | 3 --- python/indexfile.cc | 2 +- python/pkgsrcrecords.cc | 1 - python/progress.cc | 2 -- python/tar.cc | 4 ++++ setup.py | 4 ++-- 8 files changed, 13 insertions(+), 16 deletions(-) (limited to 'python/progress.cc') diff --git a/python/acquire.cc b/python/acquire.cc index e13e47d6..a36012bc 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -93,8 +93,8 @@ static PyObject *AcquireItemRepr(PyObject *Self) char S[300]; snprintf(S,sizeof(S),"<%s object: " "Status: %i Complete: %i Local: %i IsTrusted: %i " - "FileSize: %i DestFile:'%s' " - "DescURI: '%s' ID:%i ErrorText: '%s'>", + "FileSize: %lu DestFile:'%s' " + "DescURI: '%s' ID:%lu ErrorText: '%s'>", Self->ob_type->tp_name, Itm->Status, Itm->Complete, Itm->Local, Itm->IsTrusted(), Itm->FileSize, Itm->DestFile.c_str(), Itm->DescURI().c_str(), diff --git a/python/cache.cc b/python/cache.cc index 2de9c76a..0f5e27eb 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -76,9 +76,6 @@ static PyObject *CreateProvides(PyObject *Owner,pkgCache::PrvIterator I) // --------------------------------------------------------------------- static PyObject *PkgCacheUpdate(PyObject *Self,PyObject *Args) { - PyObject *CacheFilePy = GetOwner(Self); - pkgCacheFile *Cache = GetCpp(CacheFilePy); - PyObject *pyFetchProgressInst = 0; PyObject *pySourcesList = 0; if (PyArg_ParseTuple(Args, "OO", &pyFetchProgressInst,&pySourcesList) == 0) @@ -93,6 +90,7 @@ static PyObject *PkgCacheUpdate(PyObject *Self,PyObject *Args) return HandleErrors(PyRes); } +#ifdef COMPAT_0_7 static PyObject *PkgCacheClose(PyObject *Self,PyObject *Args) { PyErr_WarnEx(PyExc_DeprecationWarning, "Cache.Close() is deprecated, " @@ -137,7 +135,7 @@ static PyObject *PkgCacheOpen(PyObject *Self,PyObject *Args) Py_INCREF(Py_None); return HandleErrors(Py_None); } - +#endif static PyMethodDef PkgCacheMethods[] = { @@ -456,10 +454,10 @@ PyTypeObject PkgListType = CppOwnedClear, // tp_clear }; +#define Owner (GetOwner(Self)) #define MkGet(PyFunc,Ret) static PyObject *PyFunc(PyObject *Self,void*) \ { \ pkgCache::PkgIterator &Pkg = GetCpp(Self); \ - PyObject *Owner = GetOwner(Self); \ return Ret; \ } @@ -477,6 +475,7 @@ MkGet(PackageGetAuto,Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Auto) != 0) MkGet(PackageGetEssential,Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Essential) != 0)); MkGet(PackageGetImportant,Py_BuildValue("i",(Pkg->Flags & pkgCache::Flag::Important) != 0)); #undef MkGet +#undef Owner static PyObject *PackageGetVersionList(PyObject *Self,void*) { diff --git a/python/depcache.cc b/python/depcache.cc index e1514300..9c0c9a6f 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -62,8 +62,6 @@ static PyObject *PkgDepCacheInit(PyObject *Self,PyObject *Args) static PyObject *PkgDepCacheCommit(PyObject *Self,PyObject *Args) { - PyObject *result; - pkgDepCache *depcache = GetCpp(Self); PyObject *pyInstallProgressInst = 0; @@ -196,7 +194,6 @@ static PyObject *PkgDepCacheSetCandidateVer(PyObject *Self,PyObject *Args) &VersionType, &VersionObj) == 0) return 0; - pkgCache::PkgIterator &Pkg = GetCpp(PackageObj); pkgCache::VerIterator &I = GetCpp(VersionObj); if(I.end()) { return HandleErrors(Py_BuildValue("b",false)); diff --git a/python/indexfile.cc b/python/indexfile.cc index ef88c2f0..73f76ce6 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -62,7 +62,7 @@ static PyObject *PackageIndexFileRepr(PyObject *Self) char S[1024]; snprintf(S,sizeof(S),"", File->GetType()->Label, File->Describe().c_str(), File->Exists(), File->HasPackages(), File->Size(), diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index f75934f9..9707dce2 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -58,7 +58,6 @@ static PyObject *PkgSrcRecordsRestart(PyObject *Self,PyObject *Args) { PkgSrcRecordsStruct &Struct = GetCpp(Self); - char *Name = 0; if (PyArg_ParseTuple(Args,"") == 0) return 0; diff --git a/python/progress.cc b/python/progress.cc index c5035e62..44f27b0c 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -354,7 +354,6 @@ void PyInstallProgress::FinishUpdate() pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) { - void *dummy; pkgPackageManager::OrderResult res; int ret; pid_t child_id; @@ -426,7 +425,6 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) 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; diff --git a/python/tar.cc b/python/tar.cc index 217554c2..b93ba31a 100644 --- a/python/tar.cc +++ b/python/tar.cc @@ -72,8 +72,12 @@ bool ProcessTar::DoItem(Item &Itm,int &Fd) case Item::FIFO: Type = "FIFO"; break; + + default: + return false; } + if (PyObject_CallFunction(Function,"sssiiiiiii",Type,Itm.Name, Itm.LinkTarget,Itm.Mode,Itm.UID,Itm.GID,Itm.Size, Itm.MTime,Itm.Major,Itm.Minor) == 0) diff --git a/setup.py b/setup.py index 2afd0708..85f4c889 100755 --- a/setup.py +++ b/setup.py @@ -12,12 +12,12 @@ from DistUtilsExtra.command import build_extra, build_i18n # The apt_pkg module files = map(lambda source: "python/"+source, - parse_makefile("python/makefile")["APT_PKG_SRC"].split()) + sorted(parse_makefile("python/makefile")["APT_PKG_SRC"].split())) apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]) # The apt_inst module files = map(lambda source: "python/"+source, - parse_makefile("python/makefile")["APT_INST_SRC"].split()) + sorted(parse_makefile("python/makefile")["APT_INST_SRC"].split())) apt_inst = Extension("apt_inst", files, libraries=["apt-pkg", "apt-inst"]) # Replace the leading _ that is used in the templates for translation -- cgit v1.2.3 From aaf5907863bed9a044fa0e3e2eacd1ca2de53c59 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 15 Jul 2009 21:36:58 +0200 Subject: Introduce new progress (base) classes in apt_pkg: - apt_pkg.AcquireProgress - apt_pkg.OpProgress --- debian/changelog | 3 + python/acquireprogress.cc | 198 ++++++++++++++++++++++++++++++++++++++++++++++ python/apt_pkgmodule.cc | 2 + python/apt_pkgmodule.h | 2 + python/opprogress.cc | 173 ++++++++++++++++++++++++++++++++++++++++ python/progress.cc | 14 +++- setup.py | 5 +- 7 files changed, 393 insertions(+), 4 deletions(-) create mode 100644 python/acquireprogress.cc create mode 100644 python/opprogress.cc (limited to 'python/progress.cc') diff --git a/debian/changelog b/debian/changelog index 5e3ec667..b2936ba1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -39,6 +39,9 @@ python-apt (0.7.92) UNRELEASED; urgency=low work around a bug in debhelper. * Build-Depend on python-all-dev (>= 2.5.4-3), so we build for Python 2.6 * Simplify the whole building, build all Python versions with setup.py + * Introduce new progress (base) classes in apt_pkg: + - apt_pkg.AcquireProgress + - apt_pkg.OpProgress [ Sebastian Heinlein ] * apt/progress.py: Extract the package name from the status message diff --git a/python/acquireprogress.cc b/python/acquireprogress.cc new file mode 100644 index 00000000..ac3b8fd9 --- /dev/null +++ b/python/acquireprogress.cc @@ -0,0 +1,198 @@ +/* acquireprogress.cc - Base class for FetchProgress classes. + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "generic.h" +#include +#include + +typedef struct { + PyObject_HEAD + double last_bytes; + double current_cps; + double current_bytes; + double total_bytes; + double fetched_bytes; + unsigned long elapsed_time; + unsigned long total_items; + unsigned long current_items; +} PyAcquireProgressObject; + + +// DUMMY IMPLEMENTATIONS. +static char *acquireprogress_media_change_doc = + "media_change(media: str, drive: str) -> bool\n\n" + "Invoked when the user should be prompted to change the inserted\n" + "removable media.\n\n" + "This method should not return until the user has confirmed to the user\n" + "interface that the media change is complete.\n\n" + ":param:media The name of the media type that should be changed.\n" + ":param:drive The identifying name of the drive whose media should be\n" + " changed.\n\n" + "Return True if the user confirms the media change, False if it is\n" + "cancelled."; +static PyObject *acquireprogress_media_change(PyObject *self, PyObject *args) +{ + Py_RETURN_FALSE; +} + +static char *acquireprogress_ims_hit_doc = "ims_hit(item: AcquireItemDesc)\n\n" + "Invoked when an item is confirmed to be up-to-date. For instance,\n" + "when an HTTP download is informed that the file on the server was\n" + "not modified."; +static PyObject *acquireprogress_ims_hit(PyObject *self, PyObject *arg) +{ + // TODO: Add type check. + Py_RETURN_NONE; +} + +static char *acquireprogress_fetch_doc = "fetch(item: AcquireItemDesc)\n\n" + "Invoked when some of an item's data is fetched."; +static PyObject *acquireprogress_fetch(PyObject *self, PyObject *args) +{ + // TODO: Add type check. + Py_RETURN_NONE; +} + +static char *acquireprogress_done_doc = "done(item: AcquireItemDesc)\n\n" + "Invoked when an item is successfully and completely fetched."; +static PyObject *acquireprogress_done(PyObject *self, PyObject *args) +{ + // TODO: Add type check. + Py_RETURN_NONE; +} + +static char *acquireprogress_fail_doc = "fail(item: AcquireItemDesc)\n\n" + "Invoked when the process of fetching an item encounters a fatal error."; +static PyObject *acquireprogress_fail(PyObject *self, PyObject *args) +{ + // TODO: Add type check. + Py_RETURN_NONE; +} + +static char *acquireprogress_pulse_doc = "pulse(owner: Acquire) -> bool\n\n" + "Periodically invoked while the Acquire process is underway.\n\n" + "Return False if the user asked to cancel the whole Acquire process."; +static PyObject *acquireprogress_pulse(PyObject *self, PyObject *args) +{ + // TODO: Add type check. + Py_RETURN_TRUE; +} + +static char *acquireprogress_start_doc = "start()\n\n" + "Invoked when the Acquire process starts running."; +static PyObject *acquireprogress_start(PyObject *self, PyObject *args) +{ + Py_RETURN_NONE; +} + +static char *acquireprogress_stop_doc = "stop()\n\n" + "Invoked when the Acquire process stops running."; +static PyObject *acquireprogress_stop(PyObject *self, PyObject *args) +{ + Py_RETURN_NONE; +} + +static PyMethodDef acquireprogress_methods[] = { + {"media_change", acquireprogress_media_change, METH_VARARGS, + acquireprogress_media_change_doc}, + {"ims_hit",acquireprogress_ims_hit,METH_VARARGS, + acquireprogress_ims_hit_doc}, + {"fetch",acquireprogress_fetch,METH_VARARGS,acquireprogress_fetch_doc}, + {"done",acquireprogress_done,METH_VARARGS,acquireprogress_done_doc}, + {"fail",acquireprogress_fail,METH_VARARGS,acquireprogress_fail_doc}, + {"pulse",acquireprogress_pulse,METH_VARARGS,acquireprogress_pulse_doc}, + {"start",acquireprogress_start,METH_NOARGS,acquireprogress_start_doc}, + {"stop",acquireprogress_stop,METH_NOARGS,acquireprogress_stop_doc}, + {NULL} +}; + +static PyMemberDef acquireprogress_members[] = { + {"last_bytes", T_DOUBLE, offsetof(PyAcquireProgressObject, last_bytes), 0, + "The number of bytes fetched as of the previous call to pulse(),\n" + "including local items."}, + {"current_cps", T_DOUBLE, offsetof(PyAcquireProgressObject, current_cps), 0, + "The current rate of download, in bytes per second."}, + {"current_bytes", T_DOUBLE, offsetof(PyAcquireProgressObject, current_bytes), + 0, "The number of bytes fetched."}, + {"total_bytes", T_DOUBLE, offsetof(PyAcquireProgressObject, total_bytes), 0, + "The total number of bytes that need to be fetched. This member is\n" + "inaccurate, as new items might be enqueued while the download is\n" + "in progress!"}, + {"fetched_bytes", T_DOUBLE,offsetof(PyAcquireProgressObject, fetched_bytes), + 0, "The total number of bytes accounted for by items that were\n" + "successfully fetched."}, + {"elapsed_time", T_ULONG, offsetof(PyAcquireProgressObject, elapsed_time),0, + "The amount of time that has elapsed since the download started."}, + {"total_items", T_ULONG, offsetof(PyAcquireProgressObject, total_items),0, + "The total number of items that need to be fetched. This member is\n" + "inaccurate, as new items might be enqueued while the download is\n" + "in progress!"}, + {"current_items", T_ULONG, offsetof(PyAcquireProgressObject, current_items), + 0, "The number of items that have been successfully downloaded."}, + {NULL} +}; + +static char *acquireprogress_doc = "AcquireProgress()\n\n" + "A monitor object for downloads controlled by the Acquire class. This is\n" + "an mostly abstract class. You should subclass it and implement the\n" + "methods to get something useful."; + +PyTypeObject PyAcquireProgress_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.AcquireProgress", // tp_name + sizeof(PyAcquireProgressObject), // tp_basicsize + 0, // tp_itemsize + // Methods + 0, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE, + acquireprogress_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + acquireprogress_methods, // tp_methods + acquireprogress_members, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PyType_GenericNew, // tp_new +}; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index bc2f4258..4f948847 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -621,6 +621,8 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"HashString",&PyHashString_Type); ADDTYPE(Module,"Policy",&PyPolicy_Type); ADDTYPE(Module,"Hashes",&PyHashes_Type); + ADDTYPE(Module,"OpProgress",&PyOpProgress_Type); + ADDTYPE(Module,"AcquireProgress",&PyAcquireProgress_Type); // Tag file constants PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 97be5d5c..34bc2ae5 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -112,6 +112,8 @@ extern PyTypeObject PyIndexRecords_Type; // Policy extern PyTypeObject PyPolicy_Type; extern PyTypeObject PyHashes_Type; +extern PyTypeObject PyOpProgress_Type; +extern PyTypeObject PyAcquireProgress_Type; #include "python-apt.h" #endif diff --git a/python/opprogress.cc b/python/opprogress.cc new file mode 100644 index 00000000..450e290a --- /dev/null +++ b/python/opprogress.cc @@ -0,0 +1,173 @@ +/* op-progress.cc - Base class for OpProgress classes. + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "generic.h" +#include +#include + +typedef struct { + PyObject_HEAD + PyObject *op; + PyObject *subop; + int major_change; + float percent; +} PyOpProgressObject; + +static PyObject *opprogress_update(PyObject *Self, PyObject *args) +{ + Py_RETURN_NONE; +} + +static PyObject *opprogress_done(PyObject *Self, PyObject *args) +{ + Py_RETURN_NONE; +} + +static PyObject *opprogress_get_op(PyOpProgressObject *self, void *closure) +{ + return self->op; +} + +static int opprogress_set_op(PyOpProgressObject *self, PyObject *value, + void *closure) +{ + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, "Cannot delete 'op'"); + return -1; + } + if (!PyString_Check(value)) { + PyErr_SetString(PyExc_TypeError,"'op' must be a string."); + return -1; + } + Py_DECREF(self->op); + Py_INCREF(value); + + self->op = value; + return 0; +} + +static PyObject *opprogress_get_subop(PyOpProgressObject *self, void *closure) +{ + return self->subop; +} + +static int opprogress_set_subop(PyOpProgressObject *self, PyObject *value, + void *closure) +{ + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, "Cannot delete 'subop'."); + return -1; + } + if (!PyString_Check(value)) { + PyErr_SetString(PyExc_TypeError,"'subop' must be a string."); + return -1; + } + Py_DECREF(self->subop); + Py_INCREF(value); + self->subop = value; + return 0; +} + +static PyMethodDef opprogress_methods[] = { + {"update",opprogress_update,METH_NOARGS,"update()\n\nCalled periodically."}, + {"done",opprogress_done,METH_NOARGS,"update()\n\nCalled when done."}, + {NULL}, +}; + +static PyMemberDef opprogress_members[] = { + {"major_change", T_INT, offsetof(PyOpProgressObject, major_change), 0, + "Boolean value indicating whether the change is a major change."}, + {"percent", T_FLOAT, offsetof(PyOpProgressObject, percent), 0, + "Percentage of completion (float value)."}, + {NULL} +}; + +static PyGetSetDef opprogress_getset[] = { + {"op", (getter)opprogress_get_op, (setter)opprogress_set_op, + "Description of the current operation"}, + {"subop", (getter)opprogress_get_subop, (setter)opprogress_set_subop, + "Description of the current sub-operation"}, + {NULL}, +}; + +static void opprogress_dealloc(PyObject *self) +{ + Py_XDECREF(((PyOpProgressObject *)self)->op); + Py_XDECREF(((PyOpProgressObject *)self)->subop); + self->ob_type->tp_free(self); +} + +static PyObject *opprogress_new(PyTypeObject *type, PyObject *args, + PyObject *kwds) +{ + PyOpProgressObject *res = (PyOpProgressObject *)type->tp_alloc(type, 0); + res->op = PyString_FromString(""); + res->subop = PyString_FromString(""); + return (PyObject *)res; +} + +static char *opprogress_doc = "OpProgress()\n\n" + "A base class for writing custom operation progress classes. Subclasses\n" + "should override all the methods (and call the parent ones) but shall\n" + "not override any of the inherited descriptors because they may be\n" + "ignored."; + +PyTypeObject PyOpProgress_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.OpProgress", // tp_name + sizeof(PyOpProgressObject), // tp_basicsize + 0, // tp_itemsize + // Methods + opprogress_dealloc, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE, + opprogress_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + opprogress_methods, // tp_methods + opprogress_members, // tp_members + opprogress_getset, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + opprogress_new, // tp_new +}; diff --git a/python/progress.cc b/python/progress.cc index 44f27b0c..b1845f0a 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -15,6 +15,7 @@ #include #include "progress.h" #include "generic.h" +#include "apt_pkgmodule.h" // generic bool PyCallbackObj::RunSimpleCallback(const char* method_name, @@ -75,11 +76,20 @@ void PyOpProgress::Update() PyObject_SetAttrString(callbackInst, "majorChange", o); Py_XDECREF(o); + + // Build up the argument list... if(CheckChange(0.05)) { - PyObject *arglist = Py_BuildValue("(f)", Percent); - RunSimpleCallback("update", arglist); + if (PyObject_TypeCheck(callbackInst, &PyOpProgress_Type)) { + o = Py_BuildValue("f", Percent); + PyObject_SetAttrString(callbackInst, "percent", o); + RunSimpleCallback("update"); + Py_XDECREF(o); + } else { + PyObject *arglist = Py_BuildValue("(f)", Percent); + RunSimpleCallback("update", arglist); + } } }; diff --git a/setup.py b/setup.py index af373632..b6dde3f9 100644 --- a/setup.py +++ b/setup.py @@ -34,8 +34,9 @@ files = ['apt_pkgmodule.cc', 'acquire.cc', 'cache.cc', 'cdrom.cc', 'configuration.cc', 'depcache.cc', 'generic.cc', 'hashes.cc', 'hashstring.cc', 'indexfile.cc', 'indexrecords.cc', 'metaindex.cc', 'pkgmanager.cc', 'pkgrecords.cc', 'pkgsrcrecords.cc', 'policy.cc', - 'progress.cc', 'sourcelist.cc', 'string.cc', 'tag.cc'] -files = ['python/' + fname for fname in files] + 'progress.cc', 'sourcelist.cc', 'string.cc', 'tag.cc', + 'opprogress.cc', 'acquireprogress.cc'] +files = sorted(['python/' + fname for fname in files]) apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]) # The apt_inst module -- cgit v1.2.3 From c12a853032583a8ed829e2d0ac6752bc14efdc80 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 15 Jul 2009 22:21:23 +0200 Subject: python/progress.cc: Add support for PyAcquireProgress. --- python/progress.cc | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index b1845f0a..c53a2ea5 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -17,6 +17,7 @@ #include "generic.h" #include "apt_pkgmodule.h" +#define TUPLEIZE(op) Py_BuildValue("(O)", op) // generic bool PyCallbackObj::RunSimpleCallback(const char* method_name, PyObject *arglist, @@ -151,17 +152,26 @@ void PyFetchProgress::UpdateStatus(pkgAcquire::ItemDesc &Itm, int status) void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) { - UpdateStatus(Itm, DLHit); + if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) + RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + else + UpdateStatus(Itm, DLHit); } void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) { - UpdateStatus(Itm, DLQueued); + if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) + RunSimpleCallback("fetch", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + else + UpdateStatus(Itm, DLQueued); } void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) { - UpdateStatus(Itm, DLDone); + if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) + RunSimpleCallback("done", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + else + UpdateStatus(Itm, DLDone); } void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) @@ -175,7 +185,11 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) UpdateStatus(Itm, DLIgnored); } - UpdateStatus(Itm, DLFailed); + + if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) + RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + else + UpdateStatus(Itm, DLFailed); } void PyFetchProgress::Start() @@ -183,6 +197,9 @@ void PyFetchProgress::Start() //std::cout << "Start" << std::endl; pkgAcquireStatus::Start(); + if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) + goto end; + // These attributes should be initialized before the first callback (start) // is invoked. // -- Stephan @@ -198,12 +215,14 @@ void PyFetchProgress::Start() PyObject_SetAttrString(callbackInst, "currentItems", o); Py_XDECREF(o); o = Py_BuildValue("i", 0); + PyObject_SetAttrString(callbackInst, "totalItems", o); Py_XDECREF(o); o = Py_BuildValue("f", 0.0f); PyObject_SetAttrString(callbackInst, "totalBytes", o); Py_XDECREF(o); +end: RunSimpleCallback("start"); } @@ -256,6 +275,17 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) PyObject_SetAttrString(callbackInst, "totalBytes", o); Py_XDECREF(o); + if (PyObject_TypeCheck(callbackInst, &PyAcquireProgress_Type)) { + PyObject *result1; + bool res1 = true; + if (RunSimpleCallback("pulse", TUPLEIZE(PyAcquire_FromCpp(Owner)), &result1)) { + if (result1 != NULL && PyArg_Parse(result1, "b", &res1) && res1 == false) { + // the user returned a explicit false here, stop + return false; + } + } + return true; + } // Go through the list of items and add active items to the // activeItems vector. map activeItemMap; -- cgit v1.2.3 From 6c9876724542889c6ee1542cf529b88ffa2cf456 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 16 Jul 2009 13:47:30 +0200 Subject: python/progress.cc: Fix the types of the attributes. --- python/progress.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index c53a2ea5..c33db502 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -205,20 +205,20 @@ void PyFetchProgress::Start() // -- Stephan PyObject *o; - o = Py_BuildValue("f", 0.0f); + o = Py_BuildValue("d", 0.0f); PyObject_SetAttrString(callbackInst, "currentCPS", o); Py_XDECREF(o); - o = Py_BuildValue("f", 0.0f); + o = Py_BuildValue("d", 0.0f); PyObject_SetAttrString(callbackInst, "currentBytes", o); Py_XDECREF(o); - o = Py_BuildValue("i", 0); + o = Py_BuildValue("k", 0); PyObject_SetAttrString(callbackInst, "currentItems", o); Py_XDECREF(o); - o = Py_BuildValue("i", 0); + o = Py_BuildValue("k", 0); PyObject_SetAttrString(callbackInst, "totalItems", o); Py_XDECREF(o); - o = Py_BuildValue("f", 0.0f); + o = Py_BuildValue("d", 0.0f); PyObject_SetAttrString(callbackInst, "totalBytes", o); Py_XDECREF(o); @@ -244,31 +244,31 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) // set stats PyObject *o; - o = Py_BuildValue("f", CurrentCPS); + o = Py_BuildValue("d", CurrentCPS); if(PyObject_HasAttrString(callbackInst, "current_cps")) PyObject_SetAttrString(callbackInst, "current_cps", o); else PyObject_SetAttrString(callbackInst, "currentCPS", o); Py_XDECREF(o); - o = Py_BuildValue("f", CurrentBytes); + o = Py_BuildValue("d", CurrentBytes); if(PyObject_HasAttrString(callbackInst, "current_bytes")) PyObject_SetAttrString(callbackInst, "current_bytes", o); else PyObject_SetAttrString(callbackInst, "currentBytes", o); Py_XDECREF(o); - o = Py_BuildValue("i", CurrentItems); + o = Py_BuildValue("k", CurrentItems); if(PyObject_HasAttrString(callbackInst, "current_items")) PyObject_SetAttrString(callbackInst, "current_items", o); else PyObject_SetAttrString(callbackInst, "currentItems", o); Py_XDECREF(o); - o = Py_BuildValue("i", TotalItems); + o = Py_BuildValue("k", TotalItems); if(PyObject_HasAttrString(callbackInst, "total_items")) PyObject_SetAttrString(callbackInst, "total_items", o); else PyObject_SetAttrString(callbackInst, "totalItems", o); Py_XDECREF(o); - o = Py_BuildValue("f", TotalBytes); + o = Py_BuildValue("d", TotalBytes); if(PyObject_HasAttrString(callbackInst, "total_bytes")) PyObject_SetAttrString(callbackInst, "total_bytes", o); else -- cgit v1.2.3 From 20fadc70639593001e1a9174333331afa3b4982b Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 16 Jul 2009 15:18:15 +0200 Subject: python/progress.cc: Make PyOpProgress::Update() behave more like OpTextProgress. --- python/progress.cc | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index c33db502..753949af 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -60,6 +60,11 @@ bool PyCallbackObj::RunSimpleCallback(const char* method_name, // OpProgress interface void PyOpProgress::Update() { + // Build up the argument list... + if(!CheckChange(0.7)) + return; + + PyObject *o; o = Py_BuildValue("s", Op.c_str()); PyObject_SetAttrString(callbackInst, "op", o); @@ -77,21 +82,19 @@ void PyOpProgress::Update() PyObject_SetAttrString(callbackInst, "majorChange", o); Py_XDECREF(o); - - - // Build up the argument list... - if(CheckChange(0.05)) - { - if (PyObject_TypeCheck(callbackInst, &PyOpProgress_Type)) { - o = Py_BuildValue("f", Percent); - PyObject_SetAttrString(callbackInst, "percent", o); - RunSimpleCallback("update"); - Py_XDECREF(o); - } else { - PyObject *arglist = Py_BuildValue("(f)", Percent); - RunSimpleCallback("update", arglist); - } + + + + if (PyObject_TypeCheck(callbackInst, &PyOpProgress_Type)) { + o = Py_BuildValue("f", Percent); + PyObject_SetAttrString(callbackInst, "percent", o); + RunSimpleCallback("update"); + Py_XDECREF(o); } + else { + PyObject *arglist = Py_BuildValue("(f)", Percent); + RunSimpleCallback("update", arglist); + } }; void PyOpProgress::Done() @@ -185,7 +188,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) UpdateStatus(Itm, DLIgnored); } - + if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); else @@ -215,7 +218,7 @@ void PyFetchProgress::Start() PyObject_SetAttrString(callbackInst, "currentItems", o); Py_XDECREF(o); o = Py_BuildValue("k", 0); - + PyObject_SetAttrString(callbackInst, "totalItems", o); Py_XDECREF(o); o = Py_BuildValue("d", 0.0f); -- cgit v1.2.3 From ef106396218522fce5856744741c7b3f87261cc2 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 16 Jul 2009 16:03:02 +0200 Subject: python/acquire.cc: Introduce PyAcquireWorker_Type, make PyAcquireItemDesc_Type contain a pointer. --- python/acquire.cc | 108 +++++++++++++++++++++++++++++++++++++++++++----- python/apt_pkgmodule.cc | 13 +++--- python/apt_pkgmodule.h | 1 + python/progress.cc | 8 ++-- python/python-apt.h | 4 +- 5 files changed, 112 insertions(+), 22 deletions(-) (limited to 'python/progress.cc') diff --git a/python/acquire.cc b/python/acquire.cc index 6c4baf9c..25b10b06 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -11,6 +11,7 @@ #include "progress.h" #include +#include typedef CppPyObject PyAcquireItemObject; @@ -20,21 +21,93 @@ struct PyAcquireObject : public CppPyObject { vector items; }; + +static PyObject *acquireworker_get_current_item(PyObject *self, void *closure) +{ + return PyAcquireItemDesc_FromCpp((GetCpp(self)->CurrentItem),false,self); +} + +static PyObject *acquireworker_get_status(PyObject *self, void *closure) +{ + return CppPyString(GetCpp(self)->Status); +} + +static PyObject *acquireworker_get_current_size(PyObject *self, void *closure) +{ + return Py_BuildValue("k",GetCpp(self)->CurrentSize); +} + +static PyObject *acquireworker_get_total_size(PyObject *self, void *closure) +{ + return Py_BuildValue("k",GetCpp(self)->TotalSize); +} + +static PyObject *acquireworker_get_resumepoint(PyObject *self, void *closure) +{ + return Py_BuildValue("k",GetCpp(self)->ResumePoint); +} + +static PyGetSetDef acquireworker_getset[] = { + {"current_item",acquireworker_get_current_item}, + {"status",acquireworker_get_status}, + {"current_size",acquireworker_get_current_size}, + {"total_size",acquireworker_get_total_size}, + {"resumepoint",acquireworker_get_resumepoint}, + {NULL} +}; + + +PyTypeObject PyAcquireWorker_Type = +{ + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.AcquireWorker", // tp_name + sizeof(CppOwnedPyObject),// tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT| // tp_flags + Py_TPFLAGS_HAVE_GC, + 0, // tp_doc + CppOwnedTraverse, // tp_traverse + CppOwnedClear, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + acquireworker_getset, // tp_getset +}; + static PyObject *acquireitemdesc_get_uri(PyObject *self, void *closure) { - return CppPyString(GetCpp(self).URI); + return CppPyString(GetCpp(self)->URI); } static PyObject *acquireitemdesc_get_description(PyObject *self, void *closure) { - return CppPyString(GetCpp(self).Description); + return CppPyString(GetCpp(self)->Description); } static PyObject *acquireitemdesc_get_shortdesc(PyObject *self, void *closure) { - return CppPyString(GetCpp(self).ShortDesc); + return CppPyString(GetCpp(self)->ShortDesc); } static PyObject *acquireitemdesc_get_owner(PyObject *self, void *closure) { - return GetOwner(self); + return GetOwner(self); } static PyGetSetDef acquireitemdesc_getset[] = { @@ -52,10 +125,10 @@ PyTypeObject PyAcquireItemDesc_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.AcquireItemDesc", // tp_name - sizeof(CppOwnedPyObject),// tp_basicsize + sizeof(CppOwnedPyObject),// tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + CppOwnedDealloc, // tp_dealloc 0, // tp_print 0, // tp_getattr 0, // tp_setattr @@ -73,8 +146,8 @@ PyTypeObject PyAcquireItemDesc_Type = (Py_TPFLAGS_DEFAULT | // tp_flags Py_TPFLAGS_HAVE_GC), acquireitemdesc_doc, // tp_doc - CppOwnedTraverse,// tp_traverse - CppOwnedClear, // tp_clear + CppOwnedTraverse,// tp_traverse + CppOwnedClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -184,13 +257,13 @@ static void AcquireItemDealloc(PyObject *self) { pkgAcquire::Item *file = GetCpp(self); PyAcquireObject *owner = (PyAcquireObject *)GetOwner(self); - // Simply deallocate the object if we have no owner. + // Simply deallocate the object if we have no owner. if (owner == NULL) { CppOwnedDeallocPtr(self); return; } vector &items = owner->items; - bool DeletePtr = !((CppPyObject *)self)->NoDelete; + bool DeletePtr = !((CppPyObject *)self)->NoDelete; // Cleanup the other objects as well... for (vector::iterator I = items.begin(); @@ -307,6 +380,20 @@ static PyObject *PkgAcquireGetPartialPresent(PyObject *Self,void*) { return Py_BuildValue("d", fetcher->PartialPresent()); } #undef fetcher + +static PyObject *PkgAcquireGetWorkers(PyObject *self, void *closure) +{ + PyObject *List = PyList_New(0); + pkgAcquire *Owner = GetCpp(self); + CppOwnedPyObject *PyWorker = NULL; + for(pkgAcquire::Worker *Worker = Owner->WorkersBegin(); + Worker != 0; Worker = Owner->WorkerStep(Worker)) { + PyWorker = CppOwnedPyObject_NEW(self,&PyAcquireWorker_Type, Worker); + PyWorker->NoDelete = true; + PyList_Append(List, PyWorker); + } + return List; +} static PyObject *PkgAcquireGetItems(PyObject *Self,void*) { pkgAcquire *fetcher = GetCpp(Self); @@ -337,6 +424,7 @@ static PyObject *PkgAcquireGetResultCancelled(PyObject *Self,void*) { static PyGetSetDef PkgAcquireGetSet[] = { {"fetch_needed",PkgAcquireGetFetchNeeded}, {"items",PkgAcquireGetItems}, + {"workers",PkgAcquireGetWorkers}, {"partial_present",PkgAcquireGetPartialPresent}, {"result_cancelled",PkgAcquireGetResultCancelled}, {"result_continue",PkgAcquireGetResultContinue}, diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 5d7b6c47..a7392f58 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -450,27 +450,27 @@ static PyMethodDef methods[] = {"newConfiguration",newConfiguration,METH_VARARGS,doc_newConfiguration}, {"InitConfig",InitConfig,METH_VARARGS,doc_InitConfig}, {"InitSystem",InitSystem,METH_VARARGS,doc_InitSystem}, - + {"ParseSection",ParseSection,METH_VARARGS,doc_ParseSection}, {"ParseTagFile",ParseTagFile,METH_VARARGS,doc_ParseTagFile}, {"RewriteSection",RewriteSection,METH_VARARGS,doc_RewriteSection}, - + {"GetLock",GetLock,METH_VARARGS,doc_GetLock}, {"PkgSystemLock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock}, {"PkgSystemUnLock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock}, - + {"ReadConfigFile",LoadConfig,METH_VARARGS,doc_LoadConfig}, {"ReadConfigDir",LoadConfigDir,METH_VARARGS,doc_LoadConfigDir}, {"ReadConfigFileISC",LoadConfigISC,METH_VARARGS,doc_LoadConfig}, {"ParseCommandLine",ParseCommandLine,METH_VARARGS,doc_ParseCommandLine}, - + {"VersionCompare",VersionCompare,METH_VARARGS,doc_VersionCompare}, {"CheckDep",CheckDep,METH_VARARGS,doc_CheckDep}, {"UpstreamVersion",UpstreamVersion,METH_VARARGS,doc_UpstreamVersion}, {"ParseDepends",ParseDepends_old,METH_VARARGS,doc_ParseDepends}, {"ParseSrcDepends",ParseSrcDepends_old,METH_VARARGS,doc_ParseDepends}, - + {"CheckDomainList",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"}, {"QuoteString",StrQuoteString,METH_VARARGS,"QuoteString(String,String) -> String"}, {"DeQuoteString",StrDeQuote,METH_VARARGS,"DeQuoteString(String) -> String"}, @@ -481,7 +481,7 @@ static PyMethodDef methods[] = {"StringToBool",StrStringToBool,METH_VARARGS,"StringToBool(String) -> int"}, {"TimeRFC1123",StrTimeRFC1123,METH_VARARGS,"TimeRFC1123(int) -> String"}, {"StrToTime",StrStrToTime,METH_VARARGS,"StrToTime(String) -> Int"}, - + {"GetCache",TmpGetCache,METH_VARARGS,"GetCache() -> PkgCache"}, {"GetDepCache",GetDepCache,METH_VARARGS,"GetDepCache(Cache) -> DepCache"}, {"GetPkgRecords",GetPkgRecords,METH_VARARGS,"GetPkgRecords(Cache) -> PkgRecords"}, @@ -589,6 +589,7 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"Acquire",&PyAcquire_Type); ADDTYPE(Module,"AcquireFile",&PyAcquireFile_Type); ADDTYPE(Module,"AcquireItem",&PyAcquireItem_Type); // NO __new__() + ADDTYPE(Module,"AcquireWorker",&PyAcquireWorker_Type); // NO __new__() /* ============================ cache.cc ============================ */ ADDTYPE(Module,"Cache",&PyCache_Type); ADDTYPE(Module,"Dependency",&PyDependency_Type); // NO __new__() diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 835cfd9b..ad1fe9fe 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -115,6 +115,7 @@ extern PyTypeObject PyHashes_Type; extern PyTypeObject PyOpProgress_Type; extern PyTypeObject PyAcquireProgress_Type; extern PyTypeObject PyAcquireItemDesc_Type; +extern PyTypeObject PyAcquireWorker_Type; #include "python-apt.h" #endif diff --git a/python/progress.cc b/python/progress.cc index 753949af..18e038dd 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -156,7 +156,7 @@ void PyFetchProgress::UpdateStatus(pkgAcquire::ItemDesc &Itm, int status) void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) { if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLHit); } @@ -164,7 +164,7 @@ void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) { if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("fetch", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + RunSimpleCallback("fetch", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLQueued); } @@ -172,7 +172,7 @@ void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) { if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("done", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + RunSimpleCallback("done", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLDone); } @@ -190,7 +190,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(Itm))); + RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLFailed); } diff --git a/python/python-apt.h b/python/python-apt.h index fa589c55..d2693920 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -184,7 +184,7 @@ static int import_apt_pkg(void) { # define PyAcquire_ToCpp GetCpp # define PyAcquireFile_ToCpp GetCpp # define PyAcquireItem_ToCpp GetCpp -# define PyAcquireItemDesc_ToCpp GetCpp +# define PyAcquireItemDesc_ToCpp GetCpp # define PyActionGroup_ToCpp GetCpp # define PyCache_ToCpp GetCpp # define PyCacheFile_ToCpp GetCpp @@ -234,7 +234,7 @@ inline PyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, # define PyAcquire_FromCpp(...) FromCpp(&PyAcquire_Type, ##__VA_ARGS__) # define PyAcquireFile_FromCpp(...) FromCppOwned(&PyAcquireFile_Type, ##__VA_ARGS__) # define PyAcquireItem_FromCpp(...) FromCppOwned(&PyAcquireItem_Type,##__VA_ARGS__) -# define PyAcquireItemDesc_FromCpp(...) FromCppOwned(&PyAcquireItemDesc_Type,##__VA_ARGS__) +# define PyAcquireItemDesc_FromCpp(...) FromCppOwned(&PyAcquireItemDesc_Type,##__VA_ARGS__) # define PyActionGroup_FromCpp(...) FromCppOwned(&PyActionGroup_Type,##__VA_ARGS__) # define PyCache_FromCpp(...) FromCppOwned(&PyCache_Type,##__VA_ARGS__) # define PyCacheFile_FromCpp(...) FromCpp(&PyCacheFile_Type,##__VA_ARGS__) -- cgit v1.2.3 From 7e5b2dee624fb0fb7a6536cfdc74d30eeca8ffbe Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 16 Jul 2009 19:27:46 +0200 Subject: python/acquire.cc, python/progress.cc: More fixes. --- python/acquire.cc | 43 ++++++++++++++++++++++++++++++++++++++----- python/progress.cc | 5 +++++ 2 files changed, 43 insertions(+), 5 deletions(-) (limited to 'python/progress.cc') diff --git a/python/acquire.cc b/python/acquire.cc index e2fd3181..05429d1b 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -116,16 +116,27 @@ static PyObject *acquireitemdesc_get_shortdesc(PyObject *self, void *closure) { return CppPyString(GetCpp(self)->ShortDesc); } -static PyObject *acquireitemdesc_get_owner(PyObject *self, void *closure) +static PyObject *acquireitemdesc_get_owner(CppOwnedPyObject *self, void *closure) { - return GetOwner(self); + + + if (self->Owner != NULL) { + Py_INCREF(self->Owner); + return self->Owner; + } + else if (self->Object && self->Object->Owner != NULL) { + self->Owner = PyAcquireItem_FromCpp(self->Object->Owner); + Py_INCREF(self->Owner); + return self->Owner; + } + Py_RETURN_NONE; } static PyGetSetDef acquireitemdesc_getset[] = { {"uri",acquireitemdesc_get_uri,0,"The URI from which to download this item."}, {"description",acquireitemdesc_get_description}, {"shortdesc",acquireitemdesc_get_shortdesc}, - {"owner",acquireitemdesc_get_owner}, + {"owner",(getter)acquireitemdesc_get_owner}, {NULL} }; @@ -198,7 +209,7 @@ MkGet(AcquireItemGetDescURI,Safe_FromString(Itm->DescURI().c_str())); MkGet(AcquireItemGetDestFile,Safe_FromString(Itm->DestFile.c_str())); MkGet(AcquireItemGetErrorText,Safe_FromString(Itm->ErrorText.c_str())); MkGet(AcquireItemGetFileSize,Py_BuildValue("i",Itm->FileSize)); -MkGet(AcquireItemGetID,Py_BuildValue("i",Itm)); +MkGet(AcquireItemGetID,Py_BuildValue("k",Itm->ID)); MkGet(AcquireItemGetMode,Py_BuildValue("s",Itm->Mode)); MkGet(AcquireItemGetIsTrusted,Py_BuildValue("i",Itm->IsTrusted())); MkGet(AcquireItemGetLocal,Py_BuildValue("i",Itm->Local)); @@ -212,13 +223,35 @@ MkGet(AcquireItemGetStatError,Py_BuildValue("i", pkgAcquire::Item::StatError)); MkGet(AcquireItemGetStatAuthError,Py_BuildValue("i", pkgAcquire::Item::StatAuthError)); #undef MkGet +static int AcquireItemSetID(PyObject *self, PyObject *value, void *closure) +{ + pkgAcquire::Item *Itm = acquireitem_tocpp(self); + if (Itm == 0) + return -1; + if (PyLong_Check(value)) { + Itm->ID = PyLong_AsLong(value); + } + else if (PyInt_Check(value)) { + Itm->ID = PyInt_AsLong(value); + } + else { + PyErr_SetString(PyExc_TypeError, "value must be integer."); + return -1; + } + + + + return 0; +} + + static PyGetSetDef AcquireItemGetSet[] = { {"complete",AcquireItemGetComplete}, {"desc_uri",AcquireItemGetDescURI}, {"destfile",AcquireItemGetDestFile}, {"error_text",AcquireItemGetErrorText}, {"filesize",AcquireItemGetFileSize}, - {"id",AcquireItemGetID}, + {"id",AcquireItemGetID,AcquireItemSetID}, {"mode",AcquireItemGetMode}, {"is_trusted",AcquireItemGetIsTrusted}, {"local",AcquireItemGetLocal}, diff --git a/python/progress.cc b/python/progress.cc index 18e038dd..1f17afdf 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -247,6 +247,11 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) // set stats PyObject *o; + + + o = Py_BuildValue("d", FetchedBytes); + PyObject_SetAttrString(callbackInst, "fetched_bytes", o); + Py_DECREF(o); o = Py_BuildValue("d", CurrentCPS); if(PyObject_HasAttrString(callbackInst, "current_cps")) PyObject_SetAttrString(callbackInst, "current_cps", o); -- cgit v1.2.3 From 0153cede3726849504b04dabdebc8460c1c0fc91 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 16 Jul 2009 19:36:58 +0200 Subject: python/progress.h: Add Py{Acquire,Op}ProgressObject. --- python/acquireprogress.cc | 12 +------ python/opprogress.cc | 9 ++--- python/progress.cc | 85 ++++++++++++++++++++++++++--------------------- python/progress.h | 20 +++++++++++ 4 files changed, 71 insertions(+), 55 deletions(-) (limited to 'python/progress.cc') diff --git a/python/acquireprogress.cc b/python/acquireprogress.cc index eb02d018..c7db8921 100644 --- a/python/acquireprogress.cc +++ b/python/acquireprogress.cc @@ -19,20 +19,10 @@ */ #include "apt_pkgmodule.h" +#include "progress.h" #include #include -typedef struct { - PyObject_HEAD - double last_bytes; - double current_cps; - double current_bytes; - double total_bytes; - double fetched_bytes; - unsigned long elapsed_time; - unsigned long total_items; - unsigned long current_items; -} PyAcquireProgressObject; // DUMMY IMPLEMENTATIONS. diff --git a/python/opprogress.cc b/python/opprogress.cc index ba9acd14..d3738904 100644 --- a/python/opprogress.cc +++ b/python/opprogress.cc @@ -19,16 +19,11 @@ */ #include "generic.h" +#include "progress.h" #include #include -typedef struct { - PyObject_HEAD - PyObject *op; - PyObject *subop; - int major_change; - float percent; -} PyOpProgressObject; + static PyObject *opprogress_update(PyObject *Self, PyObject *args) { diff --git a/python/progress.cc b/python/progress.cc index 1f17afdf..6f226ef8 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -245,43 +245,54 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) if(callbackInst == 0) return false; - // set stats - PyObject *o; - - - o = Py_BuildValue("d", FetchedBytes); - PyObject_SetAttrString(callbackInst, "fetched_bytes", o); - Py_DECREF(o); - o = Py_BuildValue("d", CurrentCPS); - if(PyObject_HasAttrString(callbackInst, "current_cps")) - PyObject_SetAttrString(callbackInst, "current_cps", o); - else - PyObject_SetAttrString(callbackInst, "currentCPS", o); - Py_XDECREF(o); - o = Py_BuildValue("d", CurrentBytes); - if(PyObject_HasAttrString(callbackInst, "current_bytes")) - PyObject_SetAttrString(callbackInst, "current_bytes", o); - else - PyObject_SetAttrString(callbackInst, "currentBytes", o); - Py_XDECREF(o); - o = Py_BuildValue("k", CurrentItems); - if(PyObject_HasAttrString(callbackInst, "current_items")) - PyObject_SetAttrString(callbackInst, "current_items", o); - else - PyObject_SetAttrString(callbackInst, "currentItems", o); - Py_XDECREF(o); - o = Py_BuildValue("k", TotalItems); - if(PyObject_HasAttrString(callbackInst, "total_items")) - PyObject_SetAttrString(callbackInst, "total_items", o); - else - PyObject_SetAttrString(callbackInst, "totalItems", o); - Py_XDECREF(o); - o = Py_BuildValue("d", TotalBytes); - if(PyObject_HasAttrString(callbackInst, "total_bytes")) - PyObject_SetAttrString(callbackInst, "total_bytes", o); - else - PyObject_SetAttrString(callbackInst, "totalBytes", o); - Py_XDECREF(o); + if (PyObject_TypeCheck(callbackInst, &PyAcquireProgress_Type)) { + PyAcquireProgressObject *obj = (PyAcquireProgressObject *)callbackInst; + obj->last_bytes = LastBytes; + obj->current_cps = CurrentCPS; + obj->current_bytes = CurrentBytes; + obj->total_bytes = TotalBytes; + obj->fetched_bytes = FetchedBytes; + obj->elapsed_time = ElapsedTime; + obj->total_items = TotalItems; + obj->current_items = CurrentItems; + } + else { + // set stats + PyObject *o; + o = Py_BuildValue("d", FetchedBytes); + PyObject_SetAttrString(callbackInst, "fetched_bytes", o); + Py_DECREF(o); + o = Py_BuildValue("d", CurrentCPS); + if(PyObject_HasAttrString(callbackInst, "current_cps")) + PyObject_SetAttrString(callbackInst, "current_cps", o); + else + PyObject_SetAttrString(callbackInst, "currentCPS", o); + Py_XDECREF(o); + o = Py_BuildValue("d", CurrentBytes); + if(PyObject_HasAttrString(callbackInst, "current_bytes")) + PyObject_SetAttrString(callbackInst, "current_bytes", o); + else + PyObject_SetAttrString(callbackInst, "currentBytes", o); + Py_XDECREF(o); + o = Py_BuildValue("k", CurrentItems); + if(PyObject_HasAttrString(callbackInst, "current_items")) + PyObject_SetAttrString(callbackInst, "current_items", o); + else + PyObject_SetAttrString(callbackInst, "currentItems", o); + Py_XDECREF(o); + o = Py_BuildValue("k", TotalItems); + if(PyObject_HasAttrString(callbackInst, "total_items")) + PyObject_SetAttrString(callbackInst, "total_items", o); + else + PyObject_SetAttrString(callbackInst, "totalItems", o); + Py_XDECREF(o); + o = Py_BuildValue("d", TotalBytes); + if(PyObject_HasAttrString(callbackInst, "total_bytes")) + PyObject_SetAttrString(callbackInst, "total_bytes", o); + else + PyObject_SetAttrString(callbackInst, "totalBytes", o); + Py_XDECREF(o); + } if (PyObject_TypeCheck(callbackInst, &PyAcquireProgress_Type)) { PyObject *result1; diff --git a/python/progress.h b/python/progress.h index 5ac67b1c..50fd7f20 100644 --- a/python/progress.h +++ b/python/progress.h @@ -15,6 +15,26 @@ #include #include +typedef struct { + PyObject_HEAD + PyObject *op; + PyObject *subop; + int major_change; + float percent; +} PyOpProgressObject; + +typedef struct { + PyObject_HEAD + double last_bytes; + double current_cps; + double current_bytes; + double total_bytes; + double fetched_bytes; + unsigned long elapsed_time; + unsigned long total_items; + unsigned long current_items; +} PyAcquireProgressObject; + class PyCallbackObj { protected: -- cgit v1.2.3 From 007fd304fe99b0d97b8039a8c1a83ac749e876f9 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 16 Jul 2009 20:00:27 +0200 Subject: python/progress.cc: Call fail() on AcquireProgress objects. --- python/progress.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index 6f226ef8..450b7654 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -179,6 +179,11 @@ void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) { + if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) { + RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + return; + } + // Ignore certain kinds of transient failures (bad code) if (Itm.Owner->Status == pkgAcquire::Item::StatIdle) return; -- cgit v1.2.3 From c7d7fbb650c8ff7c0e52c95723e1e65e295d55cf Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 16 Jul 2009 21:39:31 +0200 Subject: python/progress.cc: Set members directly, without using Python. --- python/opprogress.cc | 7 ++++++- python/progress.cc | 48 +++++++++++++++++++++++++----------------------- python/progress.h | 5 +++++ 3 files changed, 36 insertions(+), 24 deletions(-) (limited to 'python/progress.cc') diff --git a/python/opprogress.cc b/python/opprogress.cc index d3738904..2ee6a03e 100644 --- a/python/opprogress.cc +++ b/python/opprogress.cc @@ -88,8 +88,13 @@ static PyMethodDef opprogress_methods[] = { {NULL}, }; +#ifndef T_BOOL +# define _T_BOOL T_INT +#else +# define _T_BOOL T_BOOL +#endif static PyMemberDef opprogress_members[] = { - {"major_change", T_INT, offsetof(PyOpProgressObject, major_change), 0, + {"major_change", _T_BOOL, offsetof(PyOpProgressObject, major_change), 0, "Boolean value indicating whether the change is a major change."}, {"percent", T_FLOAT, offsetof(PyOpProgressObject, percent), 0, "Percentage of completion (float value)."}, diff --git a/python/progress.cc b/python/progress.cc index 450b7654..123a1805 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -65,33 +65,35 @@ void PyOpProgress::Update() return; - PyObject *o; - o = Py_BuildValue("s", Op.c_str()); - PyObject_SetAttrString(callbackInst, "op", o); - Py_XDECREF(o); - o = Py_BuildValue("s", SubOp.c_str()); - if(PyObject_HasAttrString(callbackInst, "sub_op")) - PyObject_SetAttrString(callbackInst, "sub_op", o); - else - PyObject_SetAttrString(callbackInst, "subOp", o); - Py_XDECREF(o); - o = Py_BuildValue("b", MajorChange); - if(PyObject_HasAttrString(callbackInst, "major_change")) - PyObject_SetAttrString(callbackInst, "major_change", o); - else - PyObject_SetAttrString(callbackInst, "majorChange", o); - Py_XDECREF(o); - - - - if (PyObject_TypeCheck(callbackInst, &PyOpProgress_Type)) { - o = Py_BuildValue("f", Percent); - PyObject_SetAttrString(callbackInst, "percent", o); + PyOpProgressObject *obj = (PyOpProgressObject *)callbackInst; + obj->op = CppPyString(Op); + obj->subop = CppPyString(SubOp); +#ifdef T_BOOL + obj->major_change = (char)(MajorChange); +#else + obj->major_change = (int)(MajorChange); +#endif + obj->percent = Percent; RunSimpleCallback("update"); - Py_XDECREF(o); } else { + PyObject *o; + o = Py_BuildValue("s", Op.c_str()); + PyObject_SetAttrString(callbackInst, "op", o); + Py_XDECREF(o); + o = Py_BuildValue("s", SubOp.c_str()); + if(PyObject_HasAttrString(callbackInst, "sub_op")) + PyObject_SetAttrString(callbackInst, "sub_op", o); + else + PyObject_SetAttrString(callbackInst, "subOp", o); + Py_XDECREF(o); + o = Py_BuildValue("b", MajorChange); + if(PyObject_HasAttrString(callbackInst, "major_change")) + PyObject_SetAttrString(callbackInst, "major_change", o); + else + PyObject_SetAttrString(callbackInst, "majorChange", o); + Py_XDECREF(o); PyObject *arglist = Py_BuildValue("(f)", Percent); RunSimpleCallback("update", arglist); } diff --git a/python/progress.h b/python/progress.h index 50fd7f20..e21a5c5a 100644 --- a/python/progress.h +++ b/python/progress.h @@ -15,11 +15,16 @@ #include #include + typedef struct { PyObject_HEAD PyObject *op; PyObject *subop; +#ifdef T_BOOL + char major_change; +#else int major_change; +#endif float percent; } PyOpProgressObject; -- cgit v1.2.3 From 5c219e07aea347f652cf7949dc74f37282a17144 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 19 Jul 2009 14:39:41 +0200 Subject: python/cdromprogress.cc: Add apt_pkg.CdromProgress. --- apt/progress/old.py | 22 ++-------- python/apt_pkgmodule.cc | 1 + python/apt_pkgmodule.h | 1 + python/cdrom.cc | 11 +++++ python/cdromprogress.cc | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ python/progress.cc | 12 ++++-- python/progress.h | 6 +++ 7 files changed, 137 insertions(+), 22 deletions(-) create mode 100644 python/cdromprogress.cc (limited to 'python/progress.cc') diff --git a/apt/progress/old.py b/apt/progress/old.py index d4ff5815..63fc5d2e 100644 --- a/apt/progress/old.py +++ b/apt/progress/old.py @@ -343,27 +343,13 @@ class InstallProgress(DumbInstallProgress): updateInterface = function_deprecated_by(update_interface) -class CdromProgress(object): +class CdromProgress(apt_pkg.CdromProgress): """Report the cdrom add progress. - Subclass this class to implement cdrom add progress reporting. + This class has been replaced by apt_pkg.CdromProgress. """ - - def __init__(self): - pass - - def update(self, text, step): - """Called periodically to update the user interface.""" - - def ask_cdrom_name(self): - """Called to ask for the name of the cdrom.""" - - def change_cdrom(self): - """Called to ask for the cdrom to be changed.""" - - if apt_pkg._COMPAT_0_7: - askCdromName = function_deprecated_by(ask_cdrom_name) - changeCdrom = function_deprecated_by(change_cdrom) + askCdromName = function_deprecated_by(apt_pkg.CdromProgress.ask_cdrom_name) + changeCdrom = function_deprecated_by(apt_pkg.CdromProgress.change_cdrom) class DpkgInstallProgress(InstallProgress): diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index d6b8e3d1..b6ae709e 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -651,6 +651,7 @@ extern "C" void initapt_pkg() ADDTYPE(Module,"OpProgress",&PyOpProgress_Type); ADDTYPE(Module,"AcquireProgress",&PyAcquireProgress_Type); ADDTYPE(Module,"AcquireItemDesc",&PyAcquireItemDesc_Type); + ADDTYPE(Module,"CdromProgress",&PyCdromProgress_Type); // Tag file constants PyModule_AddObject(Module,"REWRITE_PACKAGE_ORDER", CharCharToList(TFRewritePackageOrder)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index ad1fe9fe..1277ab60 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -114,6 +114,7 @@ extern PyTypeObject PyPolicy_Type; extern PyTypeObject PyHashes_Type; extern PyTypeObject PyOpProgress_Type; extern PyTypeObject PyAcquireProgress_Type; +extern PyTypeObject PyCdromProgress_Type; extern PyTypeObject PyAcquireItemDesc_Type; extern PyTypeObject PyAcquireWorker_Type; #include "python-apt.h" diff --git a/python/cdrom.cc b/python/cdrom.cc index 50d1b4b1..6ee3becd 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -34,9 +34,20 @@ static PyObject *PkgCdromIdent(PyObject *Self,PyObject *Args) pkgCdrom &Cdrom = GetCpp(Self); PyObject *pyCdromProgressInst = 0; +#ifdef COMPAT_0_7 if (PyArg_ParseTuple(Args, "O", &pyCdromProgressInst) == 0) { +#else + if (PyArg_ParseTuple(Args, "O!", &PyCdromProgress_Type, + &pyCdromProgressInst) == 0) { +#endif return 0; } +#ifdef COMPAT_0_7 + if (!PyObject_TypeCheck(pyCdromProgressInst, &PyCdromProgress_Type)) { + PyErr_WarnEx(PyExc_DeprecationWarning, "Argument should be a subclass of" + " apt_pkg.CdromProgress.", 1); + } +#endif PyCdromProgress progress; progress.setCallbackInst(pyCdromProgressInst); diff --git a/python/cdromprogress.cc b/python/cdromprogress.cc new file mode 100644 index 00000000..09c76a2a --- /dev/null +++ b/python/cdromprogress.cc @@ -0,0 +1,106 @@ +/* cdromprogress.cc - Base class for CdromProgress classes. + * + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +#include "apt_pkgmodule.h" +#include "progress.h" +#include +#include + +// Takes two arguments (string, int) +static PyObject *cdromprogress_update(PyObject *self, PyObject *args) +{ + Py_RETURN_NONE; +} + +// Takes no arguments +static PyObject *cdromprogress_change_cdrom(PyObject *self, PyObject *args) +{ + Py_RETURN_FALSE; +} + +// Takes a single PyObject argument as *arg +static PyObject *cdromprogress_ask_cdrom_name(PyObject *self, PyObject *arg) +{ + Py_RETURN_FALSE; +} + +static PyMethodDef cdromprogress_methods[] = { + {"update",cdromprogress_update,METH_VARARGS, + "update(text: str, current: int)\n\nCalled regularly."}, + {"change_cdrom",cdromprogress_change_cdrom,METH_NOARGS, + "change_cdrom() -> bool\n\nAsk for the CD-ROM to be changed.\n" + "Return False if the user requested to cancel the action (default)."}, + {"ask_cdrom_name",cdromprogress_ask_cdrom_name,METH_O, + "ask_cdrom_name(name: str) -> bool\n\nAsk for the name of the CD-ROM.\n" + "Return False if the user requested to cancel the action (default)."}, + {NULL} +}; + +static PyMemberDef cdromprogress_members[] = { + {"total_steps", T_INT, offsetof(PyCdromProgressObject,total_steps), 0, + "The number of total steps to be taken."}, + {NULL} +}; + +static char *cdromprogress_doc = "CdromProgress()\n\n" + "Base class for reporting the progress of adding a cdrom. Can be used\n" + "with apt_pkg.Cdrom to produce an utility like apt-cdrom."; + +PyTypeObject PyCdromProgress_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.CdromProgress", // tp_name + sizeof(PyCdromProgressObject), // tp_basicsize + 0, // tp_itemsize + // Methods + 0, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE, + cdromprogress_doc, // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + cdromprogress_methods, // tp_methods + cdromprogress_members, // tp_members + 0, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + PyType_GenericNew, // tp_new +}; diff --git a/python/progress.cc b/python/progress.cc index 123a1805..b19ab0c7 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -518,10 +518,14 @@ 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); - Py_XDECREF(o); + if (PyObject_TypeCheck(callbackInst, &PyCdromProgress_Type)) { + ((PyCdromProgressObject *)callbackInst)->total_steps = totalSteps; + } + else { + PyObject *o = Py_BuildValue("i", totalSteps); + PyObject_SetAttrString(callbackInst, "totalSteps", o); + Py_XDECREF(o); + } RunSimpleCallback("update", arglist); } diff --git a/python/progress.h b/python/progress.h index e21a5c5a..88bd3552 100644 --- a/python/progress.h +++ b/python/progress.h @@ -28,6 +28,12 @@ typedef struct { float percent; } PyOpProgressObject; + +typedef struct { + PyObject_HEAD + int total_steps; +} PyCdromProgressObject; + typedef struct { PyObject_HEAD double last_bytes; -- cgit v1.2.3 From 48cc0bcaabe824f49987ed3236b9421c583226dd Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 19 Jul 2009 15:40:40 +0200 Subject: python/progress.cc: CdromProgress.ask_cdrom_name() shall return None on failure. --- python/cdromprogress.cc | 6 +++--- python/progress.cc | 32 ++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 15 deletions(-) (limited to 'python/progress.cc') diff --git a/python/cdromprogress.cc b/python/cdromprogress.cc index 09c76a2a..440b5ce6 100644 --- a/python/cdromprogress.cc +++ b/python/cdromprogress.cc @@ -37,7 +37,7 @@ static PyObject *cdromprogress_change_cdrom(PyObject *self, PyObject *args) // Takes a single PyObject argument as *arg static PyObject *cdromprogress_ask_cdrom_name(PyObject *self, PyObject *arg) { - Py_RETURN_FALSE; + Py_RETURN_NONE; } static PyMethodDef cdromprogress_methods[] = { @@ -47,8 +47,8 @@ static PyMethodDef cdromprogress_methods[] = { "change_cdrom() -> bool\n\nAsk for the CD-ROM to be changed.\n" "Return False if the user requested to cancel the action (default)."}, {"ask_cdrom_name",cdromprogress_ask_cdrom_name,METH_O, - "ask_cdrom_name(name: str) -> bool\n\nAsk for the name of the CD-ROM.\n" - "Return False if the user requested to cancel the action (default)."}, + "ask_cdrom_name() -> str\n\nAsk for the name of the CD-ROM.\n" + "Return None if the user requested to cancel the action (default)."}, {NULL} }; diff --git a/python/progress.cc b/python/progress.cc index b19ab0c7..55ed13f9 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -548,20 +548,28 @@ bool PyCdromProgress::ChangeCdrom() bool PyCdromProgress::AskCdromName(string &Name) { PyObject *arglist = Py_BuildValue("()"); - PyObject *result; - - if (!RunSimpleCallback("ask_cdrom_name", arglist, &result)) - RunSimpleCallback("askCdromName", arglist, &result); - const char *new_name; bool res; - if(!PyArg_Parse(result, "(bs)", &res, &new_name)) - std::cerr << "AskCdromName: result could not be parsed" << std::endl; - - //std::cerr << "got: " << res << " " << "name: " << new_name << std::endl; + PyObject *result; - // set the new name - Name = string(new_name); + // New style: String on success, None on failure. + if (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; + 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; + return res; + } } -- cgit v1.2.3 From cbfbbf0728df4d9f7d52685549eb529041184d82 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 19 Jul 2009 16:37:43 +0200 Subject: python/progress.cc: Use PyObject_CallObject instead of PyEval_CallObject. --- python/progress.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index 55ed13f9..2feba503 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -35,7 +35,7 @@ bool PyCallbackObj::RunSimpleCallback(const char* method_name, Py_XDECREF(arglist); return false; } - PyObject *result = PyEval_CallObject(method, arglist); + PyObject *result = PyObject_CallObject(method, arglist); Py_XDECREF(arglist); @@ -44,7 +44,6 @@ bool PyCallbackObj::RunSimpleCallback(const char* method_name, std::cerr << "Error in function " << method_name << std::endl; PyErr_Print(); PyErr_Clear(); - return false; } if(res != NULL) @@ -435,7 +434,7 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) PyObject *method = PyObject_GetAttrString(callbackInst, "fork"); std::cerr << "custom fork found" << std::endl; PyObject *arglist = Py_BuildValue("()"); - PyObject *result = PyEval_CallObject(method, arglist); + PyObject *result = PyObject_CallObject(method, arglist); Py_DECREF(arglist); if (result == NULL) { std::cerr << "fork method invalid" << std::endl; @@ -484,7 +483,7 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) 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); + PyObject *result = PyObject_CallObject(method, arglist); Py_DECREF(arglist); if (result == NULL) { std::cerr << "waitChild method invalid" << std::endl; -- cgit v1.2.3 From 59ca8fafbe93d5aff7ac4baf54877dd1aa5fa036 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 21 Jul 2009 20:56:19 +0200 Subject: python/progress.cc: Fix problems with threads. --- python/progress.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index 3dd104ab..cc0c9ffc 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -138,11 +138,9 @@ bool PyFetchProgress::MediaChange(string Media, string Drive) void PyFetchProgress::UpdateStatus(pkgAcquire::ItemDesc &Itm, int status) { //std::cout << "UpdateStatus: " << Itm.URI << " " << status << std::endl; - // Added object file size and object partial size to // parameters that are passed to updateStatus. // -- Stephan - PyCbObj_END_ALLOW_THREADS PyObject *arglist = Py_BuildValue("(sssikk)", Itm.URI.c_str(), Itm.Description.c_str(), Itm.ShortDesc.c_str(), @@ -159,35 +157,41 @@ void PyFetchProgress::UpdateStatus(pkgAcquire::ItemDesc &Itm, int status) if(!RunSimpleCallback("update_status", arglist)) RunSimpleCallback("updateStatus", arglist); - PyCbObj_BEGIN_ALLOW_THREADS } void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) { + PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLHit); + PyCbObj_BEGIN_ALLOW_THREADS } void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) { + PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) RunSimpleCallback("fetch", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLQueued); + PyCbObj_BEGIN_ALLOW_THREADS } void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) { + PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) RunSimpleCallback("done", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLDone); + PyCbObj_BEGIN_ALLOW_THREADS } void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) { + PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) { RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); return; @@ -207,6 +211,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); else UpdateStatus(Itm, DLFailed); + PyCbObj_BEGIN_ALLOW_THREADS } void PyFetchProgress::Start() @@ -258,6 +263,7 @@ void PyFetchProgress::Stop() * PyCbObj_END_ALLOW_THREADS to our previous * PyCbObj_BEGIN_ALLOW_THREADS (Python requires this!). */ + PyCbObj_END_ALLOW_THREADS //std::cout << "Stop" << std::endl; pkgAcquireStatus::Stop(); @@ -328,9 +334,11 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) if (RunSimpleCallback("pulse", TUPLEIZE(PyAcquire_FromCpp(Owner)), &result1)) { if (result1 != NULL && PyArg_Parse(result1, "b", &res1) && res1 == false) { // the user returned a explicit false here, stop + PyCbObj_BEGIN_ALLOW_THREADS return false; } } + PyCbObj_BEGIN_ALLOW_THREADS return true; } -- cgit v1.2.3 From 1358664af2c27db4d7d62292680013e811f11750 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 21 Jul 2009 21:53:36 +0200 Subject: python/progress.cc: Introduce setattr to reduce code duplication. This way, we can replace stuff like PyObject *o = PyBuildValue("i", 0); PyObject_SetAttrString(callbackInst, "attribute", o); Py_DECREF(o) with setattr(callbackInst,"attribute","i",0); --- python/progress.cc | 135 +++++++++++++++++++++-------------------------------- python/progress.h | 3 +- 2 files changed, 55 insertions(+), 83 deletions(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index cc0c9ffc..305246b7 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -17,6 +17,24 @@ #include "generic.h" #include "apt_pkgmodule.h" + +/** + * Set an attribute on an object, after creating the value with + * Py_BuildValue(fmt, arg). Afterwards, decrease its refcount and return + * whether setting the attribute was successful. + */ +template +inline bool setattr(PyObject *object, const char *attr, const char *fmt, T arg) +{ + if (!object) + return false; + PyObject *value = Py_BuildValue(fmt, arg); + + int result = PyObject_SetAttrString(object, attr, value); + Py_DECREF(value); + return result != -1; +} + #define TUPLEIZE(op) Py_BuildValue("(O)", op) // generic bool PyCallbackObj::RunSimpleCallback(const char* method_name, @@ -81,22 +99,11 @@ void PyOpProgress::Update() RunSimpleCallback("update"); } else { - PyObject *o; - o = Py_BuildValue("s", Op.c_str()); - PyObject_SetAttrString(callbackInst, "op", o); - Py_XDECREF(o); - o = Py_BuildValue("s", SubOp.c_str()); - if(PyObject_HasAttrString(callbackInst, "sub_op")) - PyObject_SetAttrString(callbackInst, "sub_op", o); - else - PyObject_SetAttrString(callbackInst, "subOp", o); - Py_XDECREF(o); - o = Py_BuildValue("b", MajorChange); - if(PyObject_HasAttrString(callbackInst, "major_change")) - PyObject_SetAttrString(callbackInst, "major_change", o); - else - PyObject_SetAttrString(callbackInst, "majorChange", o); - Py_XDECREF(o); + setattr(callbackInst, "op", "s", Op.c_str()); + setattr(callbackInst, "subop", "s", SubOp.c_str()); + setattr(callbackInst, "subOp", "s", SubOp.c_str()); + setattr(callbackInst, "major_change", "b", MajorChange); + setattr(callbackInst, "majorChange", "b", MajorChange); PyObject *arglist = Py_BuildValue("(f)", Percent); RunSimpleCallback("update", arglist); } @@ -219,35 +226,16 @@ void PyFetchProgress::Start() //std::cout << "Start" << std::endl; pkgAcquireStatus::Start(); +#ifdef COMPAT_0_7 + if (!PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) { + setattr(callbackInst, "currentCPS", "d", 0); + setattr(callbackInst, "currentBytes", "d", 0); + setattr(callbackInst, "currentItems", "k", 0); + setattr(callbackInst, "totalItems", "k", 0); + setattr(callbackInst, "totalBytes", "d", 0); + } +#endif - if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - goto end; - - // These attributes should be initialized before the first callback (start) - // is invoked. - // -- Stephan - PyObject *o; - - o = Py_BuildValue("d", 0); - PyObject_SetAttrString(callbackInst, "currentCPS", o); - Py_XDECREF(o); - - o = Py_BuildValue("d", 0); - PyObject_SetAttrString(callbackInst, "currentBytes", o); - Py_XDECREF(o); - - o = Py_BuildValue("k", 0); - PyObject_SetAttrString(callbackInst, "currentItems", o); - Py_XDECREF(o); - o = Py_BuildValue("k", 0); - PyObject_SetAttrString(callbackInst, "totalItems", o); - Py_XDECREF(o); - - o = Py_BuildValue("d", 0); - PyObject_SetAttrString(callbackInst, "totalBytes", o); - Py_XDECREF(o); - -end: RunSimpleCallback("start"); /* After calling the start method we can safely allow * other Python threads to do their work for now. @@ -291,41 +279,22 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) obj->current_items = CurrentItems; } else { - // set stats - PyObject *o; - o = Py_BuildValue("d", FetchedBytes); - PyObject_SetAttrString(callbackInst, "fetched_bytes", o); - Py_DECREF(o); - o = Py_BuildValue("d", CurrentCPS); - if(PyObject_HasAttrString(callbackInst, "current_cps")) - PyObject_SetAttrString(callbackInst, "current_cps", o); - else - PyObject_SetAttrString(callbackInst, "currentCPS", o); - Py_XDECREF(o); - o = Py_BuildValue("d", CurrentBytes); - if(PyObject_HasAttrString(callbackInst, "current_bytes")) - PyObject_SetAttrString(callbackInst, "current_bytes", o); - else - PyObject_SetAttrString(callbackInst, "currentBytes", o); - Py_XDECREF(o); - o = Py_BuildValue("k", CurrentItems); - if(PyObject_HasAttrString(callbackInst, "current_items")) - PyObject_SetAttrString(callbackInst, "current_items", o); - else - PyObject_SetAttrString(callbackInst, "currentItems", o); - Py_XDECREF(o); - o = Py_BuildValue("k", TotalItems); - if(PyObject_HasAttrString(callbackInst, "total_items")) - PyObject_SetAttrString(callbackInst, "total_items", o); - else - PyObject_SetAttrString(callbackInst, "totalItems", o); - Py_XDECREF(o); - o = Py_BuildValue("d", TotalBytes); - if(PyObject_HasAttrString(callbackInst, "total_bytes")) - PyObject_SetAttrString(callbackInst, "total_bytes", o); - else - PyObject_SetAttrString(callbackInst, "totalBytes", o); - Py_XDECREF(o); + setattr(callbackInst, "last_bytes", "d", LastBytes); + setattr(callbackInst, "current_cps", "d", CurrentCPS); + setattr(callbackInst, "current_bytes", "d", CurrentBytes); + setattr(callbackInst, "total_bytes", "d", TotalBytes); + setattr(callbackInst, "fetched_bytes", "d", FetchedBytes); + setattr(callbackInst, "elapsed_time", "k", ElapsedTime); + setattr(callbackInst, "current_items", "k", CurrentItems); + setattr(callbackInst, "total_items", "k", TotalItems); +#ifdef COMPAT_0_7 + setattr(callbackInst, "currentCPS", "d", CurrentCPS); + setattr(callbackInst, "currentBytes", "d", CurrentBytes); + setattr(callbackInst, "totalBytes", "d", TotalBytes); + setattr(callbackInst, "fetchedBytes", "d", FetchedBytes); + setattr(callbackInst, "currentItems", "k", CurrentItems); + setattr(callbackInst, "totalItems", "k", TotalItems); +#endif } if (PyObject_TypeCheck(callbackInst, &PyAcquireProgress_Type)) { @@ -568,9 +537,11 @@ void PyCdromProgress::Update(string text, int current) ((PyCdromProgressObject *)callbackInst)->total_steps = totalSteps; } else { - PyObject *o = Py_BuildValue("i", totalSteps); - PyObject_SetAttrString(callbackInst, "totalSteps", o); - Py_XDECREF(o); + + setattr(callbackInst, "total_steps", "i", totalSteps); +#ifdef COMPAT_0_7 + setattr(callbackInst, "totalSteps", "i", totalSteps); +#endif } RunSimpleCallback("update", arglist); diff --git a/python/progress.h b/python/progress.h index 88c0a21b..e92933a7 100644 --- a/python/progress.h +++ b/python/progress.h @@ -18,7 +18,7 @@ /* PyCbObj_BEGIN_ALLOW_THREADS and PyCbObj_END_ALLOW_THREADS are sligthly * modified versions of Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS. * Instead of storing the thread state in a function-local variable these - * use a class attribute (with the same) name, allowing blocking and + * use a class attribute (with the same) name, allowing blocking and * unblocking from different class methods. * Py_BLOCK_THREADS and Py_UNBLOCK_THREADS do not define their own * local variable but use the one provided by PyCbObj_BEGIN_ALLOW_THREADS @@ -63,6 +63,7 @@ typedef struct { } PyAcquireProgressObject; + class PyCallbackObj { protected: PyObject *callbackInst; -- cgit v1.2.3 From 6ba42d2e31f161fc0ebe5405cf63b616c3e822b4 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 22 Jul 2009 17:21:08 +0200 Subject: python: First step of fixing acquire stuff. Basically, we only want to have on PyAcquireItem per pkgAcquire::Item, and one PyAcquireItemDesc per pkgAcquire::ItemDesc. Therefore, we store them so we can return them at a later time. --- python/acquire-item.cc | 357 ++++++++++++++++++++++++++++++++++++++++++++++++ python/acquire.cc | 356 ++++++----------------------------------------- python/apt_pkgmodule.cc | 32 +++++ python/progress.cc | 12 +- python/progress.h | 7 + setup.py | 3 +- 6 files changed, 451 insertions(+), 316 deletions(-) create mode 100644 python/acquire-item.cc (limited to 'python/progress.cc') diff --git a/python/acquire-item.cc b/python/acquire-item.cc new file mode 100644 index 00000000..cf0a628e --- /dev/null +++ b/python/acquire-item.cc @@ -0,0 +1,357 @@ +/* + * acquire-item.cc - Wrapper around pkgAcquire::Item and pkgAcqFile. + * + * Copyright 2004-2009 Canonical Ltd. + * Copyright 2009 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "generic.h" +#include "apt_pkgmodule.h" + +#include +#include + +using namespace std; + + + +struct PyAcquireItems { + CppOwnedPyObject *file; + CppOwnedPyObject *item; + CppOwnedPyObject *desc; +}; + +typedef map item_map; + +// Keep a vector to PyAcquireItemObject pointers, so we can set the Object +// pointers to NULL when deallocating the main object (mostly AcquireFile). +struct PyAcquireObject : public CppPyObject { + item_map items; +}; + +inline pkgAcquire::Item *acquireitem_tocpp(PyObject *self) +{ + pkgAcquire::Item *itm = GetCpp(self); + if (itm == 0) + PyErr_SetString(PyExc_ValueError, "Acquire() has been shut down or " + "the AcquireFile() object has been deallocated."); + return itm; +} + +static PyObject *acquireitem_get_complete(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? PyBool_FromLong(item->Complete) : 0; +} + +static PyObject *acquireitem_get_desc_uri(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? CppPyString(item->DescURI()) : 0; +} + +static PyObject *acquireitem_get_destfile(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? CppPyString(item->DestFile) : 0; +} + + +static PyObject *acquireitem_get_error_text(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? CppPyString(item->ErrorText) : 0; +} + +static PyObject *acquireitem_get_filesize(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? Py_BuildValue("i", item->FileSize) : 0; +} + +static PyObject *acquireitem_get_id(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? Py_BuildValue("k", item->ID) : 0; +} + +static PyObject *acquireitem_get_mode(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? Py_BuildValue("s", item->Mode) : 0; +} + +static PyObject *acquireitem_get_is_trusted(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? PyBool_FromLong(item->IsTrusted()) : 0; +} + +static PyObject *acquireitem_get_local(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? PyBool_FromLong(item->Local) : 0; +} + +static PyObject *acquireitem_get_status(PyObject *self, void *closure) +{ + pkgAcquire::Item *item = acquireitem_tocpp(self); + return item ? Py_BuildValue("i", item->Status) : 0; +} + +static int acquireitem_set_id(PyObject *self, PyObject *value, void *closure) +{ + pkgAcquire::Item *Itm = acquireitem_tocpp(self); + if (Itm == 0) + return -1; + if (PyLong_Check(value)) { + Itm->ID = PyLong_AsLong(value); + } + else if (PyInt_Check(value)) { + Itm->ID = PyInt_AsLong(value); + } + else { + PyErr_SetString(PyExc_TypeError, "value must be integer."); + return -1; + } + return 0; +} + + +static PyGetSetDef acquireitem_getset[] = { + {"complete",acquireitem_get_complete}, + {"desc_uri",acquireitem_get_desc_uri}, + {"destfile",acquireitem_get_destfile}, + {"error_text",acquireitem_get_error_text}, + {"filesize",acquireitem_get_filesize}, + {"id",acquireitem_get_id,acquireitem_set_id}, + {"mode",acquireitem_get_mode}, + {"is_trusted",acquireitem_get_is_trusted}, + {"local",acquireitem_get_local}, + {"status",acquireitem_get_status}, +#ifdef COMPAT_0_7 + {"Complete",acquireitem_get_complete}, + {"DescURI",acquireitem_get_desc_uri}, + {"DestFile",acquireitem_get_destfile}, + {"ErrorText",acquireitem_get_error_text}, + {"FileSize",acquireitem_get_filesize}, + {"ID",acquireitem_get_id}, + {"IsTrusted",acquireitem_get_is_trusted}, + {"Local",acquireitem_get_local}, + {"Status",acquireitem_get_status}, +#endif + {} +}; + +static PyObject *acquireitem_repr(PyObject *Self) +{ + pkgAcquire::Item *Itm = acquireitem_tocpp(Self); + if (Itm == 0) + return 0; + + return PyString_FromFormat("<%s object: " + "Status: %i Complete: %i Local: %i IsTrusted: %i " + "FileSize: %lu DestFile:'%s' " + "DescURI: '%s' ID:%lu ErrorText: '%s'>", + Self->ob_type->tp_name, + Itm->Status, Itm->Complete, Itm->Local, Itm->IsTrusted(), + Itm->FileSize, Itm->DestFile.c_str(), Itm->DescURI().c_str(), + Itm->ID,Itm->ErrorText.c_str()); +} + +static void acquireitem_dealloc(PyObject *self) +{ + // TODO: Unregister the object in the owner. + if (!((CppOwnedPyObject*)self)->NoDelete) { + pkgAcquire::Item *item = PyAcquireItem_ToCpp(self); + PyAcquireObject *Owner = (PyAcquireObject *)GetOwner(self); + + PyAcquireItems item_struct = Owner->items[item]; + + if (item_struct.file != 0 && item_struct.file != self) + item_struct.file->Object = 0; + if (item_struct.item != 0 && item_struct.item != self) { + item_struct.item->Object = 0; + Py_DECREF(item_struct.item); + } + if (item_struct.desc != 0) { + item_struct.desc->Object = 0; + Py_DECREF(item_struct.desc); + } + Owner->items.erase(item); + } + + CppOwnedDeallocPtr(self); +} + +PyTypeObject PyAcquireItem_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.AcquireItem", // tp_name + sizeof(CppOwnedPyObject), // tp_basicsize + 0, // tp_itemsize + // Methods + acquireitem_dealloc, // tp_dealloc + 0, // tp_print + 0, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + acquireitem_repr, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT, // tp_flags + "AcquireItem Object", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + acquireitem_getset, // tp_getset +}; + +static PyObject *acquirefile_new(PyTypeObject *type, 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", "short_descr", + "destdir", "destfile", NULL + }; + + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, + &PyAcquire_Type, &pyfetcher, &uri, &md5, + &size, &descr, &shortDescr, &destDir, &destFile) == 0) + return 0; + + pkgAcquire *fetcher = GetCpp(pyfetcher); + pkgAcqFile *af = new pkgAcqFile(fetcher, // owner + uri, // uri + md5, // md5 + size, // size + descr, // descr + shortDescr, + destDir, + destFile); // short-desc + CppOwnedPyObject *AcqFileObj = CppOwnedPyObject_NEW(pyfetcher, type); + AcqFileObj->Object = af; + + + ((PyAcquireObject *)pyfetcher)->items[af].file = AcqFileObj; + return AcqFileObj; +} + + +static char *acquirefile_doc = + "AcquireFile(owner, uri[, md5, size, descr, short_descr, destdir," + "destfile]) -> New AcquireFile() object\n\n" + "The parameter *owner* refers to an apt_pkg.Acquire() object. You can use\n" + "*destdir* OR *destfile* to specify the destination directory/file."; + +PyTypeObject PyAcquireFile_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) + "apt_pkg.AcquireFile", // tp_name + sizeof(CppOwnedPyObject),// tp_basicsize + 0, // tp_itemsize + // Methods + acquireitem_dealloc, // tp_dealloc + 0, // tp_print + 0, // 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 + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT | // tp_flags + Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_HAVE_GC, + acquirefile_doc, // tp_doc + CppOwnedTraverse, // tp_traverse + CppOwnedClear, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + 0, // tp_methods + 0, // tp_members + 0, // tp_getset + &PyAcquireItem_Type, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + acquirefile_new, // tp_new +}; + +#ifdef COMPAT_0_7 +char *doc_GetPkgAcqFile = + "GetPkgAcqFile(pkgAquire, uri[, md5, size, descr, shortDescr, destDir, destFile]) -> PkgAcqFile\n"; +PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) +{ + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgAcqFile() is " + "deprecated. Please see apt_pkg.AcquireFile() for the " + "replacement", 1); + 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", + "destDir", "destFile", NULL + }; + + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, + &PyAcquire_Type, &pyfetcher, &uri, &md5, + &size, &descr, &shortDescr, &destDir, &destFile) == 0) + return 0; + + pkgAcquire *fetcher = GetCpp(pyfetcher); + pkgAcqFile *af = new pkgAcqFile(fetcher, // owner + uri, // uri + md5, // md5 + size, // size + descr, // descr + shortDescr, + destDir, + destFile); // short-desc + CppPyObject *AcqFileObj = CppPyObject_NEW(&PyAcquireFile_Type); + AcqFileObj->Object = af; + AcqFileObj->NoDelete = true; + + return AcqFileObj; +} +#endif diff --git a/python/acquire.cc b/python/acquire.cc index 78bd016e..5e03586e 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -13,23 +13,22 @@ #include #include -typedef CppOwnedPyObject PyAcquireItemObject; -typedef CppOwnedPyObject PyAcquireItemDescObject; -typedef CppOwnedPyObject PyAcquireFileObject; -typedef CppOwnedPyObject PyAcquireWorkerObject; - +typedef CppOwnedPyObject PyAcquireWorkerObject; struct PyAcquireItems { - PyAcquireFileObject *file; - PyAcquireItemObject *item; + CppOwnedPyObject *file; + CppOwnedPyObject *item; + CppOwnedPyObject *desc; }; +typedef map item_map; +typedef map worker_map; + // Keep a vector to PyAcquireItemObject pointers, so we can set the Object // pointers to NULL when deallocating the main object (mostly AcquireFile). struct PyAcquireObject : public CppPyObject { - map item_map; - map itemdesc_map; - map worker_map; + item_map items; + worker_map workers; }; @@ -47,18 +46,20 @@ static PyObject *acquireworker_get_current_item(PyObject *self, void *closure) PyObject *PyItem; // FIXME: PyAcquire_FromCpp needs to initialize item_map. - if (PyAcquire && false && PyAcquire->item_map[Item].item) { + if (PyAcquire && false && PyAcquire->items[Item].item) { Py_INCREF(PyItem); - PyItem = PyAcquire->item_map[Item].item; + PyItem = PyAcquire->items[Item].item; } else { PyItem = PyAcquireItem_FromCpp(Item,false,PyAcquire); // FIXME: PyAcquire_FromCpp needs to initialize item_map. if (PyAcquire && false) - PyAcquire->item_map[Item].item = (PyAcquireItemObject*)PyItem; + PyAcquire->items[Item].item = (CppOwnedPyObject*)PyItem; } - return PyAcquireItemDesc_FromCpp(worker->CurrentItem,false,PyItem); + PyObject *ret = PyAcquireItemDesc_FromCpp(worker->CurrentItem,false,PyItem); + Py_DECREF(PyItem); + return ret; } static PyObject *acquireworker_get_status(PyObject *self, void *closure) @@ -208,168 +209,6 @@ PyTypeObject PyAcquireItemDesc_Type = 0, // tp_new }; -inline pkgAcquire::Item *acquireitem_tocpp(PyObject *self) { - pkgAcquire::Item *itm = GetCpp(self); - if (itm == 0) - PyErr_SetString(PyExc_ValueError, "Acquire() has been shut down or " - "the AcquireFile() object has been deallocated."); - return itm; -} - -#define MkGet(PyFunc,Ret) static PyObject *PyFunc(PyObject *Self,void*) \ -{ \ - pkgAcquire::Item *Itm = acquireitem_tocpp(Self); \ - if (Itm == 0) \ - return 0; \ - return Ret; \ -} - -// Define our getters -MkGet(AcquireItemGetComplete,Py_BuildValue("i",Itm->Complete)); -MkGet(AcquireItemGetDescURI,Safe_FromString(Itm->DescURI().c_str())); -MkGet(AcquireItemGetDestFile,Safe_FromString(Itm->DestFile.c_str())); -MkGet(AcquireItemGetErrorText,Safe_FromString(Itm->ErrorText.c_str())); -MkGet(AcquireItemGetFileSize,Py_BuildValue("i",Itm->FileSize)); -MkGet(AcquireItemGetID,Py_BuildValue("k",Itm->ID)); -MkGet(AcquireItemGetMode,Py_BuildValue("s",Itm->Mode)); -MkGet(AcquireItemGetIsTrusted,Py_BuildValue("i",Itm->IsTrusted())); -MkGet(AcquireItemGetLocal,Py_BuildValue("i",Itm->Local)); -MkGet(AcquireItemGetStatus,Py_BuildValue("i",Itm->Status)); - -// Constants -MkGet(AcquireItemGetStatIdle,Py_BuildValue("i", pkgAcquire::Item::StatIdle)); -MkGet(AcquireItemGetStatFetching,Py_BuildValue("i", pkgAcquire::Item::StatFetching)); -MkGet(AcquireItemGetStatDone,Py_BuildValue("i", pkgAcquire::Item::StatDone)); -MkGet(AcquireItemGetStatError,Py_BuildValue("i", pkgAcquire::Item::StatError)); -MkGet(AcquireItemGetStatAuthError,Py_BuildValue("i", pkgAcquire::Item::StatAuthError)); -#undef MkGet - -static int AcquireItemSetID(PyObject *self, PyObject *value, void *closure) -{ - pkgAcquire::Item *Itm = acquireitem_tocpp(self); - if (Itm == 0) - return -1; - if (PyLong_Check(value)) { - Itm->ID = PyLong_AsLong(value); - } - else if (PyInt_Check(value)) { - Itm->ID = PyInt_AsLong(value); - } - else { - PyErr_SetString(PyExc_TypeError, "value must be integer."); - return -1; - } - return 0; -} - - -static PyGetSetDef AcquireItemGetSet[] = { - {"complete",AcquireItemGetComplete}, - {"desc_uri",AcquireItemGetDescURI}, - {"destfile",AcquireItemGetDestFile}, - {"error_text",AcquireItemGetErrorText}, - {"filesize",AcquireItemGetFileSize}, - {"id",AcquireItemGetID,AcquireItemSetID}, - {"mode",AcquireItemGetMode}, - {"is_trusted",AcquireItemGetIsTrusted}, - {"local",AcquireItemGetLocal}, - {"status",AcquireItemGetStatus}, - {"stat_idle",AcquireItemGetStatIdle}, - {"stat_fetching",AcquireItemGetStatFetching}, - {"stat_done",AcquireItemGetStatDone}, - {"stat_error",AcquireItemGetStatError}, - {"stat_auth_error",AcquireItemGetStatAuthError}, -#ifdef COMPAT_0_7 - {"Complete",AcquireItemGetComplete}, - {"DescURI",AcquireItemGetDescURI}, - {"DestFile",AcquireItemGetDestFile}, - {"ErrorText",AcquireItemGetErrorText}, - {"FileSize",AcquireItemGetFileSize}, - {"ID",AcquireItemGetID}, - {"IsTrusted",AcquireItemGetIsTrusted}, - {"Local",AcquireItemGetLocal}, - {"Status",AcquireItemGetStatus}, - {"StatIdle",AcquireItemGetStatIdle}, - {"StatFetching",AcquireItemGetStatFetching}, - {"StatDone",AcquireItemGetStatDone}, - {"StatError",AcquireItemGetStatError}, - {"StatAuthError",AcquireItemGetStatAuthError}, -#endif - {} -}; - - - -static PyObject *AcquireItemRepr(PyObject *Self) -{ - pkgAcquire::Item *Itm = acquireitem_tocpp(Self); - if (Itm == 0) - return 0; - - return PyString_FromFormat("<%s object: " - "Status: %i Complete: %i Local: %i IsTrusted: %i " - "FileSize: %lu DestFile:'%s' " - "DescURI: '%s' ID:%lu ErrorText: '%s'>", - Self->ob_type->tp_name, - Itm->Status, Itm->Complete, Itm->Local, Itm->IsTrusted(), - Itm->FileSize, Itm->DestFile.c_str(), Itm->DescURI().c_str(), - Itm->ID,Itm->ErrorText.c_str()); -} - -static void AcquireItemDealloc(PyObject *self) { - pkgAcquire::Item *file = GetCpp(self); - PyAcquireObject *owner = (PyAcquireObject *)GetOwner(self); - - // Simply deallocate the object if we have no owner. - if (owner != NULL && !((CppPyObject *)self)->NoDelete) { - PyAcquireItems &items = owner->item_map[file]; - - if (items.item && items.item != self) - items.item->Object = NULL; - if (items.file && items.item != self) - items.file->Object = NULL; - owner->item_map.erase(file); - } - - CppOwnedDeallocPtr(self); -} - - - -PyTypeObject PyAcquireItem_Type = -{ - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "apt_pkg.AcquireItem", // tp_name - sizeof(CppOwnedPyObject), // tp_basicsize - 0, // tp_itemsize - // Methods - AcquireItemDealloc, // tp_dealloc - 0, // tp_print - 0, // 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 - 0, // tp_call - 0, // tp_str - 0, // tp_getattro - 0, // tp_setattro - 0, // tp_as_buffer - Py_TPFLAGS_DEFAULT, // tp_flags - "AcquireItem Object", // tp_doc - 0, // tp_traverse - 0, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext - 0, // tp_methods - 0, // tp_members - AcquireItemGetSet, // tp_getset -}; @@ -396,15 +235,20 @@ static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args) fetcher->Shutdown(); // TODO: Delete all objects here - map items = ((PyAcquireObject *)Self)->item_map; - for (map::iterator I = items.begin(); - I != items.end(); I++) { - (*I).second.file->Object = NULL; - (*I).second.item->Object = NULL; + item_map &items = ((PyAcquireObject *)Self)->items; + for (item_map::iterator I = items.begin(); I != items.end(); I++) { + if ((*I).second.file) + (*I).second.file->Object = NULL; + if ((*I).second.item) { + (*I).second.item->Object = NULL; + Py_DECREF((*I).second.item); + } + if ((*I).second.desc) { + (*I).second.desc->Object = NULL; + Py_DECREF((*I).second.desc); + } } - - - + items.clear(); Py_INCREF(Py_None); return HandleErrors(Py_None); } @@ -442,6 +286,7 @@ static PyObject *PkgAcquireGetWorkers(PyObject *self, void *closure) PyWorker = CppOwnedPyObject_NEW(self,&PyAcquireWorker_Type, Worker); PyWorker->NoDelete = true; PyList_Append(List, PyWorker); + Py_DECREF(PyWorker); } return List; } @@ -449,19 +294,22 @@ static PyObject *PkgAcquireGetItems(PyObject *Self,void*) { pkgAcquire *fetcher = GetCpp(Self); PyObject *List = PyList_New(0); - PyAcquireItemObject *Obj; + CppOwnedPyObject *Obj; for (pkgAcquire::ItemIterator I = fetcher->ItemsBegin(); I != fetcher->ItemsEnd(); I++) { - if (((PyAcquireObject *)Self)->item_map[*I].item) - PyList_Append(List, ((PyAcquireObject *)Self)->item_map[*I].item); + if (((PyAcquireObject *)Self)->items[*I].item) + PyList_Append(List, ((PyAcquireObject *)Self)->items[*I].item); else { Obj = CppOwnedPyObject_NEW(Self,&PyAcquireItem_Type,*I); Obj->NoDelete = true; + PyList_Append(List,Obj); - ((PyAcquireObject *)Self)->item_map[*I].item = Obj; - Py_DECREF(Obj); + ((PyAcquireObject *)Self)->items[*I].item = Obj; + + + // Not DECREFING it, we want to manage it somewhere else. } } return List; @@ -506,9 +354,10 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) if (PyArg_ParseTupleAndKeywords(Args,kwds,"|O",kwlist,&pyFetchProgressInst) == 0) return 0; + PyFetchProgress *progress = 0; if (pyFetchProgressInst != NULL) { // FIXME: memleak? - PyFetchProgress *progress = new PyFetchProgress(); + progress = new PyFetchProgress(); progress->setCallbackInst(pyFetchProgressInst); fetcher = new pkgAcquire(progress); } else { @@ -518,8 +367,11 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) PyAcquireObject *FetcherObj = (PyAcquireObject *) CppPyObject_NEW(type, fetcher); + if (progress != 0) + progress->setPyAcquire(FetcherObj); // prepare our map of items. - new (&FetcherObj->item_map) map(); + new (&FetcherObj->items) item_map(); + new (&FetcherObj->workers) worker_map(); return FetcherObj; } @@ -581,125 +433,3 @@ PyObject *GetAcquire(PyObject *Self,PyObject *Args) } #endif -static PyObject *PkgAcquireFileNew(PyTypeObject *type, 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", "short_descr", - "destdir", "destfile", NULL}; - - if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, - &PyAcquire_Type, &pyfetcher, &uri, &md5, - &size, &descr, &shortDescr, &destDir, &destFile) == 0) - return 0; - - pkgAcquire *fetcher = GetCpp(pyfetcher); - pkgAcqFile *af = new pkgAcqFile(fetcher, // owner - uri, // uri - md5, // md5 - size, // size - descr, // descr - shortDescr, - destDir, - destFile); // short-desc - CppOwnedPyObject *AcqFileObj = CppOwnedPyObject_NEW(pyfetcher, type); - AcqFileObj->Object = af; - - // Register the file so we can remove it later. - ((PyAcquireObject *)pyfetcher)->item_map[af].file = AcqFileObj; - - return AcqFileObj; -} - - -static char *doc_PkgAcquireFile = - "AcquireFile(owner, uri[, md5, size, descr, short_descr, destdir," - "destfile]) -> New AcquireFile() object\n\n" - "The parameter *owner* refers to an apt_pkg.Acquire() object. You can use\n" - "*destdir* OR *destfile* to specify the destination directory/file."; - -PyTypeObject PyAcquireFile_Type = -{ - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "apt_pkg.AcquireFile", // tp_name - sizeof(CppOwnedPyObject),// tp_basicsize - 0, // tp_itemsize - // Methods - AcquireItemDealloc, // tp_dealloc - 0, // tp_print - 0, // 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 - 0, // tp_call - 0, // tp_str - 0, // tp_getattro - 0, // tp_setattro - 0, // tp_as_buffer - (Py_TPFLAGS_DEFAULT | // tp_flags - Py_TPFLAGS_BASETYPE | - Py_TPFLAGS_HAVE_GC), - doc_PkgAcquireFile, // tp_doc - CppOwnedTraverse, // tp_traverse - CppOwnedClear, // tp_clear - 0, // tp_richcompare - 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext - 0, // tp_methods - 0, // tp_members - 0, // tp_getset - &PyAcquireItem_Type, // tp_base - 0, // tp_dict - 0, // tp_descr_get - 0, // tp_descr_set - 0, // tp_dictoffset - 0, // tp_init - 0, // tp_alloc - PkgAcquireFileNew, // tp_new -}; - -#ifdef COMPAT_0_7 -char *doc_GetPkgAcqFile = -"GetPkgAcqFile(pkgAquire, uri[, md5, size, descr, shortDescr, destDir, destFile]) -> PkgAcqFile\n"; -PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) -{ - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgAcqFile() is " - "deprecated. Please see apt_pkg.AcquireFile() for the " - "replacement", 1); - 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", - "destDir", "destFile", NULL}; - - if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, - &PyAcquire_Type, &pyfetcher, &uri, &md5, - &size, &descr, &shortDescr, &destDir, &destFile) == 0) - return 0; - - pkgAcquire *fetcher = GetCpp(pyfetcher); - pkgAcqFile *af = new pkgAcqFile(fetcher, // owner - uri, // uri - md5, // md5 - size, // size - descr, // descr - shortDescr, - destDir, - destFile); // short-desc - CppPyObject *AcqFileObj = CppPyObject_NEW(&PyAcquireFile_Type); - AcqFileObj->Object = af; - AcqFileObj->NoDelete = true; - - return AcqFileObj; -} -#endif diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 5ee4015c..0a899efb 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -13,6 +13,7 @@ #include "generic.h" #include +#include #include #include #include @@ -606,6 +607,9 @@ extern "C" void initapt_pkg() PyModule_AddObject(Module,"Config",Config); #endif + + + // Add our classes. /* ============================ tag.cc ============================ */ ADDTYPE(Module,"TagSection",&PyTagSection_Type); @@ -661,6 +665,34 @@ extern "C" void initapt_pkg() PyModule_AddObject(Module,"REWRITE_SOURCE_ORDER", CharCharToList(TFRewriteSourceOrder)); + + // AcquireItem Constants. + + + PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "stat_idle", + Py_BuildValue("i", pkgAcquire::Item::StatIdle)); + PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "stat_fetching", + Py_BuildValue("i", pkgAcquire::Item::StatFetching)); + PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "stat_done", + Py_BuildValue("i", pkgAcquire::Item::StatDone)); + PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "stat_error", + Py_BuildValue("i", pkgAcquire::Item::StatError)); + PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "stat_auth_error", + Py_BuildValue("i", pkgAcquire::Item::StatAuthError)); + +#ifdef COMPAT_0_7 + PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "StatIdle", + Py_BuildValue("i", pkgAcquire::Item::StatIdle)); + PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "StatFetching", + Py_BuildValue("i", pkgAcquire::Item::StatFetching)); + PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "StatDone", + Py_BuildValue("i", pkgAcquire::Item::StatDone)); + PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "StatError", + Py_BuildValue("i", pkgAcquire::Item::StatError)); + PyDict_SetItemString(PyAcquireItem_Type.tp_dict, "StatAuthError", + Py_BuildValue("i", pkgAcquire::Item::StatAuthError)); +#endif + #if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 1 PyObject *PyCapsule = PyCapsule_New(&API, "apt_pkg._C_API", NULL); #else diff --git a/python/progress.cc b/python/progress.cc index 305246b7..1b135a75 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -35,7 +35,12 @@ inline bool setattr(PyObject *object, const char *attr, const char *fmt, T arg) return result != -1; } -#define TUPLEIZE(op) Py_BuildValue("(O)", op) +inline PyObject *TUPLEIZE(PyObject *op) { + PyObject *ret = Py_BuildValue("(O)", op); + Py_DECREF(op); + return ret; +} + // generic bool PyCallbackObj::RunSimpleCallback(const char* method_name, PyObject *arglist, @@ -300,7 +305,10 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) if (PyObject_TypeCheck(callbackInst, &PyAcquireProgress_Type)) { PyObject *result1; bool res1 = true; - if (RunSimpleCallback("pulse", TUPLEIZE(PyAcquire_FromCpp(Owner)), &result1)) { + + Py_INCREF(pyAcquire); + + if (RunSimpleCallback("pulse", TUPLEIZE(pyAcquire) , &result1)) { if (result1 != NULL && PyArg_Parse(result1, "b", &res1) && res1 == false) { // the user returned a explicit false here, stop PyCbObj_BEGIN_ALLOW_THREADS diff --git a/python/progress.h b/python/progress.h index e92933a7..bc1bd640 100644 --- a/python/progress.h +++ b/python/progress.h @@ -94,6 +94,9 @@ struct PyOpProgress : public OpProgress, public PyCallbackObj struct PyFetchProgress : public pkgAcquireStatus, public PyCallbackObj { + protected: + PyObject *pyAcquire; + public: enum { DLDone, DLQueued, DLFailed, DLHit, DLIgnored }; @@ -102,6 +105,10 @@ struct PyFetchProgress : public pkgAcquireStatus, public PyCallbackObj virtual bool MediaChange(string Media, string Drive); + void setPyAcquire(PyObject *o) { + pyAcquire = o; + } + /* apt stuff */ virtual void IMSHit(pkgAcquire::ItemDesc &Itm); virtual void Fetch(pkgAcquire::ItemDesc &Itm); diff --git a/setup.py b/setup.py index e07bd83b..93fcb436 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,8 @@ files = ['apt_pkgmodule.cc', 'acquire.cc', 'cache.cc', 'cdrom.cc', 'hashstring.cc', 'indexfile.cc', 'indexrecords.cc', 'metaindex.cc', 'pkgmanager.cc', 'pkgrecords.cc', 'pkgsrcrecords.cc', 'policy.cc', 'progress.cc', 'sourcelist.cc', 'string.cc', 'tag.cc', - 'opprogress.cc', 'acquireprogress.cc', 'cdromprogress.cc', 'lock.cc'] + 'opprogress.cc', 'acquireprogress.cc', 'cdromprogress.cc', 'lock.cc', + 'acquire-item.cc'] files = sorted(['python/' + fname for fname in files]) apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]) -- cgit v1.2.3 From 544f14e0f2fb70b5a1f30786a93023a42d88290d Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 22 Jul 2009 18:16:28 +0200 Subject: python: 2nd part of the acquire fixes (one PyObject per C++ object). --- python/acquire-item.cc | 14 +++++++---- python/acquire.cc | 63 +++++++++++++++++++++++++------------------------- python/apt_pkgmodule.h | 5 ++++ python/progress.cc | 10 ++++---- python/python-apt.h | 5 ++-- 5 files changed, 54 insertions(+), 43 deletions(-) (limited to 'python/progress.cc') diff --git a/python/acquire-item.cc b/python/acquire-item.cc index cf0a628e..1fb66080 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -176,13 +176,11 @@ static PyObject *acquireitem_repr(PyObject *Self) static void acquireitem_dealloc(PyObject *self) { + pkgAcquire::Item *item = PyAcquireItem_ToCpp(self); + PyAcquireObject *Owner = (PyAcquireObject *)GetOwner(self); + PyAcquireItems item_struct = Owner->items[item]; // TODO: Unregister the object in the owner. if (!((CppOwnedPyObject*)self)->NoDelete) { - pkgAcquire::Item *item = PyAcquireItem_ToCpp(self); - PyAcquireObject *Owner = (PyAcquireObject *)GetOwner(self); - - PyAcquireItems item_struct = Owner->items[item]; - if (item_struct.file != 0 && item_struct.file != self) item_struct.file->Object = 0; if (item_struct.item != 0 && item_struct.item != self) { @@ -195,6 +193,12 @@ static void acquireitem_dealloc(PyObject *self) } Owner->items.erase(item); } + else { + if (item_struct.file == self) + item_struct.file = 0; + if (item_struct.item == self) + item_struct.item = 0; + } CppOwnedDeallocPtr(self); } diff --git a/python/acquire.cc b/python/acquire.cc index 5e03586e..1085d0a2 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -40,26 +40,17 @@ static PyObject *acquireworker_get_current_item(PyObject *self, void *closure) Py_RETURN_NONE; } - PyAcquireObject *PyAcquire = (PyAcquireObject *)GetOwner(self); + PyObject *PyAcquire = GetOwner(self); - pkgAcquire::Item *Item = worker->CurrentItem->Owner; - - PyObject *PyItem; - // FIXME: PyAcquire_FromCpp needs to initialize item_map. - if (PyAcquire && false && PyAcquire->items[Item].item) { - Py_INCREF(PyItem); - PyItem = PyAcquire->items[Item].item; - } + if (PyAcquire) + return PyAcquire_GetItemDesc(PyAcquire, worker->CurrentItem); else { - PyItem = PyAcquireItem_FromCpp(Item,false,PyAcquire); - // FIXME: PyAcquire_FromCpp needs to initialize item_map. - if (PyAcquire && false) - PyAcquire->items[Item].item = (CppOwnedPyObject*)PyItem; + PyObject *PyItem = PyAcquireItem_FromCpp(worker->CurrentItem->Owner); + PyObject *ret = PyAcquireItemDesc_FromCpp(worker->CurrentItem,false, + PyItem); + Py_DECREF(PyItem); + return ret; } - - PyObject *ret = PyAcquireItemDesc_FromCpp(worker->CurrentItem,false,PyItem); - Py_DECREF(PyItem); - return ret; } static PyObject *acquireworker_get_status(PyObject *self, void *closure) @@ -146,7 +137,7 @@ static PyObject *acquireitemdesc_get_owner(CppOwnedPyObjectOwner); return self->Owner; } - else if (self->Object && self->Object->Owner != NULL) { + else if (self->Object) { self->Owner = PyAcquireItem_FromCpp(self->Object->Owner); Py_INCREF(self->Owner); return self->Owner; @@ -210,7 +201,27 @@ PyTypeObject PyAcquireItemDesc_Type = }; +// Acquire + +PyObject *PyAcquire_GetItem(PyObject *self, pkgAcquire::Item *item) { + PyAcquireItems &item_struct = ((PyAcquireObject *)self)->items[item]; + if (! item_struct.item) { + item_struct.item = PyAcquireItem_FromCpp(item,false,self); + } + Py_INCREF(item_struct.item); + return item_struct.item; +} +PyObject *PyAcquire_GetItemDesc(PyObject *self, pkgAcquire::ItemDesc *item) { + PyAcquireItems &item_struct = ((PyAcquireObject *)self)->items[item->Owner]; + if (! item_struct.item) + item_struct.item = PyAcquireItem_FromCpp(item->Owner,false,self); + if (! item_struct.desc) + item_struct.desc = PyAcquireItemDesc_FromCpp(item,false, + item_struct.item); + Py_INCREF(item_struct.desc); + return item_struct.desc; +} static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args) { @@ -294,23 +305,13 @@ static PyObject *PkgAcquireGetItems(PyObject *Self,void*) { pkgAcquire *fetcher = GetCpp(Self); PyObject *List = PyList_New(0); - CppOwnedPyObject *Obj; + PyObject *Obj; for (pkgAcquire::ItemIterator I = fetcher->ItemsBegin(); I != fetcher->ItemsEnd(); I++) { - - if (((PyAcquireObject *)Self)->items[*I].item) - PyList_Append(List, ((PyAcquireObject *)Self)->items[*I].item); - else { - Obj = CppOwnedPyObject_NEW(Self,&PyAcquireItem_Type,*I); - Obj->NoDelete = true; - + Obj = PyAcquire_GetItem(Self, *I); PyList_Append(List,Obj); - ((PyAcquireObject *)Self)->items[*I].item = Obj; - - - // Not DECREFING it, we want to manage it somewhere else. - } + Py_DECREF(Obj); } return List; } diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 04bce2cc..3edba5d2 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -12,6 +12,7 @@ #include #include +#include // Configuration Stuff #define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type) @@ -49,6 +50,10 @@ PyObject *StrTimeRFC1123(PyObject *self,PyObject *Args); PyObject *StrStrToTime(PyObject *self,PyObject *Args); PyObject *StrCheckDomainList(PyObject *Self,PyObject *Args); +PyObject *PyAcquire_GetItem(PyObject *self, pkgAcquire::Item *item); +PyObject *PyAcquire_GetItemDesc(PyObject *self, pkgAcquire::ItemDesc *item); +bool PyAcquire_DropItem(PyObject *self, pkgAcquire::Item *item); + // Cache Stuff extern PyTypeObject PyCache_Type; extern PyTypeObject PyCacheFile_Type; diff --git a/python/progress.cc b/python/progress.cc index 1b135a75..7873d894 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -175,7 +175,7 @@ void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLHit); PyCbObj_BEGIN_ALLOW_THREADS @@ -185,7 +185,7 @@ void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("fetch", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("fetch", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLQueued); PyCbObj_BEGIN_ALLOW_THREADS @@ -195,7 +195,7 @@ void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("done", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("done", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLDone); PyCbObj_BEGIN_ALLOW_THREADS @@ -205,7 +205,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) { - RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); return; } @@ -220,7 +220,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) - RunSimpleCallback("fail", TUPLEIZE(PyAcquireItemDesc_FromCpp(&Itm))); + RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLFailed); PyCbObj_BEGIN_ALLOW_THREADS diff --git a/python/python-apt.h b/python/python-apt.h index 80ad03bd..fb84b394 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -220,7 +220,8 @@ static int import_apt_pkg(void) { // Python object creation, using two inline template functions and one variadic // macro per type. template -inline PyObject *FromCpp(PyTypeObject *pytype, Cpp obj, bool Delete=false) +inline CppPyObject *FromCpp(PyTypeObject *pytype, Cpp obj, + bool Delete=false) { CppPyObject *Obj = CppPyObject_NEW(pytype, obj); Obj->NoDelete = (!Delete); @@ -228,7 +229,7 @@ inline PyObject *FromCpp(PyTypeObject *pytype, Cpp obj, bool Delete=false) } template -inline PyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, +inline CppOwnedPyObject *FromCppOwned(PyTypeObject *pytype, Cpp const &obj, bool Delete=false, PyObject *Owner=NULL) { CppOwnedPyObject *Obj = CppOwnedPyObject_NEW(Owner, pytype, obj); -- cgit v1.2.3 From e3653ead6554eafb9eb3327708944f30171aed6c Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 31 Jul 2009 14:58:49 +0200 Subject: python/progress.cc: Do not special case apt_pkg.*Progress anymore. --- python/progress.cc | 123 ++++++++++++++++++++++------------------------------- 1 file changed, 51 insertions(+), 72 deletions(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index 7873d894..c754dd35 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -91,28 +91,20 @@ void PyOpProgress::Update() return; - if (PyObject_TypeCheck(callbackInst, &PyOpProgress_Type)) { - PyOpProgressObject *obj = (PyOpProgressObject *)callbackInst; - obj->op = CppPyString(Op); - obj->subop = CppPyString(SubOp); -#ifdef T_BOOL - obj->major_change = (char)(MajorChange); + setattr(callbackInst, "op", "s", Op.c_str()); + setattr(callbackInst, "subop", "s", SubOp.c_str()); + setattr(callbackInst, "major_change", "b", MajorChange); +#ifdef COMPAT_0_7 + setattr(callbackInst, "Op", "s", Op.c_str()); + setattr(callbackInst, "subOp", "s", SubOp.c_str()); + setattr(callbackInst, "majorChange", "b", MajorChange); + PyObject *arglist = Py_BuildValue("(f)", Percent); + RunSimpleCallback("update", arglist); #else - obj->major_change = (int)(MajorChange); + setattr(callbackInst, "percent", "f", Percent); + RunSimpleCallback("update"); #endif - obj->percent = Percent; - RunSimpleCallback("update"); - } - else { - setattr(callbackInst, "op", "s", Op.c_str()); - setattr(callbackInst, "subop", "s", SubOp.c_str()); - setattr(callbackInst, "subOp", "s", SubOp.c_str()); - setattr(callbackInst, "major_change", "b", MajorChange); - setattr(callbackInst, "majorChange", "b", MajorChange); - PyObject *arglist = Py_BuildValue("(f)", Percent); - RunSimpleCallback("update", arglist); - } -}; +} void PyOpProgress::Done() { @@ -174,7 +166,7 @@ void PyFetchProgress::UpdateStatus(pkgAcquire::ItemDesc &Itm, int status) void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS - if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) + if (PyObject_HasAttrString(callbackInst, "ims_hit")) RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLHit); @@ -184,7 +176,7 @@ void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS - if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) + if (PyObject_HasAttrString(callbackInst, "fetch")) RunSimpleCallback("fetch", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLQueued); @@ -194,7 +186,7 @@ void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS - if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) + if (PyObject_HasAttrString(callbackInst, "done")) RunSimpleCallback("done", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLDone); @@ -204,7 +196,7 @@ void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS - if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) { + if (PyObject_HasAttrString(callbackInst, "fail")) { RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); return; } @@ -219,7 +211,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) } - if (PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) + if (PyObject_HasAttrString(callbackInst, "fail")) RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); else UpdateStatus(Itm, DLFailed); @@ -232,13 +224,11 @@ void PyFetchProgress::Start() pkgAcquireStatus::Start(); #ifdef COMPAT_0_7 - if (!PyObject_TypeCheck(callbackInst,&PyAcquireProgress_Type)) { - setattr(callbackInst, "currentCPS", "d", 0); - setattr(callbackInst, "currentBytes", "d", 0); - setattr(callbackInst, "currentItems", "k", 0); - setattr(callbackInst, "totalItems", "k", 0); - setattr(callbackInst, "totalBytes", "d", 0); - } + setattr(callbackInst, "currentCPS", "d", 0); + setattr(callbackInst, "currentBytes", "d", 0); + setattr(callbackInst, "currentItems", "k", 0); + setattr(callbackInst, "totalItems", "k", 0); + setattr(callbackInst, "totalBytes", "d", 0); #endif RunSimpleCallback("start"); @@ -272,37 +262,29 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) if(callbackInst == 0) return false; - if (PyObject_TypeCheck(callbackInst, &PyAcquireProgress_Type)) { - PyAcquireProgressObject *obj = (PyAcquireProgressObject *)callbackInst; - obj->last_bytes = LastBytes; - obj->current_cps = CurrentCPS; - obj->current_bytes = CurrentBytes; - obj->total_bytes = TotalBytes; - obj->fetched_bytes = FetchedBytes; - obj->elapsed_time = ElapsedTime; - obj->total_items = TotalItems; - obj->current_items = CurrentItems; - } - else { - setattr(callbackInst, "last_bytes", "d", LastBytes); - setattr(callbackInst, "current_cps", "d", CurrentCPS); - setattr(callbackInst, "current_bytes", "d", CurrentBytes); - setattr(callbackInst, "total_bytes", "d", TotalBytes); - setattr(callbackInst, "fetched_bytes", "d", FetchedBytes); - setattr(callbackInst, "elapsed_time", "k", ElapsedTime); - setattr(callbackInst, "current_items", "k", CurrentItems); - setattr(callbackInst, "total_items", "k", TotalItems); + setattr(callbackInst, "last_bytes", "d", LastBytes); + setattr(callbackInst, "current_cps", "d", CurrentCPS); + setattr(callbackInst, "current_bytes", "d", CurrentBytes); + setattr(callbackInst, "total_bytes", "d", TotalBytes); + setattr(callbackInst, "fetched_bytes", "d", FetchedBytes); + setattr(callbackInst, "elapsed_time", "k", ElapsedTime); + setattr(callbackInst, "current_items", "k", CurrentItems); + setattr(callbackInst, "total_items", "k", TotalItems); #ifdef COMPAT_0_7 - setattr(callbackInst, "currentCPS", "d", CurrentCPS); - setattr(callbackInst, "currentBytes", "d", CurrentBytes); - setattr(callbackInst, "totalBytes", "d", TotalBytes); - setattr(callbackInst, "fetchedBytes", "d", FetchedBytes); - setattr(callbackInst, "currentItems", "k", CurrentItems); - setattr(callbackInst, "totalItems", "k", TotalItems); + setattr(callbackInst, "currentCPS", "d", CurrentCPS); + setattr(callbackInst, "currentBytes", "d", CurrentBytes); + setattr(callbackInst, "totalBytes", "d", TotalBytes); + setattr(callbackInst, "fetchedBytes", "d", FetchedBytes); + setattr(callbackInst, "currentItems", "k", CurrentItems); + setattr(callbackInst, "totalItems", "k", TotalItems); #endif - } - if (PyObject_TypeCheck(callbackInst, &PyAcquireProgress_Type)) { + // New style +#ifdef COMPAT_0_7 + if (!PyObject_HasAttrString(callbackInst, "updateStatus")) { +#else + { +#endif PyObject *result1; bool res1 = true; @@ -317,8 +299,11 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) } PyCbObj_BEGIN_ALLOW_THREADS return true; - } + + + } +#ifdef COMPAT_0_7 // Go through the list of items and add active items to the // activeItems vector. map activeItemMap; @@ -407,6 +392,7 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) PyCbObj_BEGIN_ALLOW_THREADS // fetching can be canceld by returning false return res; +#endif } @@ -541,17 +527,10 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) void PyCdromProgress::Update(string text, int current) { PyObject *arglist = Py_BuildValue("(si)", text.c_str(), current); - if (PyObject_TypeCheck(callbackInst, &PyCdromProgress_Type)) { - ((PyCdromProgressObject *)callbackInst)->total_steps = totalSteps; - } - else { - - setattr(callbackInst, "total_steps", "i", totalSteps); -#ifdef COMPAT_0_7 - setattr(callbackInst, "totalSteps", "i", totalSteps); -#endif - } - + setattr(callbackInst, "total_steps", "i", totalSteps); + #ifdef COMPAT_0_7 + setattr(callbackInst, "totalSteps", "i", totalSteps); + #endif RunSimpleCallback("update", arglist); } -- cgit v1.2.3 From b76e901886d37d0eee8d554a5d977cedd134d353 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 15 Jan 2010 18:07:27 +0100 Subject: python/lock.cc,python/progress.cc: Include Python.h first to avoid warning. --- python/lock.cc | 2 +- python/progress.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'python/progress.cc') diff --git a/python/lock.cc b/python/lock.cc index d4d45734..fc78c0cb 100644 --- a/python/lock.cc +++ b/python/lock.cc @@ -18,9 +18,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ +#include #include #include -#include #include "generic.h" static PyObject *systemlock_exit(PyObject *self, PyObject *args) diff --git a/python/progress.cc b/python/progress.cc index 30f62763..0de54510 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -5,7 +5,7 @@ Progress - Wrapper for the progress related functions ##################################################################### */ - +#include #include #include #include -- cgit v1.2.3 From 0d3c3d391bdff23e78d693d10d43e0cc24ce16fc Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 20 Jan 2010 15:40:35 +0100 Subject: python/progress.cc: Always set 'percent' in OpProgress objects. --- python/progress.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index 0de54510..22ce39a4 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -90,10 +90,10 @@ void PyOpProgress::Update() if(!CheckChange(0.7)) return; - setattr(callbackInst, "op", "s", Op.c_str()); setattr(callbackInst, "subop", "s", SubOp.c_str()); setattr(callbackInst, "major_change", "b", MajorChange); + setattr(callbackInst, "percent", "f", Percent); #ifdef COMPAT_0_7 setattr(callbackInst, "Op", "s", Op.c_str()); setattr(callbackInst, "subOp", "s", SubOp.c_str()); @@ -101,7 +101,6 @@ void PyOpProgress::Update() PyObject *arglist = Py_BuildValue("(f)", Percent); RunSimpleCallback("update", arglist); #else - setattr(callbackInst, "percent", "f", Percent); RunSimpleCallback("update"); #endif } -- cgit v1.2.3 From 511ca4dd916413a5f6a0ae140cfc678695bb006f Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 23 Jan 2010 15:36:36 +0100 Subject: Fix reference counting for old progress classes (Closes: #566370). --- debian/changelog | 6 ++++++ python/progress.cc | 22 +++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'python/progress.cc') diff --git a/debian/changelog b/debian/changelog index d9cc2dfe..6f5cd696 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +python-apt (0.7.93.1) UNRELEASED; urgency=low + + * Fix reference counting for old progress classes (Closes: #566370). + + -- Julian Andres Klode Sat, 23 Jan 2010 15:35:55 +0100 + python-apt (0.7.93) unstable; urgency=low [ Julian Andres Klode ] diff --git a/python/progress.cc b/python/progress.cc index 22ce39a4..63d9eede 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -124,8 +124,11 @@ bool PyFetchProgress::MediaChange(string Media, string Drive) //std::cout << "MediaChange" << std::endl; PyObject *arglist = Py_BuildValue("(ss)", Media.c_str(), Drive.c_str()); PyObject *result; - if(! RunSimpleCallback("media_change", arglist, &result)) - RunSimpleCallback("mediaChange", arglist, &result); + + if(PyObject_HasAttrString(callbackInst, "media_change")) + RunSimpleCallback("media_change", arglist, &result); + else + RunSimpleCallback("mediaChange", arglist, &result); bool res = true; if(!PyArg_Parse(result, "b", &res)) { @@ -157,8 +160,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(!RunSimpleCallback("update_status", arglist)) - RunSimpleCallback("updateStatus", arglist); + if(PyObject_HasAttrString(callbackInst, "update_status")) + RunSimpleCallback("update_status", arglist); + else + RunSimpleCallback("updateStatus", arglist); } void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) @@ -536,8 +541,10 @@ bool PyCdromProgress::ChangeCdrom() { PyObject *arglist = Py_BuildValue("()"); PyObject *result; - if(!RunSimpleCallback("change_cdrom", arglist, &result)) - RunSimpleCallback("changeCdrom", arglist, &result); + if (PyObject_HasAttrString(callbackInst, "change_cdrom")) + RunSimpleCallback("change_cdrom", arglist, &result); + else + RunSimpleCallback("changeCdrom", arglist, &result); bool res = true; if(!PyArg_Parse(result, "b", &res)) @@ -555,7 +562,8 @@ bool PyCdromProgress::AskCdromName(string &Name) PyObject *result; // New style: String on success, None on failure. - if (RunSimpleCallback("ask_cdrom_name", arglist, &result)) { + if (PyObject_HasAttrString(callbackInst, "ask_cdrom_name")) { + RunSimpleCallback("ask_cdrom_name", arglist, &result); if(result == Py_None) return false; if(!PyArg_Parse(result, "s", &new_name)) -- cgit v1.2.3 From c654ae4c10bf40922e2ecf8f1b7fe1c2b97a06aa Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 23 Jan 2010 19:21:26 +0100 Subject: * python/progress.cc: - Fix some threading issues (add some missing PyCbObj_BEGIN_ALLOW_THREADS) --- debian/changelog | 2 ++ python/progress.cc | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'python/progress.cc') diff --git a/debian/changelog b/debian/changelog index 95ca5b41..3fa0852f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,8 @@ python-apt (0.7.93.1) UNRELEASED; urgency=low * Fix reference counting for old progress classes (Closes: #566370). * apt/cache.py: - Fix Cache.update() to not raise errors on successful updates. + * python/progress.cc: + - Fix some threading issues (add some missing PyCbObj_BEGIN_ALLOW_THREADS) -- Julian Andres Klode Sat, 23 Jan 2010 15:35:55 +0100 diff --git a/python/progress.cc b/python/progress.cc index 63d9eede..0fc01085 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -133,6 +133,7 @@ bool PyFetchProgress::MediaChange(string Media, string Drive) bool res = true; if(!PyArg_Parse(result, "b", &res)) { // no return value or None, assume false + PyCbObj_BEGIN_ALLOW_THREADS return false; } @@ -201,12 +202,15 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) PyCbObj_END_ALLOW_THREADS if (PyObject_HasAttrString(callbackInst, "fail")) { RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); + PyCbObj_BEGIN_ALLOW_THREADS return; } // Ignore certain kinds of transient failures (bad code) - if (Itm.Owner->Status == pkgAcquire::Item::StatIdle) + if (Itm.Owner->Status == pkgAcquire::Item::StatIdle) { + PyCbObj_BEGIN_ALLOW_THREADS return; + } if (Itm.Owner->Status == pkgAcquire::Item::StatDone) { @@ -262,8 +266,10 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) pkgAcquireStatus::Pulse(Owner); //std::cout << "Pulse" << std::endl; - if(callbackInst == 0) + if(callbackInst == 0) { + PyCbObj_BEGIN_ALLOW_THREADS return false; + } setattr(callbackInst, "last_bytes", "d", LastBytes); setattr(callbackInst, "current_cps", "d", CurrentCPS); @@ -496,6 +502,7 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) if (result == NULL) { std::cerr << "waitChild method invalid" << std::endl; PyErr_Print(); + PyCbObj_BEGIN_ALLOW_THREADS return pkgPackageManager::Failed; } if(!PyArg_Parse(result, "i", &res) ) { -- cgit v1.2.3 From 2bb149489844096c55e9e90379795930171a6f73 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 27 Jan 2010 13:51:27 +0100 Subject: Drop the segfault prevention measures from the Acquire code, as they fail to work. A replacement will be added once destruction callbacks are added in APT. --- debian/changelog | 3 ++ python/acquire-item.cc | 48 +------------------ python/acquire.cc | 124 +++++++++++++------------------------------------ python/apt_pkgmodule.h | 1 + python/progress.cc | 47 ++++++++++--------- python/progress.h | 1 + 6 files changed, 64 insertions(+), 160 deletions(-) (limited to 'python/progress.cc') diff --git a/debian/changelog b/debian/changelog index 276f1e89..9b505a58 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,6 +12,9 @@ python-apt (0.7.93.1) UNRELEASED; urgency=low - Do not segfault if TarFile.go() is called without a member name. - Clone all pkgDirStream::Item's so apt_pkg.TarMember object can be used outside of the callback function passed to go(). + * Drop the segfault prevention measures from the Acquire code, as they fail + to work. A replacement will be added once destruction callbacks are added + in APT. -- Julian Andres Klode Sat, 23 Jan 2010 15:35:55 +0100 diff --git a/python/acquire-item.cc b/python/acquire-item.cc index 24780f1c..059f1802 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -28,22 +28,6 @@ using namespace std; - - -struct PyAcquireItems { - CppOwnedPyObject *file; - CppOwnedPyObject *item; - CppOwnedPyObject *desc; -}; - -typedef map item_map; - -// Keep a vector to PyAcquireItemObject pointers, so we can set the Object -// pointers to NULL when deallocating the main object (mostly AcquireFile). -struct PyAcquireObject : public CppPyObject { - item_map items; -}; - inline pkgAcquire::Item *acquireitem_tocpp(PyObject *self) { pkgAcquire::Item *itm = GetCpp(self); @@ -163,45 +147,18 @@ static PyObject *acquireitem_repr(PyObject *Self) pkgAcquire::Item *Itm = acquireitem_tocpp(Self); if (Itm == 0) return 0; - return PyString_FromFormat("<%s object: " "Status: %i Complete: %i Local: %i IsTrusted: %i " "FileSize: %lu DestFile:'%s' " "DescURI: '%s' ID:%lu ErrorText: '%s'>", Self->ob_type->tp_name, Itm->Status, Itm->Complete, Itm->Local, Itm->IsTrusted(), - Itm->FileSize, Itm->DestFile.c_str(), Itm->DescURI().c_str(), + Itm->FileSize, Itm->DestFile.c_str(), Itm->DescURI().c_str(), Itm->ID,Itm->ErrorText.c_str()); } static void acquireitem_dealloc(PyObject *self) { - pkgAcquire::Item *item = PyAcquireItem_ToCpp(self); - PyAcquireObject *Owner = (PyAcquireObject *)GetOwner(self); - if (Owner != NULL) { - PyAcquireItems item_struct = Owner->items[item]; - // TODO: Unregister the object in the owner. - if (!((CppOwnedPyObject*)self)->NoDelete) { - if (item_struct.file != 0 && item_struct.file != self) - item_struct.file->Object = 0; - if (item_struct.item != 0 && item_struct.item != self) { - item_struct.item->Object = 0; - Py_DECREF(item_struct.item); - } - if (item_struct.desc != 0) { - item_struct.desc->Object = 0; - Py_DECREF(item_struct.desc); - } - Owner->items.erase(item); - } - else { - if (item_struct.file == self) - item_struct.file = 0; - if (item_struct.item == self) - item_struct.item = 0; - } - } - CppOwnedDeallocPtr(self); } @@ -267,9 +224,6 @@ static PyObject *acquirefile_new(PyTypeObject *type, PyObject *Args, PyObject * destFile); // short-desc CppOwnedPyObject *AcqFileObj = CppOwnedPyObject_NEW(pyfetcher, type); AcqFileObj->Object = af; - - - ((PyAcquireObject *)pyfetcher)->items[af].file = AcqFileObj; return AcqFileObj; } diff --git a/python/acquire.cc b/python/acquire.cc index 789f994e..bcb76d67 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -30,43 +30,18 @@ #include -typedef CppOwnedPyObject PyAcquireWorkerObject; -struct PyAcquireItems { - CppOwnedPyObject *file; - CppOwnedPyObject *item; - CppOwnedPyObject *desc; -}; - -typedef map item_map; -typedef map worker_map; - -// Keep a vector to PyAcquireItemObject pointers, so we can set the Object -// pointers to NULL when deallocating the main object (mostly AcquireFile). -struct PyAcquireObject : public CppPyObject { - item_map items; - worker_map workers; -}; - - static PyObject *acquireworker_get_current_item(PyObject *self, void *closure) { pkgAcquire::Worker *worker = GetCpp(self); - - if (worker->CurrentItem == NULL) { + pkgAcquire::ItemDesc *desc = worker->CurrentItem; + if (desc == NULL) { Py_RETURN_NONE; } - - PyObject *PyAcquire = GetOwner(self); - - if (PyAcquire) - return PyAcquire_GetItemDesc(PyAcquire, worker->CurrentItem); - else { - PyObject *PyItem = PyAcquireItem_FromCpp(worker->CurrentItem->Owner); - PyObject *ret = PyAcquireItemDesc_FromCpp(worker->CurrentItem,false, - PyItem); - Py_DECREF(PyItem); - return ret; - } + PyObject *PyAcq = GetOwner(self); + PyObject *PyItem = PyAcquireItem_FromCpp(desc->Owner, false, PyAcq); + PyObject *PyDesc = PyAcquireItemDesc_FromCpp(desc, false, PyItem); + Py_XDECREF(PyItem); + return PyDesc; } static PyObject *acquireworker_get_status(PyObject *self, void *closure) @@ -134,17 +109,28 @@ PyTypeObject PyAcquireWorker_Type = { acquireworker_getset, // tp_getset }; + +static pkgAcquire::ItemDesc* acquireitemdesc_tocpp(PyObject *self) { + pkgAcquire::ItemDesc *item = GetCpp(self); + if (item == NULL) + PyErr_SetString(PyExc_ValueError, "Acquire has been shutdown"); + return item; +} + static PyObject *acquireitemdesc_get_uri(PyObject *self, void *closure) { - return CppPyString(GetCpp(self)->URI); + pkgAcquire::ItemDesc *item = acquireitemdesc_tocpp(self); + return item ? CppPyString(item->URI) : NULL; } static PyObject *acquireitemdesc_get_description(PyObject *self, void *closure) { - return CppPyString(GetCpp(self)->Description); + pkgAcquire::ItemDesc *item = acquireitemdesc_tocpp(self); + return item ? CppPyString(item->Description) : NULL; } static PyObject *acquireitemdesc_get_shortdesc(PyObject *self, void *closure) { - return CppPyString(GetCpp(self)->ShortDesc); + pkgAcquire::ItemDesc *item = acquireitemdesc_tocpp(self); + return item ? CppPyString(item->ShortDesc) : NULL; } static PyObject *acquireitemdesc_get_owner(CppOwnedPyObject *self, void *closure) { @@ -153,7 +139,7 @@ static PyObject *acquireitemdesc_get_owner(CppOwnedPyObjectOwner; } else if (self->Object) { - self->Owner = PyAcquireItem_FromCpp(self->Object->Owner); + self->Owner = PyAcquireItem_FromCpp(self->Object->Owner, false, NULL); Py_INCREF(self->Owner); return self->Owner; } @@ -214,31 +200,6 @@ PyTypeObject PyAcquireItemDesc_Type = { 0, // tp_new }; - -// Acquire - -PyObject *PyAcquire_GetItem(PyObject *self, pkgAcquire::Item *item) -{ - PyAcquireItems &item_struct = ((PyAcquireObject *)self)->items[item]; - if (! item_struct.item) { - item_struct.item = PyAcquireItem_FromCpp(item,false,self); - } - Py_INCREF(item_struct.item); - return item_struct.item; -} - -PyObject *PyAcquire_GetItemDesc(PyObject *self, pkgAcquire::ItemDesc *item) -{ - PyAcquireItems &item_struct = ((PyAcquireObject *)self)->items[item->Owner]; - if (! item_struct.item) - item_struct.item = PyAcquireItem_FromCpp(item->Owner,false,self); - if (! item_struct.desc) - item_struct.desc = PyAcquireItemDesc_FromCpp(item,false, - item_struct.item); - Py_INCREF(item_struct.desc); - return item_struct.desc; -} - static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args) { pkgAcquire *fetcher = GetCpp(Self); @@ -252,34 +213,19 @@ static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args) return HandleErrors(Py_BuildValue("i",run)); } + static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args) { pkgAcquire *fetcher = GetCpp(Self); - if (PyArg_ParseTuple(Args, "") == 0) return 0; - fetcher->Shutdown(); - - // TODO: Delete all objects here - item_map &items = ((PyAcquireObject *)Self)->items; - for (item_map::iterator I = items.begin(); I != items.end(); I++) { - if ((*I).second.file) - (*I).second.file->Object = NULL; - if ((*I).second.item) { - (*I).second.item->Object = NULL; - Py_DECREF((*I).second.item); - } - if ((*I).second.desc) { - (*I).second.desc->Object = NULL; - Py_DECREF((*I).second.desc); - } - } - items.clear(); 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"}, @@ -312,8 +258,7 @@ static PyObject *PkgAcquireGetWorkers(PyObject *self, void *closure) CppOwnedPyObject *PyWorker = NULL; for (pkgAcquire::Worker *Worker = Owner->WorkersBegin(); Worker != 0; Worker = Owner->WorkerStep(Worker)) { - PyWorker = CppOwnedPyObject_NEW(self,&PyAcquireWorker_Type, Worker); - PyWorker->NoDelete = true; + PyWorker = PyAcquireWorker_FromCpp(Worker, false, self); PyList_Append(List, PyWorker); Py_DECREF(PyWorker); } @@ -326,7 +271,7 @@ static PyObject *PkgAcquireGetItems(PyObject *Self,void*) PyObject *Obj; for (pkgAcquire::ItemIterator I = fetcher->ItemsBegin(); I != fetcher->ItemsEnd(); I++) { - Obj = PyAcquire_GetItem(Self, *I); + Obj = PyAcquireItem_FromCpp(*I, false, Self); PyList_Append(List,Obj); Py_DECREF(Obj); } @@ -368,14 +313,11 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) fetcher = new pkgAcquire(); } - PyAcquireObject *FetcherObj = (PyAcquireObject *) - CppPyObject_NEW(type, fetcher); + PyObject *FetcherObj = CppPyObject_NEW(type, fetcher); if (progress != 0) progress->setPyAcquire(FetcherObj); // prepare our map of items. - new (&FetcherObj->items) item_map(); - new (&FetcherObj->workers) worker_map(); return FetcherObj; } @@ -383,11 +325,9 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) * Create a new apt_pkg.Acquire Python object from the pkgAcquire object. */ PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete) { - PyAcquireObject *FetcherObj = (PyAcquireObject *)CppPyObject_NEW(&PyAcquire_Type, fetcher); - new (&FetcherObj->items) item_map(); - new (&FetcherObj->workers) worker_map(); - FetcherObj->NoDelete = (!Delete); - return FetcherObj; + CppPyObject *obj = CppPyObject_NEW(&PyAcquire_Type, fetcher); + obj->NoDelete = (!Delete); + return obj; } static char *doc_PkgAcquire = @@ -399,7 +339,7 @@ static char *doc_PkgAcquire = PyTypeObject PyAcquire_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "apt_pkg.Acquire", // tp_name - sizeof(PyAcquireObject), // tp_basicsize + sizeof(CppPyObject), // tp_basicsize 0, // tp_itemsize // Methods CppDeallocPtr, // tp_dealloc diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 5a5a6c6f..ec6cf10e 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -123,6 +123,7 @@ extern PyTypeObject PySystemLock_Type; extern PyTypeObject PyFileLock_Type; PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete); +PyObject *PyAcquireItem_FromCpp(pkgAcquire::Item *item, bool Delete, PyObject *owner); #include "python-apt.h" #endif diff --git a/python/progress.cc b/python/progress.cc index 0fc01085..b69149d5 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -17,7 +17,6 @@ #include "generic.h" #include "apt_pkgmodule.h" - /** * Set an attribute on an object, after creating the value with * Py_BuildValue(fmt, arg). Afterwards, decrease its refcount and return @@ -118,6 +117,16 @@ void PyOpProgress::Done() // apt interface +PyObject *PyFetchProgress::GetDesc(pkgAcquire::ItemDesc *item) { + if (!pyAcquire && item->Owner && item->Owner->GetOwner()) { + pyAcquire = PyAcquire_FromCpp(item->Owner->GetOwner(), false); + } + PyObject *pyItem = PyAcquireItem_FromCpp(item->Owner, false, pyAcquire); + PyObject *pyDesc = PyAcquireItemDesc_FromCpp(item, false, pyItem); + Py_DECREF(pyItem); + return pyDesc; +} + bool PyFetchProgress::MediaChange(string Media, string Drive) { PyCbObj_END_ALLOW_THREADS @@ -171,7 +180,7 @@ void PyFetchProgress::IMSHit(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_HasAttrString(callbackInst, "ims_hit")) - RunSimpleCallback("ims_hit", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); + RunSimpleCallback("ims_hit", TUPLEIZE(GetDesc(&Itm))); else UpdateStatus(Itm, DLHit); PyCbObj_BEGIN_ALLOW_THREADS @@ -181,7 +190,7 @@ void PyFetchProgress::Fetch(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_HasAttrString(callbackInst, "fetch")) - RunSimpleCallback("fetch", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); + RunSimpleCallback("fetch", TUPLEIZE(GetDesc(&Itm))); else UpdateStatus(Itm, DLQueued); PyCbObj_BEGIN_ALLOW_THREADS @@ -191,7 +200,7 @@ void PyFetchProgress::Done(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_HasAttrString(callbackInst, "done")) - RunSimpleCallback("done", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); + RunSimpleCallback("done", TUPLEIZE(GetDesc(&Itm))); else UpdateStatus(Itm, DLDone); PyCbObj_BEGIN_ALLOW_THREADS @@ -201,7 +210,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) { PyCbObj_END_ALLOW_THREADS if (PyObject_HasAttrString(callbackInst, "fail")) { - RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); + RunSimpleCallback("fail", TUPLEIZE(GetDesc(&Itm))); PyCbObj_BEGIN_ALLOW_THREADS return; } @@ -219,7 +228,7 @@ void PyFetchProgress::Fail(pkgAcquire::ItemDesc &Itm) if (PyObject_HasAttrString(callbackInst, "fail")) - RunSimpleCallback("fail", TUPLEIZE(PyAcquire_GetItemDesc(pyAcquire, &Itm))); + RunSimpleCallback("fail", TUPLEIZE(GetDesc(&Itm))); else UpdateStatus(Itm, DLFailed); PyCbObj_BEGIN_ALLOW_THREADS @@ -279,24 +288,15 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) setattr(callbackInst, "elapsed_time", "k", ElapsedTime); setattr(callbackInst, "current_items", "k", CurrentItems); setattr(callbackInst, "total_items", "k", TotalItems); -#ifdef COMPAT_0_7 - setattr(callbackInst, "currentCPS", "d", CurrentCPS); - setattr(callbackInst, "currentBytes", "d", CurrentBytes); - setattr(callbackInst, "totalBytes", "d", TotalBytes); - setattr(callbackInst, "fetchedBytes", "d", FetchedBytes); - setattr(callbackInst, "currentItems", "k", CurrentItems); - setattr(callbackInst, "totalItems", "k", TotalItems); -#endif // New style -#ifdef COMPAT_0_7 if (!PyObject_HasAttrString(callbackInst, "updateStatus")) { -#else - { -#endif PyObject *result1; bool res1 = true; + if (pyAcquire == NULL) { + pyAcquire = PyAcquire_FromCpp(Owner, false); + } Py_INCREF(pyAcquire); if (RunSimpleCallback("pulse", TUPLEIZE(pyAcquire) , &result1)) { @@ -308,11 +308,14 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) } PyCbObj_BEGIN_ALLOW_THREADS return true; - - - } #ifdef COMPAT_0_7 + setattr(callbackInst, "currentCPS", "d", CurrentCPS); + setattr(callbackInst, "currentBytes", "d", CurrentBytes); + setattr(callbackInst, "totalBytes", "d", TotalBytes); + setattr(callbackInst, "fetchedBytes", "d", FetchedBytes); + setattr(callbackInst, "currentItems", "k", CurrentItems); + setattr(callbackInst, "totalItems", "k", TotalItems); // Go through the list of items and add active items to the // activeItems vector. map activeItemMap; @@ -401,6 +404,8 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) PyCbObj_BEGIN_ALLOW_THREADS // fetching can be canceld by returning false return res; +#else + return false; #endif } diff --git a/python/progress.h b/python/progress.h index 7e75652b..4e66c771 100644 --- a/python/progress.h +++ b/python/progress.h @@ -64,6 +64,7 @@ struct PyFetchProgress : public pkgAcquireStatus, public PyCallbackObj { protected: PyObject *pyAcquire; + PyObject *GetDesc(pkgAcquire::ItemDesc *item); public: enum { DLDone, DLQueued, DLFailed, DLHit, DLIgnored -- cgit v1.2.3 From 3827ac6144cc4beda932a7602e66e4286a3e4265 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 2 Feb 2010 17:59:22 +0100 Subject: python: Update PyAcquire_FromCpp to the new API rules (add Owner parameter). --- python/acquire.cc | 4 ++-- python/apt_pkgmodule.h | 3 ++- python/progress.cc | 4 ++-- python/python-apt.h | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) (limited to 'python/progress.cc') diff --git a/python/acquire.cc b/python/acquire.cc index 04e00b02..5e22280e 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -324,8 +324,8 @@ static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) /** * Create a new apt_pkg.Acquire Python object from the pkgAcquire object. */ -PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete) { - CppPyObject *obj = CppPyObject_NEW(NULL, &PyAcquire_Type, fetcher); +PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete, PyObject *owner) { + CppPyObject *obj = CppPyObject_NEW(owner, &PyAcquire_Type, fetcher); obj->NoDelete = (!Delete); return obj; } diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index 3dcf8069..da647c3f 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -134,7 +134,7 @@ extern PyTypeObject PySystemLock_Type; extern PyTypeObject PyFileLock_Type; // Functions to be exported in the public API. -PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete); + # define PyAcquire_ToCpp GetCpp # define PyAcquireFile_ToCpp GetCpp # define PyAcquireItem_ToCpp GetCpp @@ -167,6 +167,7 @@ PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete); # define PyTagSection_ToCpp GetCpp # define PyVersion_ToCpp GetCpp +PyObject* PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete, PyObject *Owner); PyObject* PyAcquireFile_FromCpp(pkgAcqFile* const &obj, bool Delete, PyObject *Owner); PyObject* PyAcquireItem_FromCpp(pkgAcquire::Item* const &obj, bool Delete, PyObject *Owner); PyObject* PyAcquireItemDesc_FromCpp(pkgAcquire::ItemDesc* const &obj, bool Delete, PyObject *Owner); diff --git a/python/progress.cc b/python/progress.cc index b69149d5..bedad935 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -119,7 +119,7 @@ void PyOpProgress::Done() PyObject *PyFetchProgress::GetDesc(pkgAcquire::ItemDesc *item) { if (!pyAcquire && item->Owner && item->Owner->GetOwner()) { - pyAcquire = PyAcquire_FromCpp(item->Owner->GetOwner(), false); + pyAcquire = PyAcquire_FromCpp(item->Owner->GetOwner(), false, NULL); } PyObject *pyItem = PyAcquireItem_FromCpp(item->Owner, false, pyAcquire); PyObject *pyDesc = PyAcquireItemDesc_FromCpp(item, false, pyItem); @@ -295,7 +295,7 @@ bool PyFetchProgress::Pulse(pkgAcquire * Owner) bool res1 = true; if (pyAcquire == NULL) { - pyAcquire = PyAcquire_FromCpp(Owner, false); + pyAcquire = PyAcquire_FromCpp(Owner, false, NULL); } Py_INCREF(pyAcquire); diff --git a/python/python-apt.h b/python/python-apt.h index 0c25ff02..b9fc9212 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -43,7 +43,7 @@ typedef pkgDepCache::ActionGroup*& ActionGroupT(PyObject *self); struct _PyAptPkgAPIStruct { // apt_pkg.Acquire (pkgAcquire*) PyTypeObject *acquire_type; - PyObject* (*acquire_fromcpp)(pkgAcquire *acquire, bool Delete); + PyObject* (*acquire_fromcpp)(pkgAcquire *acquire, bool Delete, PyObject*); pkgAcquire*& (*acquire_tocpp)(PyObject *self); // apt_pkg.AcquireFile PyTypeObject *acquirefile_type; -- cgit v1.2.3 From 478a5ebf8c3e7bb4b17981e51d6341309bba3df6 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 17 Feb 2010 17:27:59 +0100 Subject: * python/progress.cc: - try to call compatibility functions first, then new functions --- debian/changelog | 2 ++ python/progress.cc | 45 ++++++++++++++++++++++----------------------- 2 files changed, 24 insertions(+), 23 deletions(-) (limited to 'python/progress.cc') diff --git a/debian/changelog b/debian/changelog index 8c488e0b..ddb94ecf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -30,6 +30,8 @@ python-apt (0.7.93.2) UNRELEASED; urgency=low * 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 Sun, 07 Feb 2010 19:58:40 +0100 diff --git a/python/progress.cc b/python/progress.cc index bedad935..ee8f9348 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) @@ -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,8 +573,17 @@ 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("ask_cdrom_name", 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; @@ -583,15 +592,5 @@ bool PyCdromProgress::AskCdromName(string &Name) 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; } } -- cgit v1.2.3 From 8c2fa71d625189bf848b32e8da9b6e562751dadc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 17 Feb 2010 17:35:17 +0100 Subject: python/progress.cc: more compat fixes --- python/progress.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'python/progress.cc') diff --git a/python/progress.cc b/python/progress.cc index ee8f9348..18081690 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -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) @@ -575,7 +575,7 @@ bool PyCdromProgress::AskCdromName(string &Name) // Old style: (True, name) on success, (False, name) on failure. if (PyObject_HasAttrString(callbackInst, "askAdromName")) { - RunSimpleCallback("ask_cdrom_name", arglist, &result); + 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 @@ -588,7 +588,7 @@ bool PyCdromProgress::AskCdromName(string &Name) 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; -- cgit v1.2.3 From 62a7342edb16c38e3d646cc731a4a50ad6657b4f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 9 Mar 2010 14:15:47 +0100 Subject: python/generic.cc: use std::string instead of string --- python/generic.cc | 4 ++-- python/progress.cc | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'python/progress.cc') diff --git a/python/generic.cc b/python/generic.cc index 640f0862..b0770e02 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -31,11 +31,11 @@ PyObject *HandleErrors(PyObject *Res) Py_DECREF(Res); } - string Err; + std::string Err; int errcnt = 0; while (_error->empty() == false) { - string Msg; + std::string Msg; bool Type = _error->PopMessage(Msg); if (errcnt > 0) Err.append(", "); diff --git a/python/progress.cc b/python/progress.cc index 18081690..097f06cf 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -491,7 +491,6 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) StartUpdate(); - PyCbObj_END_ALLOW_THREADS if(PyObject_HasAttrString(callbackInst, "waitChild") || PyObject_HasAttrString(callbackInst, "wait_child")) { -- cgit v1.2.3