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

Proposed by Michael Vogt on 2014-12-03
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 on 2014-12-03

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
1=== modified file 'click/acquire.py'
2--- click/acquire.py 2014-10-14 12:52:49 +0000
3+++ click/acquire.py 2014-12-03 08:34:01 +0000
4@@ -25,15 +25,19 @@
5 'ClickAcquireMethodPycurl',
6 'ClickAcquireMethodUbuntuDownloadManager',
7 'ClickAcquireStatus',
8+ 'ClickAcquireStatusMeter',
9 'ClickAcquireStatusText',
10 ]
11
12 import os
13+import math
14 import select
15 import subprocess
16 import sys
17 from textwrap import dedent
18
19+from progressbar import ProgressBar, Bar, Widget
20+
21 import apt_pkg
22 from debian.deb822 import Deb822
23 import dbus
24@@ -123,6 +127,71 @@
25 sys.stdout.write("Done fetching %s\n" % self.uri)
26
27
28+class FileSize(Widget):
29+ def update(self, pbar):
30+ value = pbar.maxval # or .currval?
31+ if value < 1000:
32+ return '{:3d} B '.format(int(value))
33+ scale = int(math.log(value, 1000)) # or binary? e.g. MiB
34+ try:
35+ suffix = ' kMGTPEZY'[scale]
36+ except IndexError:
37+ # Should never happen, but still.
38+ suffix = '!'
39+ scaled_value = value // 1000 ** scale
40+ return '{:3d} {:1s}B '.format(scaled_value, suffix)
41+
42+
43+class OK(Widget):
44+ def update(self, pbar):
45+ if pbar.currval >= pbar.maxval:
46+ return 'OK'
47+ else:
48+ return ' '
49+
50+SPACER = ' '
51+
52+class ClickAcquireStatusMeter(ClickAcquireStatus):
53+ """Progress meter reporting for the acquire progress"""
54+
55+ # We have to defer creating the actual progress bar until its first use
56+ # because the constructor doesn't get called with essential information
57+ # (e.g. the uri and the total bytes). These get set after the fact but
58+ # before the first call to .pulse(), so initialize the object there.
59+ _progress = None
60+
61+ def pulse(self):
62+ if self.total_bytes <= 1:
63+ return
64+ if self._progress is None:
65+ # Massage the uri. Use the part to the right of the .click
66+ # suffix, minus any version number.
67+ base = os.path.basename(self.uri)
68+ if base.startswith('com.ubuntu.snappy.'):
69+ base = base[18:]
70+ snap, _, extra = base.partition('_')
71+ self._progress = ProgressBar(widgets=[
72+ snap,
73+ SPACER,
74+ # XXX in the examples, it's unclear whether the size field
75+ # should be the total size or the fetched size. Also, decimal
76+ # (MB) or binary (MiB)? For now, we go with total size in
77+ # decimal.
78+ FileSize(),
79+ SPACER,
80+ Bar(marker='=', left='[', right=']'),
81+ SPACER,
82+ OK(),
83+ SPACER,
84+ ],
85+ maxval=self.total_bytes)
86+ self._progress.start()
87+ self._progress.update(self.fetched_bytes)
88+
89+ def done(self):
90+ self._progress.finish()
91+
92+
93 # similar to Acquire/AcquireWorker
94 class ClickAcquire:
95 """Acquire from remote locations"""
96
97=== modified file 'click/commands/install.py'
98--- click/commands/install.py 2014-09-15 14:02:27 +0000
99+++ click/commands/install.py 2014-12-03 08:34:01 +0000
100@@ -28,7 +28,7 @@
101
102 from click.acquire import (
103 ClickAcquire,
104- ClickAcquireStatusText,
105+ ClickAcquireStatusMeter,
106 )
107 from click.install import ClickInstaller, ClickInstallerError
108
109@@ -68,7 +68,7 @@
110 if parsed_uri.scheme != "":
111 t = tempfile.NamedTemporaryFile()
112 package_path = t.name
113- log = ClickAcquireStatusText()
114+ log = ClickAcquireStatusMeter()
115 acq = ClickAcquire(log)
116 acq.fetch(package_uri, package_path)
117 else:
118
119=== modified file 'debian/changelog'
120--- debian/changelog 2014-10-14 09:47:10 +0000
121+++ debian/changelog 2014-12-03 08:34:01 +0000
122@@ -1,3 +1,10 @@
123+click (0.4.35+ppa17) UNRELEASED; urgency=medium
124+
125+ * click/acquire.py:
126+ - progress meter
127+
128+ -- Barry Warsaw <barry@ubuntu.com> Tue, 02 Dec 2014 18:20:19 -0500
129+
130 click (0.4.34) UNRELEASED; urgency=medium
131
132 [ Michael Vogt ]
133
134=== modified file 'debian/control'
135--- debian/control 2014-10-14 13:55:38 +0000
136+++ debian/control 2014-12-03 08:34:01 +0000
137@@ -3,7 +3,7 @@
138 Priority: optional
139 Maintainer: Colin Watson <cjwatson@ubuntu.com>
140 Standards-Version: 3.9.5
141-Build-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
142+Build-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
143 Vcs-Bzr: https://code.launchpad.net/~ubuntu-managed-branches/click/click
144 Vcs-Browser: http://bazaar.launchpad.net/~ubuntu-managed-branches/click/click/files
145 X-Auto-Uploader: no-rewrite-version
146@@ -14,7 +14,7 @@
147 Package: click
148 Architecture: any
149 Pre-Depends: ${misc:Pre-Depends}
150-Depends: ${shlibs:Depends}, ${misc:Depends}, ${python3:Depends}, python3-click (= ${binary:Version}), adduser, python3-pycurl, python3-dbus
151+Depends: ${shlibs:Depends}, ${misc:Depends}, ${python3:Depends}, python3-click (= ${binary:Version}), adduser, python3-pycurl, python3-dbus, python3-progressbar
152 Recommends: click-apparmor
153 Suggests: click-reviewers-tools (>= 0.9), ubuntu-app-launch-tools | upstart-app-launch-tools
154 Conflicts: click-package

Subscribers

People subscribed via source and target branches

to all changes: