-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·83 lines (80 loc) · 2.56 KB
/
run.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
#!/usr/bin/env python3
import os
import sys
import yaml
from pprint import pprint
import kaggle_brane as kb
if __name__ == "__main__":
if len(sys.argv) < 3:
print(
yaml.dump(
{
"output": {
"status": {
"success": False,
"error": 'must provide a command and a subcommand, e.g. "competitions list"',
},
}
},
)
)
else:
command = sys.argv[1]
subcommand = sys.argv[2]
functions = {
"debug": {
"auth": kb.debug_auth,
},
"competitions": {
"list": kb.list_competitions,
"files": kb.list_competition_files,
"download": kb.download_competition,
"submit": kb.submit_competition,
"submissions": kb.competition_submissions,
"leaderboard": kb.competition_leaderboard,
},
"datasets": {
"list": kb.list_dataset,
"files": kb.list_dataset_files,
"download": kb.download_dataset,
"create": kb.create_dataset,
"version": kb.dataset_version,
"init": kb.init_dataset,
"metadata": kb.dataset_metadata,
"status": kb.dataset_status,
},
"kernels": {
"list": kb.list_kernel,
"init": kb.init_kernel,
"push": kb.push_kernel,
"pull": kb.pull_kernel,
"output": kb.kernel_output,
"status": kb.kernel_status,
},
}
try:
api = kb.authenticate(os.environ)
except Exception as e:
if kb.DEBUG:
raise e
status = {"success": False, "error": str(e)}
print(yaml.dump({"output": status}))
func = functions[command][subcommand]
if kb.DEBUG:
print(func)
success, output, error = func(api, os.environ)
if kb.DEBUG:
pprint(dict(success=success, output=output, error=error))
output = output if output is not None else dict()
status = {"success": success, "error": error}
# status = {"status": status}
print(
yaml.dump(
{
"output": {
**status,
**output,
}
},
)
)