Merge lp:~mvo/click/progressmeter into lp:~mvo/click/acquire

Proposed by Michael Vogt
Status: Needs review
Proposed branch: lp:~mvo/click/progressmeter
Merge into: lp:~mvo/click/acquire
Diff against target: 154 lines (+80/-4)
4 files modified
click/acquire.py (+69/-0)
click/commands/install.py (+2/-2)
debian/changelog (+7/-0)
debian/control (+2/-2)
To merge this branch: bzr merge lp:~mvo/click/progressmeter
Reviewer Review Type Date Requested Status
Michael Vogt Pending
Review via email: mp+243498@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

551. By Michael Vogt

cherry pick r570,r571 of lp:~snappy-dev/click/progressmeter (thanks to Barry Warsaw)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'click/acquire.py'
--- click/acquire.py 2014-10-14 12:52:49 +0000
+++ click/acquire.py 2014-12-03 08:34:01 +0000
@@ -25,15 +25,19 @@
25 'ClickAcquireMethodPycurl',25 'ClickAcquireMethodPycurl',
26 'ClickAcquireMethodUbuntuDownloadManager',26 'ClickAcquireMethodUbuntuDownloadManager',
27 'ClickAcquireStatus',27 'ClickAcquireStatus',
28 'ClickAcquireStatusMeter',
28 'ClickAcquireStatusText',29 'ClickAcquireStatusText',
29 ]30 ]
3031
31import os32import os
33import math
32import select34import select
33import subprocess35import subprocess
34import sys36import sys
35from textwrap import dedent37from textwrap import dedent
3638
39from progressbar import ProgressBar, Bar, Widget
40
37import apt_pkg41import apt_pkg
38from debian.deb822 import Deb82242from debian.deb822 import Deb822
39import dbus43import dbus
@@ -123,6 +127,71 @@
123 sys.stdout.write("Done fetching %s\n" % self.uri)127 sys.stdout.write("Done fetching %s\n" % self.uri)
124128
125129
130class FileSize(Widget):
131 def update(self, pbar):
132 value = pbar.maxval # or .currval?
133 if value < 1000:
134 return '{:3d} B '.format(int(value))
135 scale = int(math.log(value, 1000)) # or binary? e.g. MiB
136 try:
137 suffix = ' kMGTPEZY'[scale]
138 except IndexError:
139 # Should never happen, but still.
140 suffix = '!'
141 scaled_value = value // 1000 ** scale
142 return '{:3d} {:1s}B '.format(scaled_value, suffix)
143
144
145class OK(Widget):
146 def update(self, pbar):
147 if pbar.currval >= pbar.maxval:
148 return 'OK'
149 else:
150 return ' '
151
152SPACER = ' '
153
154class ClickAcquireStatusMeter(ClickAcquireStatus):
155 """Progress meter reporting for the acquire progress"""
156
157 # We have to defer creating the actual progress bar until its first use
158 # because the constructor doesn't get called with essential information
159 # (e.g. the uri and the total bytes). These get set after the fact but
160 # before the first call to .pulse(), so initialize the object there.
161 _progress = None
162
163 def pulse(self):
164 if self.total_bytes <= 1:
165 return
166 if self._progress is None:
167 # Massage the uri. Use the part to the right of the .click
168 # suffix, minus any version number.
169 base = os.path.basename(self.uri)
170 if base.startswith('com.ubuntu.snappy.'):
171 base = base[18:]
172 snap, _, extra = base.partition('_')
173 self._progress = ProgressBar(widgets=[
174 snap,
175 SPACER,
176 # XXX in the examples, it's unclear whether the size field
177 # should be the total size or the fetched size. Also, decimal
178 # (MB) or binary (MiB)? For now, we go with total size in
179 # decimal.
180 FileSize(),
181 SPACER,
182 Bar(marker='=', left='[', right=']'),
183 SPACER,
184 OK(),
185 SPACER,
186 ],
187 maxval=self.total_bytes)
188 self._progress.start()
189 self._progress.update(self.fetched_bytes)
190
191 def done(self):
192 self._progress.finish()
193
194
126# similar to Acquire/AcquireWorker195# similar to Acquire/AcquireWorker
127class ClickAcquire:196class ClickAcquire:
128 """Acquire from remote locations"""197 """Acquire from remote locations"""
129198
=== modified file 'click/commands/install.py'
--- click/commands/install.py 2014-09-15 14:02:27 +0000
+++ click/commands/install.py 2014-12-03 08:34:01 +0000
@@ -28,7 +28,7 @@
2828
29from click.acquire import (29from click.acquire import (
30 ClickAcquire,30 ClickAcquire,
31 ClickAcquireStatusText,31 ClickAcquireStatusMeter,
32)32)
33from click.install import ClickInstaller, ClickInstallerError33from click.install import ClickInstaller, ClickInstallerError
3434
@@ -68,7 +68,7 @@
68 if parsed_uri.scheme != "":68 if parsed_uri.scheme != "":
69 t = tempfile.NamedTemporaryFile()69 t = tempfile.NamedTemporaryFile()
70 package_path = t.name70 package_path = t.name
71 log = ClickAcquireStatusText()71 log = ClickAcquireStatusMeter()
72 acq = ClickAcquire(log)72 acq = ClickAcquire(log)
73 acq.fetch(package_uri, package_path)73 acq.fetch(package_uri, package_path)
74 else:74 else:
7575
=== modified file 'debian/changelog'
--- debian/changelog 2014-10-14 09:47:10 +0000
+++ debian/changelog 2014-12-03 08:34:01 +0000
@@ -1,3 +1,10 @@
1click (0.4.35+ppa17) UNRELEASED; urgency=medium
2
3 * click/acquire.py:
4 - progress meter
5
6 -- Barry Warsaw <barry@ubuntu.com> Tue, 02 Dec 2014 18:20:19 -0500
7
1click (0.4.34) UNRELEASED; urgency=medium8click (0.4.34) UNRELEASED; urgency=medium
29
3 [ Michael Vogt ]10 [ Michael Vogt ]
411
=== modified file 'debian/control'
--- debian/control 2014-10-14 13:55:38 +0000
+++ debian/control 2014-12-03 08:34:01 +0000
@@ -3,7 +3,7 @@
3Priority: optional3Priority: optional
4Maintainer: Colin Watson <cjwatson@ubuntu.com>4Maintainer: Colin Watson <cjwatson@ubuntu.com>
5Standards-Version: 3.9.55Standards-Version: 3.9.5
6Build-Depends: debhelper (>= 9~), dh-autoreconf, intltool, python3:any (>= 3.2), python3-all:any, python3-setuptools, python3-apt, python3-debian, python3-gi, python3:any (>= 3.3) | python3-mock, pep8, python3-pep8, pyflakes, python3-sphinx, pkg-config, valac, gobject-introspection (>= 0.6.7), libgirepository1.0-dev (>= 0.6.7), libglib2.0-dev (>= 2.34), gir1.2-glib-2.0, libjson-glib-dev (>= 0.10), libgee-0.8-dev, libpackagekit-glib2-dev (>= 0.7.2), python3-coverage, python3-six, dh-systemd (>= 1.3), python3-pycurl, python3-dbus6Build-Depends: debhelper (>= 9~), dh-autoreconf, intltool, python3:any (>= 3.2), python3-all:any, python3-setuptools, python3-apt, python3-debian, python3-gi, python3:any (>= 3.3) | python3-mock, pep8, python3-pep8, pyflakes, python3-sphinx, pkg-config, valac, gobject-introspection (>= 0.6.7), libgirepository1.0-dev (>= 0.6.7), libglib2.0-dev (>= 2.34), gir1.2-glib-2.0, libjson-glib-dev (>= 0.10), libgee-0.8-dev, libpackagekit-glib2-dev (>= 0.7.2), python3-coverage, python3-six, dh-systemd (>= 1.3), python3-pycurl, python3-dbus, python3-progressbar
7Vcs-Bzr: https://code.launchpad.net/~ubuntu-managed-branches/click/click7Vcs-Bzr: https://code.launchpad.net/~ubuntu-managed-branches/click/click
8Vcs-Browser: http://bazaar.launchpad.net/~ubuntu-managed-branches/click/click/files8Vcs-Browser: http://bazaar.launchpad.net/~ubuntu-managed-branches/click/click/files
9X-Auto-Uploader: no-rewrite-version9X-Auto-Uploader: no-rewrite-version
@@ -14,7 +14,7 @@
14Package: click14Package: click
15Architecture: any15Architecture: any
16Pre-Depends: ${misc:Pre-Depends}16Pre-Depends: ${misc:Pre-Depends}
17Depends: ${shlibs:Depends}, ${misc:Depends}, ${python3:Depends}, python3-click (= ${binary:Version}), adduser, python3-pycurl, python3-dbus17Depends: ${shlibs:Depends}, ${misc:Depends}, ${python3:Depends}, python3-click (= ${binary:Version}), adduser, python3-pycurl, python3-dbus, python3-progressbar
18Recommends: click-apparmor18Recommends: click-apparmor
19Suggests: click-reviewers-tools (>= 0.9), ubuntu-app-launch-tools | upstart-app-launch-tools19Suggests: click-reviewers-tools (>= 0.9), ubuntu-app-launch-tools | upstart-app-launch-tools
20Conflicts: click-package20Conflicts: click-package

Subscribers

People subscribed via source and target branches

to all changes: