Update dcase2018-task3.py
Browse files- dcase2018-task3.py +17 -14
dcase2018-task3.py
CHANGED
|
@@ -232,21 +232,24 @@ def download_file(
|
|
| 232 |
if unpack:
|
| 233 |
if dest_unpack is None:
|
| 234 |
dest_unpack = os.path.dirname(dest)
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
if (
|
| 238 |
-
source.endswith(".tar.gz")
|
| 239 |
-
or source.endswith(".tgz")
|
| 240 |
-
or source.endswith(".gz")
|
| 241 |
-
):
|
| 242 |
-
out = dest.replace(".gz", "")
|
| 243 |
-
with gzip.open(dest, "rb") as f_in:
|
| 244 |
-
with open(out, "wb") as f_out:
|
| 245 |
-
shutil.copyfileobj(f_in, f_out)
|
| 246 |
else:
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
|
| 252 |
def set_writing_permissions(folder_path):
|
|
|
|
| 232 |
if unpack:
|
| 233 |
if dest_unpack is None:
|
| 234 |
dest_unpack = os.path.dirname(dest)
|
| 235 |
+
if os.path.exists(dest_unpack):
|
| 236 |
+
logger.info(f"{dest_unpack} already exists. Skipping extraction")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
else:
|
| 238 |
+
logger.info(f"Extracting {dest} to {dest_unpack}")
|
| 239 |
+
# shutil unpack_archive does not work with tar.gz files
|
| 240 |
+
if (
|
| 241 |
+
source.endswith(".tar.gz")
|
| 242 |
+
or source.endswith(".tgz")
|
| 243 |
+
or source.endswith(".gz")
|
| 244 |
+
):
|
| 245 |
+
out = dest.replace(".gz", "")
|
| 246 |
+
with gzip.open(dest, "rb") as f_in:
|
| 247 |
+
with open(out, "wb") as f_out:
|
| 248 |
+
shutil.copyfileobj(f_in, f_out)
|
| 249 |
+
else:
|
| 250 |
+
shutil.unpack_archive(dest, dest_unpack)
|
| 251 |
+
if write_permissions:
|
| 252 |
+
set_writing_permissions(dest_unpack)
|
| 253 |
|
| 254 |
|
| 255 |
def set_writing_permissions(folder_path):
|