コード例 #1
0
def real_time_output(task_id, offset, count, launch=False):
    """
    :add 'real-time-output' to retrieve output real-time.
    :param task_id:
    :param offset: 100 for example
    :param count: 100 for example
    :return:
    """
    # use this to get requests

    code, header, content = response_get(task_id, offset, count)
    if code != 200 and code != 204:
        if code == 500 and launch:
            return 'TRY_AGAIN'
        else:
            handle_error(code, realtime=True)
            exit(0)
    if not launch:
        print(f"{y}{h}The output of this task is:{e}")
        tmp_str = b''
        while True:
            while True:
                if code != 200 and code != 204:
                    continue
                code, header, content = response_get(task_id, offset, count)
                val = (code, header, content)
                tmp_str = print_(val, tmp_str)
                break

    content_length = header['Content-Length']
    output = content
    _offset = output.split(b'\r\n')[0]
    output = output.split(b'\r\n')[1:][0]
    return content_length, _offset, output
コード例 #2
0
ファイル: lauch_task.py プロジェクト: ligengen/Terminal-api
def request_post(this_url, info):
    response = requests.post(base_url + this_url, json=info)
    if response.status_code != 200:
        handle_error(response.status_code, launch_task=True)
        exit(0)
    response_dic = response.json()
    return response.status_code, response_dic
コード例 #3
0
ファイル: upload_file.py プロジェクト: ligengen/Terminal-api
def request_post(this_url, headers, params, path):
    req = requests.Request('POST', base_url + this_url, headers=headers, params=params)
    code, response_dic = read_upload(req, path)
    if code != 200:
        handle_error(code)
        exit(0)
    return code, response_dic
コード例 #4
0
def response_post(info):
    response = requests.post(base_url + this_url, json=info, headers=headers)
    if response.status_code != 200:
        handle_error(response.status_code)
        exit(0)
    response_dic = response.json()
    return response.status_code, response_dic
コード例 #5
0
ファイル: logout.py プロジェクト: ligengen/Terminal-api
def post(this_url, info):
    response = requests.post(base_url + this_url, json=info)

    if response.status_code != 200:
        handle_error(response.status_code)
        exit(0)
    return response.status_code, response.json()
コード例 #6
0
def get(this_url, params):
    response = requests.get(base_url + this_url, params=params)
    if response.status_code != 200:
        handle_error(response.status_code)
        exit(0)
    response_dic = response.json()
    return response.status_code, response_dic
コード例 #7
0
def response_get(task_id, format):
    this_url = "/api/v1/task/_download/%s.%s" % (task_id, format)
    response = requests.get(base_url + this_url, stream=True)
    if response.status_code != 200:
        handle_error(response.status_code, download_file=True)
        exit(0)
    return response
コード例 #8
0
def post(this_url, info):
    response = requests.post(base_url + this_url, json=info, headers=headers)
    if response.status_code != 200:
        handle_error(response.status_code)
        exit(0)
    response_dic = response.json()
    print(f"{b}{h}Your task has been updated:{e}")
    return response.status_code, response_dic
コード例 #9
0
def response_get(task_id):
    this_url = "/api/v1/task/%s" % task_id
    response = requests.get(base_url + this_url)
    if response.status_code != 200:
        handle_error(response.status_code)
        exit(0)
    response_dic = response.json()
    return response.status_code, response_dic
コード例 #10
0
def response_get():
    # use this to get requests
    this_url = "/api/_inspect"
    response = requests.get(base_url + this_url, timeout=5)
    if response.status_code != 200:
        handle_error(response.status_code)
        exit(0)
    response_dic = response.json()
    print(response_dic)
    return response.status_code, response_dic
コード例 #11
0
def list_files_call(taskid, path):
    if path is not None:
        url = base_url + "/api/v1/task/%s/_listdir/%s" % (taskid, path)
    else:
        url = base_url + "/api/v1/task/%s/_listdir/" % taskid
    response = requests.get(url)
    if response.status_code != 200:
        handle_error(response.status_code)
        exit(0)
    response_dic = response.json()
    return response.status_code, response_dic
コード例 #12
0
ファイル: kill_task.py プロジェクト: ligengen/Terminal-api
def response_post(task_id):
    this_url = "/api/v1/task/%s/_kill" % task_id
    # new a info and process it afterwards
    info = {

    }
    # use this to post requests
    response = requests.post(base_url + this_url, json=info)
    if response.status_code != 200:
        handle_error(response.status_code, launch_task=True)
        exit(0)
    return response.status_code, response.json()
コード例 #13
0
def response_get(task_id, range):
    # use this to get requests
    this_url = "/api/v1/task/%s/output" % task_id
    headers = {

    }
    if range is not None:
        headers["Range"] = "bytes=" + range
        response = requests.get(base_url + this_url, headers=headers)
    else:
        response = requests.get(base_url + this_url)

    if response.status_code != 200 and response.status_code != 206:
        handle_error(response.status_code, retrieve=True)
        exit(0)
    return response.content
コード例 #14
0
def response_get(path, task_id, range_to_download):
    if path is not None:
        this_url = "/api/v1/task/%s/_getfile/%s" % (task_id, path)
    else:
        this_url = "/api/v1/task/%s/_getfile/" % task_id
    if range_to_download is not None:
        headers = {
            'Range': range_to_download
        }
        response = requests.get(base_url + this_url, headers=headers, stream=True)
    else:
        response = requests.get(base_url + this_url, stream=True)

    if response.status_code != 200 and response.status_code != 206:
        handle_error(response.status_code, download_file=True)
        exit(0)
    return response
コード例 #15
0
def test_error_code():
    assert handle_error(200) is None
    assert handle_error(400) is None
    assert handle_error(400, list_files=True) is None
    assert handle_error(400, retrieve=True) is None
    assert handle_error(401) is None
    assert handle_error(403) is None
    assert handle_error(404) is None
    assert handle_error(404, realtime=True) is None
    assert handle_error(405) is None
    assert handle_error(409, launch_task=True) is None
    assert handle_error(413) is None
    assert handle_error(500) is None
    assert handle_error(501) is None
    assert handle_error(503) is None
    assert handle_error(507) is None
    assert handle_error(409, retrieve=True) is None
    assert handle_error(409, realtime=True) is None
    assert handle_error(409, download_file=True) is None
    assert handle_error(409) is None