diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-07-31 15:02:12 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-07-31 15:02:12 +0200 |
| commit | dd85685eb9c2a3ce4392b581818d4ac84410f296 (patch) | |
| tree | 148b647dd88ba91df98d6e8eba0c9ffc2601755a /apt/progress/text.py | |
| parent | e3653ead6554eafb9eb3327708944f30171aed6c (diff) | |
| download | python-apt-dd85685eb9c2a3ce4392b581818d4ac84410f296.tar.gz | |
apt/progress/base.py: Introduce new base progress classes.
Also adjust the class in apt/progress/text.py to derive from this
instead of the classes in apt_pkg (which will be dropped).
Diffstat (limited to 'apt/progress/text.py')
| -rw-r--r-- | apt/progress/text.py | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/apt/progress/text.py b/apt/progress/text.py index c9e2882b..54a35704 100644 --- a/apt/progress/text.py +++ b/apt/progress/text.py @@ -18,8 +18,9 @@ import sys import apt_pkg +import apt.progress.base -__all__ = ['AcquireProgress', 'OpProgress'] +__all__ = ['AcquireProgress', 'CdromProgress', 'OpProgress'] def _(msg): @@ -54,7 +55,7 @@ class TextProgress(object): self._file.flush() -class OpProgress(apt_pkg.OpProgress, TextProgress): +class OpProgress(apt.progress.base.OpProgress, TextProgress): """Operation progress reporting. This closely resembles OpTextProgress in libapt-pkg. @@ -62,14 +63,12 @@ class OpProgress(apt_pkg.OpProgress, TextProgress): def __init__(self, outfile=None): TextProgress.__init__(self, outfile) - apt_pkg.OpProgress.__init__(self) + apt.progress.base.OpProgress.__init__(self) self.old_op = "" def update(self, percent=None): """Called periodically to update the user interface.""" - if percent: - self.percent = percent - apt_pkg.OpProgress.update(self) + apt.progress.base.OpProgress.update(self, percent) if self.major_change and self.old_op: self._write(self.old_op) self._write("%s... %i%%\r" % (self.op, self.percent), False, True) @@ -77,18 +76,18 @@ class OpProgress(apt_pkg.OpProgress, TextProgress): def done(self): """Called once an operation has been completed.""" - apt_pkg.OpProgress.done(self) + apt.progress.base.OpProgress.done(self) if self.old_op: self._write(_("%c%s... Done") % ('\r', self.old_op), True, True) self.old_op = "" -class AcquireProgress(apt_pkg.AcquireProgress, TextProgress): +class AcquireProgress(apt.progress.base.AcquireProgress, TextProgress): """AcquireProgress for the text interface.""" def __init__(self, outfile=None): TextProgress.__init__(self, outfile) - apt_pkg.AcquireProgress.__init__(self) + apt.progress.base.AcquireProgress.__init__(self) self._signal = None self._width = 80 self._id = 1 @@ -99,7 +98,7 @@ class AcquireProgress(apt_pkg.AcquireProgress, TextProgress): In this case, the function sets up a signal handler for SIGWINCH, i.e. window resize signals. And it also sets id to 1. """ - apt_pkg.AcquireProgress.start(self) + apt.progress.base.AcquireProgress.start(self) import signal self._signal = signal.signal(signal.SIGWINCH, self._winch) # Get the window size. @@ -117,7 +116,7 @@ class AcquireProgress(apt_pkg.AcquireProgress, TextProgress): def ims_hit(self, item): """Called when an item is update (e.g. not modified on the server).""" - apt_pkg.AcquireProgress.ims_hit(self, item) + apt.progress.base.AcquireProgress.ims_hit(self, item) line = _('Hit ') + item.description if item.owner.filesize: line += ' [%sB]' % apt_pkg.size_to_str(item.owner.filesize) @@ -125,7 +124,7 @@ class AcquireProgress(apt_pkg.AcquireProgress, TextProgress): def fail(self, item): """Called when an item is failed.""" - apt_pkg.AcquireProgress.fail(self, item) + apt.progress.base.AcquireProgress.fail(self, item) if item.owner.status == item.owner.stat_done: self._write(_("Ign ") + item.description) else: @@ -134,7 +133,7 @@ class AcquireProgress(apt_pkg.AcquireProgress, TextProgress): def fetch(self, item): """Called when some of the item's data is fetched.""" - apt_pkg.AcquireProgress.fetch(self, item) + apt.progress.base.AcquireProgress.fetch(self, item) # It's complete already (e.g. Hit) if item.owner.complete: return @@ -150,7 +149,7 @@ class AcquireProgress(apt_pkg.AcquireProgress, TextProgress): """Periodically invoked while the Acquire process is underway. Return False if the user asked to cancel the whole Acquire process.""" - apt_pkg.AcquireProgress.pulse(self, owner) + apt.progress.base.AcquireProgress.pulse(self, owner) percent = (((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) @@ -210,7 +209,7 @@ class AcquireProgress(apt_pkg.AcquireProgress, TextProgress): def media_change(self, medium, drive): """Prompt the user to change the inserted removable media.""" - apt_pkg.AcquireProgress.media_change(self, medium, drive) + apt.progress.base.AcquireProgress.media_change(self, medium, drive) self._write(_("Media change: please insert the disc labeled\n" " '%s'\n" "in the drive '%s' and press enter\n") % (medium, drive)) @@ -218,7 +217,7 @@ class AcquireProgress(apt_pkg.AcquireProgress, TextProgress): def stop(self): """Invoked when the Acquire process stops running.""" - apt_pkg.AcquireProgress.stop(self) + apt.progress.base.AcquireProgress.stop(self) # Trick for getting a translation from apt self._write((_("Fetched %sB in %s (%sB/s)\n") % ( apt_pkg.size_to_str(self.fetched_bytes), @@ -230,12 +229,12 @@ class AcquireProgress(apt_pkg.AcquireProgress, TextProgress): signal.signal(signal.SIGWINCH, self._signal) -class CdromProgress(apt_pkg.CdromProgress, TextProgress): +class CdromProgress(apt.progress.base.CdromProgress, TextProgress): """Text CD-ROM progress.""" def ask_cdrom_name(self): """Ask the user to provide a name for the disc.""" - apt_pkg.CdromProgress.ask_cdrom_name(self) + apt.progress.base.CdromProgress.ask_cdrom_name(self) self._write(_("Please provide a name for this Disc, such as " "'Debian 2.1r1 Disk 1'"), False) try: @@ -245,13 +244,13 @@ class CdromProgress(apt_pkg.CdromProgress, TextProgress): def update(self, text, current): """Set the current progress.""" - apt_pkg.CdromProgress.update(self, text, current) + apt.progress.base.CdromProgress.update(self, text, current) if text: self._write(text, False) def change_cdrom(self): """Ask the user to change the CD-ROM.""" - apt_pkg.CdromProgress.change_cdrom(self) + apt.progress.base.CdromProgress.change_cdrom(self) self._write(_("Please insert a Disc in the drive and press enter"), False) try: |
