# -*- encoding=utf8 -*-
import os
import sys
import common.run_case_conditions as run
import common.case_tag_get as case_tag_get
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)


if __name__ == '__main__':
    # 第一个参数设备ID
    devices = sys.argv[1]
    devices_list = devices.split(',')
    # 第二个参数 选择单机或多机或多机分布式跑
    runType = sys.argv[2]
    # 第三个参数 case 执行类型，'all', 'choose', 'tag'
    caseType = sys.argv[3]
    # 第四个参数要执行的caseName, 多个文件逗号分割
    caseName = sys.argv[4]
    # 第五个参数，设置日志等级
    log_level = sys.argv[5]
    log_level = log_level.lower()

    workspace = os.path.abspath(".")
    case_path = os.path.join(workspace, 'air_case')
    log_path = os.path.join(workspace, 'log')
    runtime_log = os.path.join(log_path, 'runtime.txt')
    print("workspace: " + workspace)
    print("air_case_path: " + case_path)
    print("air_log_path: " + log_path)
    print("runType:" + runType)
    print("caseType:" + caseType)

    test = run.CustomAirTestCase(workspace, case_path, log_path, runtime_log, log_level)

    case_list = caseName.split(',')
    if caseType == 'tag':
        tag = sys.argv[4]
        case_list = case_tag_get.get_case_tag_list_2(case_path, tag)

    if runType == 's':
        test.run_case_single(devices_list[0], case_list)
        os._exit(0)
    elif runType == 'd':
        test.run_case_by_distri(devices_list, case_list)
        os._exit(0)
    else:
        test.run_case_by_Multi(devices_list, case_list)
        os._exit(0)

