mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
* ubuntutools.archive:
- Add quiet option to silence downloading. - Use wget-style progress bar (fixed width) (LP: #845787)
This commit is contained in:
commit
98f0ba6bb1
3
debian/changelog
vendored
3
debian/changelog
vendored
@ -22,6 +22,9 @@ ubuntu-dev-tools (0.131) UNRELEASED; urgency=low
|
||||
(LP: #841975)
|
||||
- Use apt-get rather than aptitude.
|
||||
* Removed get-build-deps, mk-build-deps -ir is equivalent (LP: #158108)
|
||||
* ubuntutools.archive:
|
||||
- Add quiet option to silence downloading.
|
||||
- Use wget-style progress bar (fixed width) (LP: #845787)
|
||||
|
||||
[ Colin Watson ]
|
||||
* syncpackage: Fix typo.
|
||||
|
@ -128,7 +128,7 @@ class SourcePackage(object):
|
||||
distribution = None
|
||||
|
||||
def __init__(self, package=None, version=None, component=None,
|
||||
dscfile=None, lp=None, mirrors=(), workdir='.'):
|
||||
dscfile=None, lp=None, mirrors=(), workdir='.', quiet=False):
|
||||
"Can be initialised either using package, version or dscfile"
|
||||
assert ((package is not None and version is not None)
|
||||
or dscfile is not None)
|
||||
@ -136,6 +136,7 @@ class SourcePackage(object):
|
||||
self.source = package
|
||||
self._lp = lp
|
||||
self.workdir = workdir
|
||||
self.quiet = quiet
|
||||
|
||||
# Cached values:
|
||||
self._component = component
|
||||
@ -305,11 +306,7 @@ class SourcePackage(object):
|
||||
|
||||
def _download_file(self, url, filename):
|
||||
"Download url to filename in workdir."
|
||||
logurl = url
|
||||
if os.path.basename(url) != filename:
|
||||
logurl += ' -> ' + filename
|
||||
pathname = os.path.join(self.workdir, filename)
|
||||
if self.dsc:
|
||||
if self.dsc.verify_file(pathname):
|
||||
Logger.debug('Using existing %s', filename)
|
||||
return True
|
||||
@ -317,30 +314,39 @@ class SourcePackage(object):
|
||||
if entry['name'] == filename]
|
||||
assert len(size) == 1
|
||||
size = int(size[0])
|
||||
Logger.normal('Downloading %s (%0.3f MiB)', logurl,
|
||||
size / 1024.0 / 1024)
|
||||
else:
|
||||
Logger.normal('Downloading %s', logurl)
|
||||
host = urlparse.urlparse(url).hostname
|
||||
if not self.quiet:
|
||||
Logger.normal('Downloading %s from %s (%0.3f MiB)',
|
||||
filename, host, size / 1024.0 / 1024)
|
||||
|
||||
try:
|
||||
in_ = urllib2.build_opener().open(url)
|
||||
except urllib2.URLError:
|
||||
return False
|
||||
|
||||
downloaded = 0
|
||||
bar_width = 60
|
||||
try:
|
||||
with open(pathname, 'wb') as out:
|
||||
while True:
|
||||
block = in_.read(10240)
|
||||
if block == '':
|
||||
break
|
||||
downloaded += len(block)
|
||||
out.write(block)
|
||||
Logger.stdout.write('.')
|
||||
if not self.quiet:
|
||||
percent = downloaded * 100 // size
|
||||
bar = '=' * int(round(downloaded * bar_width / size))
|
||||
bar = (bar + '>' + ' ' * bar_width)[:bar_width]
|
||||
Logger.stdout.write('[%s] %#3i%%\r' % (bar, percent))
|
||||
Logger.stdout.flush()
|
||||
in_.close()
|
||||
Logger.stdout.write(' done\n')
|
||||
finally:
|
||||
if not self.quiet:
|
||||
Logger.stdout.write(' ' * (bar_width + 7) + '\r')
|
||||
Logger.stdout.flush()
|
||||
if self.dsc:
|
||||
if not self.dsc.verify_file(pathname):
|
||||
Logger.error('Checksum does not match.')
|
||||
Logger.error('Checksum for %s does not match.', filename)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user