summaryrefslogtreecommitdiff
path: root/apt/progress/gtk2.py
diff options
context:
space:
mode:
Diffstat (limited to 'apt/progress/gtk2.py')
-rw-r--r--apt/progress/gtk2.py240
1 files changed, 159 insertions, 81 deletions
diff --git a/apt/progress/gtk2.py b/apt/progress/gtk2.py
index f872e34f..acb01eed 100644
--- a/apt/progress/gtk2.py
+++ b/apt/progress/gtk2.py
@@ -11,7 +11,7 @@
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
-# his program is distributed in the hope that it will be useful,
+# 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.
@@ -22,7 +22,6 @@
# USA
"""GObject-powered progress classes and a GTK+ status widget."""
-from gettext import gettext as _
import os
import time
@@ -37,8 +36,17 @@ import gobject
import pango
import vte
-import apt
import apt_pkg
+from apt_pkg import gettext as _
+from apt.deprecation import function_deprecated_by, AttributeDeprecatedBy
+from apt.progress import base
+
+if apt_pkg._COMPAT_0_7:
+ from apt.progress import old
+
+
+__all__ = ['GAcquireProgress', 'GInstallProgress', 'GOpProgress',
+ 'GtkAptProgress']
def mksig(params=(), run=gobject.SIGNAL_RUN_FIRST, rettype=gobject.TYPE_NONE):
@@ -52,7 +60,7 @@ def mksig(params=(), run=gobject.SIGNAL_RUN_FIRST, rettype=gobject.TYPE_NONE):
return (run, rettype, params)
-class GOpProgress(gobject.GObject, apt.progress.OpProgress):
+class GOpProgress(gobject.GObject, base.OpProgress):
"""Operation progress with GObject signals.
Signals:
@@ -68,22 +76,28 @@ class GOpProgress(gobject.GObject, apt.progress.OpProgress):
"status-finished": mksig()}
def __init__(self):
- apt.progress.OpProgress.__init__(self)
+ base.OpProgress.__init__(self)
gobject.GObject.__init__(self)
self._context = glib.main_context_default()
- def update(self, percent):
+ def update(self, percent=None):
"""Called to update the percentage done"""
- self.emit("status-changed", self.op, percent)
+ base.OpProgress.update(self, percent)
+ self.emit("status-changed", self.op, self.percent)
while self._context.pending():
self._context.iteration()
def done(self):
"""Called when all operation have finished."""
+ base.OpProgress.done(self)
self.emit("status-finished")
+ if apt_pkg._COMPAT_0_7:
+ subOp = AttributeDeprecatedBy('subop')
+ Op = AttributeDeprecatedBy('op')
-class GInstallProgress(gobject.GObject, apt.progress.InstallProgress):
+
+class GInstallProgress(gobject.GObject, base.InstallProgress):
"""Installation progress with GObject signals.
Signals:
@@ -107,19 +121,20 @@ class GInstallProgress(gobject.GObject, apt.progress.InstallProgress):
"status-finished": mksig()}
def __init__(self, term):
- apt.progress.InstallProgress.__init__(self)
+ base.InstallProgress.__init__(self)
gobject.GObject.__init__(self)
self.finished = False
+ self.apt_status = -1
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 +153,31 @@ 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 run(self, obj):
+ """Run."""
+ self.finished = False
+ return base.InstallProgress.run(self, obj)
+
+ def finish_update(self):
"""Called when the update finished.
Emits: status-finished()
"""
self.emit("status-finished")
- def statusChange(self, pkg, percent, status):
+ def processing(self, pkg, stage):
+ """Called when entering a new stage in dpkg."""
+ # We have no percentage or alike, send -1 to let the bar pulse.
+ self.emit("status-changed", ("Installing %s...") % pkg, -1)
+
+ def status_change(self, pkg, percent, status):
"""Called when the status changed.
Emits: status-changed(status, percent)
@@ -160,12 +185,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)
+ base.InstallProgress.update_interface(self)
while self._context.pending():
self._context.iteration()
if self.time_last_update + self.INSTALL_TIMEOUT < time.time():
@@ -175,40 +200,25 @@ 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.
-
- Signals:
-
- * status-changed(str: status, int: percent)
- * status-started() - Not Implemented yet
- * status-finished()
- * status-timeout() - When the maintainer script hangs
- * status-error() - When an error happens
- * status-conffile() - On Conffile
- """
-
- def run(self, debfile):
- """Install the given package."""
- apt.progress.DpkgInstallProgress.run(self, debfile)
-
- def updateInterface(self):
- """Called periodically to update the interface.
- Emits: status-timeout() [When a timeout happens]"""
- apt.progress.DpkgInstallProgress.updateInterface(self)
- if self.time_last_update + self.INSTALL_TIMEOUT < time.time():
- self.emit("status-timeout")
+GDpkgInstallProgress = GInstallProgress
-class GFetchProgress(gobject.GObject, apt.progress.FetchProgress):
+class GAcquireProgress(gobject.GObject, base.AcquireProgress):
"""A Fetch Progress with GObject signals.
Signals:
@@ -216,6 +226,8 @@ class GFetchProgress(gobject.GObject, apt.progress.FetchProgress):
* status-changed(str: description, int: percent)
* status-started()
* status-finished()
+
+ DEPRECATED.
"""
__gsignals__ = {"status-changed": mksig((str, int)),
@@ -223,40 +235,98 @@ class GFetchProgress(gobject.GObject, apt.progress.FetchProgress):
"status-finished": mksig()}
def __init__(self):
- apt.progress.FetchProgress.__init__(self)
+ base.AcquireProgress.__init__(self)
gobject.GObject.__init__(self)
self._continue = True
self._context = glib.main_context_default()
def start(self):
+ base.AcquireProgress.start(self)
self.emit("status-started")
def stop(self):
+ base.AcquireProgress.stop(self)
self.emit("status-finished")
def cancel(self):
self._continue = False
- def pulse(self):
- apt.progress.FetchProgress.pulse(self)
- currentItem = self.currentItems + 1
- if currentItem > self.totalItems:
- currentItem = self.totalItems
- if self.currentCPS > 0:
+ def pulse(self, owner):
+ base.AcquireProgress.pulse(self, owner)
+ 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.SizeToStr(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})
- self.emit("status-changed", text, self.percent)
+ {"current": current_item,
+ "total": self.total_items})
+
+ percent = (((self.current_bytes + self.current_items) * 100.0) /
+ float(self.total_bytes + self.total_items))
+ self.emit("status-changed", text, percent)
while self._context.pending():
self._context.iteration()
return self._continue
+if apt_pkg._COMPAT_0_7:
+
+ class GFetchProgress(gobject.GObject, old.FetchProgress):
+ """A Fetch Progress with GObject signals.
+
+ Signals:
+
+ * status-changed(str: description, int: percent)
+ * status-started()
+ * status-finished()
+
+ DEPRECATED.
+ """
+
+ __gsignals__ = {"status-changed": mksig((str, int)),
+ "status-started": mksig(),
+ "status-finished": mksig()}
+
+ def __init__(self):
+ old.FetchProgress.__init__(self)
+ gobject.GObject.__init__(self)
+ self._continue = True
+ self._context = glib.main_context_default()
+
+ def start(self):
+ self.emit("status-started")
+
+ def stop(self):
+ self.emit("status-finished")
+
+ def cancel(self):
+ self._continue = False
+
+ def pulse(self):
+ old.FetchProgress.pulse(self)
+ current_item = self.currentItems + 1
+ if current_item > self.totalItems:
+ current_item = self.totalItems
+ if self.current_cps > 0:
+ text = (_("Downloading file %(current)li of %(total)li with "
+ "%(speed)s/s") % \
+ {"current": current_item,
+ "total": self.totalItems,
+ "speed": apt_pkg.size_to_str(self.currentCPS)})
+ else:
+ text = (_("Downloading file %(current)li of %(total)li") % \
+ {"current": current_item,
+ "total": self.totalItems})
+ self.emit("status-changed", text, self.percent)
+ while self._context.pending():
+ self._context.iteration()
+ return self._continue
+
class GtkAptProgress(gtk.VBox):
"""Graphical progress for installation/fetch/operations.
@@ -291,11 +361,15 @@ class GtkAptProgress(gtk.VBox):
self._progress_open.connect("status-started", self._on_status_started)
self._progress_open.connect("status-finished",
self._on_status_finished)
- self._progress_fetch = GFetchProgress()
- self._progress_fetch.connect("status-changed", self._on_status_changed)
- self._progress_fetch.connect("status-started", self._on_status_started)
- self._progress_fetch.connect("status-finished",
+ self._progress_acquire = GAcquireProgress()
+ self._progress_acquire.connect("status-changed",
+ self._on_status_changed)
+ self._progress_acquire.connect("status-started",
+ self._on_status_started)
+ self._progress_acquire.connect("status-finished",
self._on_status_finished)
+
+ self._progress_fetch = None
self._progress_install = GInstallProgress(self._terminal)
self._progress_install.connect("status-changed",
self._on_status_changed)
@@ -309,19 +383,6 @@ class GtkAptProgress(gtk.VBox):
self._on_status_timeout)
self._progress_install.connect("status-conffile",
self._on_status_timeout)
- self._progress_dpkg_install = GDpkgInstallProgress(self._terminal)
- self._progress_dpkg_install.connect("status-changed",
- self._on_status_changed)
- self._progress_dpkg_install.connect("status-started",
- self._on_status_started)
- self._progress_dpkg_install.connect("status-finished",
- self._on_status_finished)
- self._progress_dpkg_install.connect("status-timeout",
- self._on_status_timeout)
- self._progress_dpkg_install.connect("status-error",
- self._on_status_timeout)
- self._progress_dpkg_install.connect("status-conffile",
- self._on_status_timeout)
def clear(self):
"""Reset all status information."""
@@ -342,12 +403,27 @@ class GtkAptProgress(gtk.VBox):
@property
def dpkg_install(self):
"""Return the install progress handler for dpkg."""
- return self._dpkg_progress_install
+ return self._progress_install
+
+ if apt_pkg._COMPAT_0_7:
+
+ @property
+ def fetch(self):
+ """Return the fetch progress handler."""
+ if self._progress_fetch is None:
+ self._progress_fetch = GFetchProgress()
+ self._progress_fetch.connect("status-changed",
+ self._on_status_changed)
+ self._progress_fetch.connect("status-started",
+ self._on_status_started)
+ self._progress_fetch.connect("status-finished",
+ self._on_status_finished)
+ return self._progress_fetch
@property
- def fetch(self):
- """Return the fetch progress handler."""
- return self._progress_fetch
+ def acquire(self):
+ """Return the acquire progress handler."""
+ return self._progress_acquire
def _on_status_started(self, progress):
"""Called when something starts."""
@@ -364,7 +440,7 @@ class GtkAptProgress(gtk.VBox):
def _on_status_changed(self, progress, status, percent):
"""Called when the status changed."""
self._label.set_text(status)
- if percent is None:
+ if percent is None or percent == -1:
self._progressbar.pulse()
else:
self._progressbar.set_fraction(percent/100.0)
@@ -412,6 +488,7 @@ def _test():
"""Test function"""
import sys
+ import apt
from apt.debfile import DebPackage
win = gtk.Window()
@@ -422,18 +499,19 @@ def _test():
win.show()
cache = apt.cache.Cache(apt_progress.open)
pkg = cache["xterm"]
- if pkg.isInstalled:
- pkg.markDelete()
+ if pkg.is_installed:
+ pkg.mark_delete()
else:
- pkg.markInstall()
+ pkg.mark_install()
apt_progress.show_terminal(True)
try:
- cache.commit(apt_progress.fetch, apt_progress.install)
+ cache.commit(apt_progress.acquire, apt_progress.install)
except Exception, exc:
print >> sys.stderr, "Exception happened:", exc
if len(sys.argv) > 1:
deb = DebPackage(sys.argv[1], cache)
deb.install(apt_progress.dpkg_install)
+ win.connect("destroy", gtk.main_quit)
gtk.main()