-
Notifications
You must be signed in to change notification settings - Fork 2
/
manage.py
131 lines (93 loc) · 4.06 KB
/
manage.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import argparse
import os
from benchkit.data.helpers import create_dataset_zips, test_dataloading, run_upload
from datasets.project_datasets import main
from benchkit.misc.utils.tar import generate_tar
from benchkit.misc.requests.version import upload_project_code
from benchkit.misc.utils.bucket import upload_using_presigned_url
from colorama import Fore, Style
from pathlib import Path
from tqdm import tqdm
def create_datasets():
return main()
def migrate_code(version: int):
print(Fore.RED + "Starting Zipping process" + Style.RESET_ALL)
dep_path = Path(__file__).resolve().parent / "dependencies.txt"
dep_tar = generate_tar("dependency", str(dep_path))
mod_path = Path(__file__).resolve().parent / "models"
mod_tar = generate_tar("models", str(mod_path))
dat_path = Path(__file__).resolve().parent / "datasets"
dat_tar = generate_tar("datasets", str(dat_path))
ts_path = Path(__file__).resolve().parent / "train_script.py"
ts_tar = generate_tar("train-script", str(ts_path))
print(Fore.GREEN + "Completed Zipping process" + Style.RESET_ALL)
data_dict: dict = upload_project_code(os.path.getsize(dep_tar),
dep_tar,
os.path.getsize(ts_tar),
ts_tar,
os.path.getsize(mod_tar),
mod_tar,
os.path.getsize(dat_tar),
dat_tar,
version)
print(Fore.RED + "Starting Upload process" + Style.RESET_ALL)
for set_dict in tqdm(data_dict.items(), colour="blue"):
_, v = set_dict
upload_using_presigned_url(v["url"],
os.path.split(v["fields"]["key"])[-1],
os.path.split(v["fields"]["key"])[-1],
v["fields"])
print(Fore.GREEN + "Completed Upload process" + Style.RESET_ALL)
os.remove(dep_tar)
os.remove(mod_tar)
os.remove(dat_tar)
os.remove(ts_tar)
def cli():
parser = argparse.ArgumentParser()
parser.add_argument("action",
nargs='?',
choices=["migrate-data", "reset", "migrate-code"])
parser.add_argument("input_value",
nargs='?',
default=None)
parser.add_argument("--zip",
help="create zip files",
action="store_true",
required=False)
parser.add_argument("--tdl",
help="test data loader",
action="store_true",
required=False)
parser.add_argument("--up",
help="upload dataset",
action="store_true",
required=False)
args = parser.parse_args()
if args.action == "migrate-data":
arg_list = []
if args.input_value is not None:
for list_arg in create_datasets():
if list_arg[2] == args.input_value:
arg_list = [list_arg]
if not arg_list:
raise ValueError(f"No such dataset named {args.input_value}")
else:
arg_list = create_datasets()
for input_args in arg_list:
p_ds, c_ds, name = input_args
argument_list = [args.zip, args.tdl, args.up]
if argument_list == ([False] * len(argument_list)):
args.zip, args.tdl, args.up = True, True, True
if args.zip:
create_dataset_zips(p_ds, name)
if args.tdl:
test_dataloading(name, c_ds)
if args.up:
run_upload(name)
elif args.action == "migrate-code":
print(Fore.RED + "Starting Code Migration" + Style.RESET_ALL)
if not args.input_value:
args.input_value = 1
migrate_code(args.input_value)
if __name__ == '__main__':
cli()