Пример #1
0
def upload_result_file(api: markusapi.Markus,
                       assignment_id: int,
                       local_dir: str,
                       result_file_name: str,
                       utorid: str,
                       group_id: int = None):
    """Upload local_dir/utorid/result_file_name into the student repo on
    MarkUs.

    if group_id is None, download groups from MarkUs and find the group_id.
    """

    if group_id is None:
        try:
            group_id = _get_group_id(api, assignment_id, utorid)
        except NoMarkUsGroupError as error:
            print(error)
            return

    result_file_path = os.path.join(local_dir, utorid, result_file_name)
    try:
        with open(result_file_path) as result_file:
            contents = result_file.read()
    except FileNotFoundError:
        print('Warning: no result file for {}.'.format(utorid))
        return

    response = api.upload_file_to_repo(assignment_id, group_id,
                                       result_file_name, contents)
    # 201 is success
    if response.get('status', 0) == 500 or response.get('code', 0) != '201':
        print('Could not upload result file for {}: {}.'.format(
            utorid, response))