-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathvip-cli.py
More file actions
64 lines (50 loc) · 1.77 KB
/
vip-cli.py
File metadata and controls
64 lines (50 loc) · 1.77 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
61
62
63
64
import argparse
import json
import os
from vip_client import VipSession
_apikey_default = ".api_token.txt"
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--session", required=True, help="session name")
parser.add_argument("--input", required=True, help="inputs directory")
parser.add_argument("--pipeline", required=True, help="pipeline to run")
parser.add_argument(
"--arguments", required=True, help="JSON file containing pipeline's arguments "
)
parser.add_argument(
"--api-key",
default=_apikey_default,
help="API key to connect to the VIP server",
)
args = parser.parse_args()
return args
def unpack_json(filename):
"""
read JSON file and returns the object
"""
if not os.path.exists(filename):
raise FileNotFoundError(filename)
with open(filename, "r", encoding="utf-8") as fi:
return json.load(fi)
def run(args):
# 0. Connect with VIP
VipSession.init(api_key=args.api_key)
# One call applies to multiple Sessions (until connection is lost).
# 1. Create a Session
session = VipSession(session_name=args.session)
# 2. Upload your data on VIP servers
session.upload_inputs(input_dir=args.input)
# 3. Launch a pipeline on VIP
arguments = unpack_json(args.arguments)
session.launch_pipeline(pipeline_id=args.pipeline, input_settings=arguments)
# 4. Monitor its progress on VIP until all executions are over
session.monitor_workflows()
# 5. Download the outputs from VIP servers when all executions are over
session.download_outputs()
# 6. Remove the data from VIP servers (inputs and outputs)
session.finish()
def main():
args = parse_args()
run(args)
if "__main__" == __name__:
main()