Unverified Commit acf1c7b7 authored by moto's avatar moto Committed by GitHub
Browse files

Fix logging in dataset download utilities (#3624)

parent 4dc06ceb
...@@ -6,19 +6,20 @@ from typing import Any, List, Optional ...@@ -6,19 +6,20 @@ from typing import Any, List, Optional
import torchaudio import torchaudio
_LG = logging.getLogger(__name__)
def _extract_tar(from_path: str, to_path: Optional[str] = None, overwrite: bool = False) -> List[str]: def _extract_tar(from_path: str, to_path: Optional[str] = None, overwrite: bool = False) -> List[str]:
if to_path is None: if to_path is None:
to_path = os.path.dirname(from_path) to_path = os.path.dirname(from_path)
with tarfile.open(from_path, "r") as tar: with tarfile.open(from_path, "r") as tar:
logging.info("Opened tar file {}.", from_path)
files = [] files = []
for file_ in tar: # type: Any for file_ in tar: # type: Any
file_path = os.path.join(to_path, file_.name) file_path = os.path.join(to_path, file_.name)
if file_.isfile(): if file_.isfile():
files.append(file_path) files.append(file_path)
if os.path.exists(file_path): if os.path.exists(file_path):
logging.info("{} already extracted.".format(file_path)) _LG.info("%s already extracted.", file_path)
if not overwrite: if not overwrite:
continue continue
tar.extract(file_, to_path) tar.extract(file_, to_path)
...@@ -30,12 +31,11 @@ def _extract_zip(from_path: str, to_path: Optional[str] = None, overwrite: bool ...@@ -30,12 +31,11 @@ def _extract_zip(from_path: str, to_path: Optional[str] = None, overwrite: bool
to_path = os.path.dirname(from_path) to_path = os.path.dirname(from_path)
with zipfile.ZipFile(from_path, "r") as zfile: with zipfile.ZipFile(from_path, "r") as zfile:
logging.info("Opened zip file {}.", from_path)
files = zfile.namelist() files = zfile.namelist()
for file_ in files: for file_ in files:
file_path = os.path.join(to_path, file_) file_path = os.path.join(to_path, file_)
if os.path.exists(file_path): if os.path.exists(file_path):
logging.info("{} already extracted.".format(file_path)) _LG.info("%s already extracted.", file_path)
if not overwrite: if not overwrite:
continue continue
zfile.extract(file_, to_path) zfile.extract(file_, to_path)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment