示例#1
0
def clean_environment(users_path):
    print "\nCleaning environment"
    read_users_info(users_path)

    for i, user_id in enumerate(users_dict):
        user = users_dict[user_id]
        is_ss_provider = user.provider == "SS"
        response = list_content(user.oauth, user.shared_folder_id, is_ss_provider)
        if response.status_code == 200:
            json_data = response.json()
            content_root = json_data["contents"]
            print i, " ", user_id
            for line in content_root:
                try:
                    print_seq_dots()
                    name = line["filename"]
                    server_id = line["id"]
                    is_folder = line["is_folder"]
                    if name.isdigit():
                        response = unlink(user.oauth, server_id, is_folder, is_ss_provider)
                        if response.status_code != 200:
                            print response, response.text, response.content
                except KeyError:
                    pass
        else:
            print i, user_id, response, response.text, response.content
        print
示例#2
0
    def process_make(self, event_args, ops_counter):
        process_debug_log("Count %d ProcessMakeResponse node_id %d of user_id %s" % (ops_counter,
                                                                         int(event_args[TraceProcessor.csv_node_id]),
                                                                         int(event_args[TraceProcessor.csv_user_id])))

        user_id = int(event_args[TraceProcessor.csv_user_id])
        node_id = int(event_args[TraceProcessor.csv_node_id])
        is_folder = event_args[TraceProcessor.csv_node_type] == "Directory"
        friend_id = int(event_args[TraceProcessor.csv_friend_id])

        friend = TraceProcessor.all_users_dict[friend_id]
        workspace = friend.shared_folder_id
        oauth = friend.oauth
        is_ss_provider = friend.provider == "SS"
        server_id = None

        url = "NULL"
        start = time.time()
        try:
            start = time.time()
            response = make(oauth, node_id, workspace, is_folder, is_ss_provider)
            end = time.time()
            url = response.url
            if response.status_code == 201:
                json_data = json.loads(response.text)
                server_id = str(json_data["id"])

                elapsed = end - start
                process_log(str(ops_counter), str(repr(start)), str(repr(event_args[TraceProcessor.csv_queued_tstamp])),
                            str(user_id), str(event_args[TraceProcessor.csv_user_type]),
                            str(event_args[TraceProcessor.csv_req_type]),
                            str(TraceProcessor.all_users_dict[user_id].provider),
                            str(TraceProcessor.all_users_dict[friend_id].provider), str(friend_id),
                            str(server_id),
                            str(event_args[TraceProcessor.csv_node_type]), "NULL", str(elapsed),
                            str(len(TraceProcessor.all_users_dict[user_id].friends_id_factor_dict)), url=str(url))
            elif (response.status_code == 400 or response.status_code == 403) and "already" in response.text:
                elapsed = end - start
                start = time.time()
                response = list_content(oauth, parent_id=workspace, is_ss_provider=is_ss_provider)
                end = time.time()
                json_data = response.json()
                content_root = json_data["contents"]
                server_id = None

                for tuppla in content_root:
                    try:
                        name = tuppla["filename"]
                        is_response_folder = tuppla["is_folder"]
                        if name == str(node_id) and is_folder == is_response_folder:
                            server_id = tuppla["id"]
                            break
                    except KeyError:
                        process_debug_log("Failed to extract file_id form get_content at %s" % (response.url))
                elapsed += end - start
                error_msg = "existing_make"
                size = "NULL"
                process_log(str(ops_counter), str(repr(time.time())), str(repr(event_args[TraceProcessor.csv_queued_tstamp])),
                            str(user_id), str(event_args[TraceProcessor.csv_user_type]),
                            str(event_args[TraceProcessor.csv_req_type]),
                            str(TraceProcessor.all_users_dict[user_id].provider),
                            str(TraceProcessor.all_users_dict[friend_id].provider), str(friend_id),
                            str(server_id),
                            str(event_args[TraceProcessor.csv_node_type]), str(size), elapsed,
                            str(len(TraceProcessor.all_users_dict[user_id].friends_id_factor_dict)), url=str(url), error_msg=error_msg)
            else:
                raise ValueError(
                    "Error on response with status_code %d and text {%s}" % (response.status_code, response.text))

            if server_id is not None:
                if node_id not in friend.node_server_id_dict:
                    friend.node_server_id_dict[node_id] = server_id
                if is_folder and server_id not in friend.workspace_folders:
                    friend.workspace_folders.append(server_id)
                elif not is_folder and server_id not in friend.workspace_files:
                    friend.workspace_files.append(server_id)
            return 0
        except Exception as e:
            trace = event_args
            exception = type(e)
            error_msg = e.message
            args = e.args
            size = "NULL"
            level = "ERROR"
            if server_id is None:
                server_id = node_id

            elapsed = time.time() - start
            process_log(str(ops_counter), str(repr(start)), str(repr(event_args[TraceProcessor.csv_queued_tstamp])),
                        str(user_id), str(event_args[TraceProcessor.csv_user_type]),
                        str(event_args[TraceProcessor.csv_req_type]),
                        str(TraceProcessor.all_users_dict[user_id].provider),
                        str(TraceProcessor.all_users_dict[friend_id].provider), str(friend_id), str(server_id),
                        str(event_args[TraceProcessor.csv_node_type]), str(size), str(elapsed),
                        str(len(TraceProcessor.all_users_dict[user_id].friends_id_factor_dict)),
                        str(TraceProcessor.has_error_code), str(trace), str(exception), str(error_msg), str(args),
                        str(level), url=str(url))
            return TraceProcessor.has_error_code
示例#3
0
def test_api(current_path):
    is_ss_provider = False
    create_test_user(is_ss_provider)

    user = users_dict.popitem()[1]
    root = user.shared_folder_id

    oauth = user.oauth
    file_name = "file5"
    folder_name = "folder5"
    is_folder = True

    start = time.time()
    response = make(oauth, folder_name, parent_id=root, is_folder=is_folder, is_ss_provider=is_ss_provider)
    end = time.time()
    print "MAKE folder elapsed;", (end - start)
    if response.status_code == 201:
        json_data = json.loads(response.text)
        folder_id = str(json_data["id"])
    elif (response.status_code == 400 or response.status_code == 403) and "already" in response.text:
        response = list_content(oauth, parent_id=root, is_ss_provider=is_ss_provider)
        json_data = response.json()
        content_root = json_data["contents"]
        folder_id = None
        for tuppla in content_root:
            try:
                name = tuppla["filename"]
                is_response_folder = tuppla["is_folder"]
                if name == folder_name and is_folder == is_response_folder:
                    folder_id = tuppla["id"]
                    break
            except KeyError:
                raise ValueError("ERROR MAKE Folder: Failed to extract folder_id form get_content at %s" % (response.url))
    else:
        raise ValueError(
            "ERROR MAKE Folder: response with status_code %d and text {%s}" % (response.status_code, response.text))
    print "Folder_id=", folder_id

    is_folder = False
    start = time.time()
    response = make(oauth, file_name, parent_id=folder_id, is_folder=is_folder, is_ss_provider=is_ss_provider)
    end = time.time()
    print "MAKE file elapsed;", (end - start)
    if response.status_code == 201:
        json_data = json.loads(response.text)
        server_id = str(json_data["id"])
    elif (response.status_code == 400 or response.status_code == 403) and "already" in response.text:
        response = list_content(oauth, parent_id=root, is_ss_provider=is_ss_provider)
        json_data = response.json()
        content_root = json_data["contents"]
        server_id = None
        for tuppla in content_root:
            try:
                name = tuppla["filename"]
                is_response_folder = tuppla["is_folder"]
                if name == folder_name and is_folder == is_response_folder:
                    server_id = tuppla["id"]
                    break
            except KeyError:
                raise ValueError("ERROR MAKE File: Failed to extract file_id form get_content at %s" % (response.url))
    else:
        raise ValueError(
            "ERROR MAKE File: response with status_code %d and text {%s}" % (response.status_code, response.text))
    print "File_id", server_id

    file_path = current_path + "/../README.md"
    start = time.time()
    response = put_content(oauth, server_id, file_path, is_ss_provider=is_ss_provider)
    end = time.time()
    print "PUT file elapsed;", (end - start)
    if not (response.status_code == 200 or response.status_code == 201):
        raise ValueError(
            "ERROR PUT File: response with status_code %d and text {%s}" % (response.status_code, response.text))

    start = time.time()
    response = get_content(oauth, server_id, is_ss_provider=is_ss_provider)
    end = time.time()
    print "GET file elapsed;", (end - start)
    if response.status_code != 200:
        raise ValueError(
            "ERROR GET File: response with status_code %d and text {%s}" % (response.status_code, response.text))

    start = time.time()
    response = unlink(oauth, server_id, is_folder=False, is_ss_provider=is_ss_provider)
    end = time.time()
    print "DELETE file elapsed;", (end - start)
    if response.status_code != 200:
        raise ValueError(
            "ERROR DELETE File: response with status_code %d and text {%s}" % (response.status_code, response.text))

    start = time.time()
    response = unlink(oauth, folder_id, is_folder=True, is_ss_provider=is_ss_provider)
    end = time.time()
    print "DELETE folder elapsed;", (end - start)
    if response.status_code != 200:
        raise ValueError(
            "ERROR DELETE Folder: response with status_code %d and text {%s}" % (response.status_code, response.text))