Ejemplo n.º 1
0
 def _download(self, from_info, to_file, name=None, no_progress_bar=False):
     response = self._request("GET", from_info.url, stream=True)
     if response.status_code != 200:
         raise HTTPError(response.status_code, response.reason)
     with Tqdm(
             total=None
             if no_progress_bar else self._content_length(response),
             leave=False,
             bytes=True,
             desc=from_info.url if name is None else name,
             disable=no_progress_bar,
     ) as pbar:
         with open(to_file, "wb") as fd:
             for chunk in response.iter_content(chunk_size=self.CHUNK_SIZE):
                 fd.write(chunk)
                 pbar.update(len(chunk))
Ejemplo n.º 2
0
    def _upload(self, from_file, to_info, name=None, no_progress_bar=False):
        def chunks():
            with open(from_file, "rb") as fd:
                with Tqdm.wrapattr(
                        fd,
                        "read",
                        total=None
                        if no_progress_bar else os.path.getsize(from_file),
                        leave=False,
                        desc=to_info.url if name is None else name,
                        disable=no_progress_bar,
                ) as fd_wrapped:
                    while True:
                        chunk = fd_wrapped.read(self.CHUNK_SIZE)
                        if not chunk:
                            break
                        yield chunk

        response = self._request("POST", to_info.url, data=chunks())
        if response.status_code not in (200, 201):
            raise HTTPError(response.status_code, response.reason)
Ejemplo n.º 3
0
Archivo: http.py Proyecto: vijay120/dvc
 def getsize(self, path_info):
     response = self.request("GET", path_info.url, stream=True)
     if response.status_code != 200:
         raise HTTPError(response.status_code, response.reason)
     return self._content_length(response)