-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare_dirs_utils.py
More file actions
60 lines (48 loc) · 1.61 KB
/
prepare_dirs_utils.py
File metadata and controls
60 lines (48 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import shutil
import urllib.request
import zipfile
# ------------------------
# --- helper functions ---
# ------------------------
def retrieve_url(http_add, local_name):
"""
Retrieve a file from a URL.
Args:
http_add (str): The URL to retrieve the file from.
local_name (str): The name to save the file as.
"""
print(f"[INFO] Retrieving {http_add} to {local_name}")
try:
urllib.request.urlretrieve(http_add, local_name)
except Exception as err:
print(err)
print(f"[INFO] Could not download {http_add}. Please download this manually.")
def unzip_dir(zip_path, new_path):
"""
Unzip a directory.
Args:
zip_path (str): The path to the zip file.
new_path (str): The path to extract the zip file to.
"""
print(f"[INFO] Unzipping {zip_path} to {new_path}")
try:
with zipfile.ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall(new_path)
except Exception as err:
print(err)
print(f"[INFO] Could not unzip {zip_path}. Please unzip this manually.")
def move_files(src_path, dst_path):
"""
Move files from one directory to another.
Args:
src_path (str): The path to the source directory.
dst_path (str): The path to the destination directory.
"""
print(f"[INFO] Moving files from {src_path} to {dst_path}")
try:
shutil.move(src_path, dst_path)
except Exception as err:
print(err)
print(f"[INFO] Could not move files from {src_path} to {dst_path}. Please move them manually.")