Replace os.system('unzip file.zip') -> ZipFile.extractall() (#4919)

* Replace `os.system('unzip file.zip')` -> `ZipFile.extractall()`

* Cleanup
This commit is contained in:
Glenn Jocher authored and GitHub committed 2021-09-25 08:52:36 -07:00
1 parent 1492632796
commit a64a4c839f
3 files changed
+16 -12

No files matched your search

+3 -2
View File
@@ -15,6 +15,7 @@ from itertools import repeat
from multiprocessing.pool import ThreadPool, Pool
from pathlib import Path
from threading import Thread
from zipfile import ZipFile
import cv2
import numpy as np
@@ -928,8 +929,8 @@ def dataset_stats(path='coco128.yaml', autodownload=False, verbose=False, profil
# Unzip data.zip TODO: CONSTRAINT: path/to/abc.zip MUST unzip to 'path/to/abc/'
if str(path).endswith('.zip'): # path is data.zip
assert Path(path).is_file(), f'Error unzipping {path}, file not found'
assert os.system(f'unzip -q {path} -d {path.parent}') == 0, f'Error unzipping {path}'
dir = path.with_suffix('') # dataset directory
ZipFile(path).extractall(path=path.parent) # unzip
dir = path.with_suffix('') # dataset directory == zip name
return True, str(dir), next(dir.rglob('*.yaml')) # zipped, data_dir, yaml_path
else: # path is data.yaml
return False, None, path