File size: 1,535 Bytes
c3ece9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a8b18d
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
import os
import json
from types import SimpleNamespace

from kaggle_service import KernelRerunService, NbJob
import argparse
from logger import sheet_logger


def main(args):
    if not os.path.exists(args.config):
        print(f"Config folder not found: {os.path.abspath(args.config)}")
        exit(1)

    configs = []
    if os.path.isdir(args.config):
        files = os.listdir(args.config)
        for file in files:
            with open(os.path.join(args.config, file), "r") as f:
                obj = json.loads(f.read())
                configs.append(obj)
                print(obj)
    elif os.path.isfile(args.config):
        with open(args.config, "r") as f:
            obj = json.loads(f.read())
            configs.append(obj)
            print(obj)

    service = KernelRerunService()
    for config in configs:
        service.add_job(NbJob.from_dict(config))

    if args.option == "run":
        service.run_all()
    elif args.option == "validate":
        service.validate_all()
    elif args.option == "status":
        service.status_all()
    else:
        print(f"Invalid option: {args.option}")


if __name__ == "__main__":
    # parser = argparse.ArgumentParser()
    # parser.add_argument("option", type=str, default="run", choices=["run", "validate", "status"])
    # parser.add_argument("--config", type=str, default="./config")
    #
    # args = parser.parse_args()
    args = SimpleNamespace(option="validate", config='./config')

    main(args)