def download(self): LOG.info('Downloading using urllib2: %s to %s.', colorizer.quote(self.uri), colorizer.quote(self.store_where)) p_bar = None def update_bar(progress_bar, bytes_down): if progress_bar: progress_bar.update(bytes_down) try: with contextlib.closing( urllib2.urlopen(self.uri, timeout=self.timeout)) as conn: c_len = conn.headers.get('content-length') if c_len is not None: try: p_bar = self._make_bar(int(c_len)) p_bar.start() except ValueError: pass with open(self.store_where, 'wb') as ofh: return (self.store_where, sh.pipe_in_out(conn, ofh, chunk_cb=functools.partial( update_bar, p_bar))) finally: if p_bar: p_bar.finish()
def download(self): LOG.info('Downloading using urllib2: %s to %s.', colorizer.quote(self.uri), colorizer.quote(self.store_where)) p_bar = None def update_bar(progress_bar, bytes_down): if progress_bar: progress_bar.update(bytes_down) try: with contextlib.closing(urllib2.urlopen(self.uri, timeout=self.timeout)) as conn: c_len = conn.headers.get('content-length') if c_len is not None: try: p_bar = self._make_bar(int(c_len)) p_bar.start() except ValueError: pass with open(self.store_where, 'wb') as ofh: return (self.store_where, sh.pipe_in_out(conn, ofh, chunk_cb=functools.partial(update_bar, p_bar))) finally: if p_bar: p_bar.finish()
def _unpack_tar_member(self, tarhandle, member, output_location): LOG.info("Extracting %s to %s.", colorizer.quote(member.name), colorizer.quote(output_location)) with contextlib.closing(tarhandle.extractfile(member)) as mfh: with open(output_location, "wb") as ofh: return sh.pipe_in_out(mfh, ofh)