Exemplo n.º 1
0
def student_repo_pristine_clone(ctx, course, team_id):
    team = get_team_or_exit(ctx, course, team_id)

    conn = create_connection(course, ctx.obj['config'])

    if conn is None:
        ctx.exit(CHISUBMIT_FAIL)

    if not conn.exists_team_repository(course, team):
        print(
            "The repository for '%s' does not exist or you do not have permission to access it."
            % team_id)
        ctx.exit(CHISUBMIT_FAIL)

    tempdir = tempfile.mkdtemp(prefix="%s-%s-" %
                               (course.course_id, team.team_id))

    repo_url = conn.get_repository_git_url(course, team)

    try:
        LocalGitRepo.create_repo(tempdir, clone_from_url=repo_url)
    except Exception as e:
        print("Unable to create a clone of repository %s" % repo_url)
        ctx.exit(CHISUBMIT_FAIL)

    print("A pristine clone of your repository has been created in %s" %
          tempdir)

    return CHISUBMIT_SUCCESS
Exemplo n.º 2
0
def instructor_grading_assign_grader(ctx, course, assignment_id, team_id, grader_id):
    team = get_team_or_exit(ctx, course, team_id)
    grader = get_grader_or_exit(ctx, course, grader_id)

    registration = get_assignment_registration_or_exit(ctx, team, assignment_id)

    registration.grader_username = grader.username
Exemplo n.º 3
0
def student_repo_pristine_clone(ctx, course, team_id):
    team = get_team_or_exit(ctx, course, team_id)
    
    conn = create_connection(course, ctx.obj['config'])
    
    if conn is None:
        ctx.exit(CHISUBMIT_FAIL)

    if not conn.exists_team_repository(course, team):
        print("The repository for '%s' does not exist or you do not have permission to access it." % team_id)
        ctx.exit(CHISUBMIT_FAIL)

    tempdir = tempfile.mkdtemp(prefix="%s-%s-" % (course.course_id, team.team_id))
    
    repo_url = conn.get_repository_git_url(course, team)
    
    try:
        LocalGitRepo.create_repo(tempdir, clone_from_url=repo_url)
    except Exception as e:
        print("Unable to create a clone of repository %s" % repo_url)
        ctx.exit(CHISUBMIT_FAIL)
        
    print("A pristine clone of your repository has been created in %s" % tempdir)    

    return CHISUBMIT_SUCCESS
Exemplo n.º 4
0
def instructor_grading_set_grade(ctx, course, team_id, assignment_id,
                                 rubric_component_description, points):
    assignment = get_assignment_or_exit(ctx, course, assignment_id)
    team = get_team_or_exit(ctx, course, team_id)
    registration = get_assignment_registration_or_exit(ctx, team,
                                                       assignment_id)

    rubric_components = assignment.get_rubric_components()

    rubric_component = [
        rc for rc in rubric_components
        if rc.description == rubric_component_description
    ]

    if len(rubric_component) == 0:
        print("No such rubric component in %s: %s" %
              (assignment_id, rubric_component_description))
        ctx.exit(CHISUBMIT_FAIL)
    elif len(rubric_component) > 1:
        print(
            "ERROR: Server returned more than one rubric component for '%s' in %s"
            % (rubric_component_description, assignment_id))
        print(
            "       This should not happen. Please contact the chisubmit administrator."
        )
        ctx.exit(CHISUBMIT_FAIL)
    else:
        rc = rubric_component[0]

        try:
            registration.set_grade(rc, points)
            ctx.exit(CHISUBMIT_SUCCESS)
        except ValueError as ve:
            print(ve)
            ctx.exit(CHISUBMIT_FAIL)
Exemplo n.º 5
0
def instructor_grading_set_grade(ctx, course, team_id, assignment_id, rubric_component_description, points):   
    assignment = get_assignment_or_exit(ctx, course, assignment_id)
    team = get_team_or_exit(ctx, course, team_id)
    registration = get_assignment_registration_or_exit(ctx, team, assignment_id)
     
    rubric_components = assignment.get_rubric_components()
    
    rubric_component = [rc for rc in rubric_components if rc.description == rubric_component_description]
    
    if len(rubric_component) == 0:
        print "No such rubric component in %s: %s" % (assignment_id, rubric_component_description)
        ctx.exit(CHISUBMIT_FAIL)
    elif len(rubric_component) > 1:
        print "ERROR: Server returned more than one rubric component for '%s' in %s" % (rubric_component_description, assignment_id)
        print "       This should not happen. Please contact the chisubmit administrator."
        ctx.exit(CHISUBMIT_FAIL)
    else:
        rc = rubric_component[0]
        
        try:
            registration.set_grade(rc, points)
            ctx.exit(CHISUBMIT_SUCCESS)
        except ValueError, ve:
            print ve.message
            ctx.exit(CHISUBMIT_FAIL)
Exemplo n.º 6
0
def instructor_grading_assign_grader(ctx, course, assignment_id, team_id,
                                     grader_id):
    team = get_team_or_exit(ctx, course, team_id)
    grader = get_grader_or_exit(ctx, course, grader_id)

    registration = get_assignment_registration_or_exit(ctx, team,
                                                       assignment_id)

    registration.grader_username = grader.username
Exemplo n.º 7
0
def admin_course_team_repo_update(ctx, course_id, team_id):
    course = get_course_or_exit(ctx, course_id) 
    team = get_team_or_exit(ctx, course, team_id) 

    #if team.github_repo is None:
    #    print "Team %s does not have a repository." % team.id
    #    return CHISUBMIT_FAIL

    conn = create_connection(course, ctx.obj['config'], staging = False)
    
    if conn is None:
        print "Could not connect to git server."
        ctx.exit(CHISUBMIT_FAIL)

    conn.update_team_repository(course, team)
    return CHISUBMIT_SUCCESS
Exemplo n.º 8
0
def admin_course_team_repo_update(ctx, course_id, team_id):
    course = get_course_or_exit(ctx, course_id)
    team = get_team_or_exit(ctx, course, team_id)

    #if team.github_repo is None:
    #    print "Team %s does not have a repository." % team.id
    #    return CHISUBMIT_FAIL

    conn = create_connection(course, ctx.obj['config'], staging=False)

    if conn is None:
        print("Could not connect to git server.")
        ctx.exit(CHISUBMIT_FAIL)

    conn.update_team_repository(course, team)
    return CHISUBMIT_SUCCESS
Exemplo n.º 9
0
def shared_team_show(ctx, course, team_id):
    team = get_team_or_exit(ctx, course, team_id)
        
    print "Team name: %s" % team.team_id
    print
    if course.extension_policy == "per-team":
        print "Extensions available: %i" % team.extensions 
        print
    
    team_members = team.get_team_members()
    
    if len(team_members) == 0:
        print "No students in this team"
    else:
        print "STUDENTS"
        print "--------"
        for team_member in team_members:
            if team_member.confirmed:
                status = "CONFIRMED"
            else:
                status = "UNCONFIRMED"

            user = team_member.student.user

            print "%s: %s, %s  (%s)" % (user.username, user.last_name, user.first_name, status)

    print

    registrations = team.get_assignment_registrations()

    if len(registrations) == 0:
        print "This team is not registered for any assignments."
    else:
        print "ASSIGNMENTS"
        print "-----------"
        for r in registrations:
            assignment = r.assignment
            print "ID: %s" % assignment.assignment_id
            print "Name: %s" % assignment.name
            print "Deadline: %s" % convert_datetime_to_local(assignment.deadline).isoformat(" ")        
            if r.final_submission is not None:
                print "Last submitted at: %s" % convert_datetime_to_local(r.final_submission.submitted_at).isoformat(" ")
                print "Commit SHA: %s" % r.final_submission.commit_sha
                print "Extensions used: %i" % r.final_submission.extensions_used
            else:
                print "NOT SUBMITTED"    
            print    
Exemplo n.º 10
0
def admin_course_team_repo_create(ctx, course_id, team_id, ignore_existing, public, staging):
    course = get_course_or_exit(ctx, course_id) 
    team = get_team_or_exit(ctx, course, team_id) 

    conn = create_connection(course, ctx.obj['config'], staging)
    
    if conn is None:
        print "Could not connect to git server."
        ctx.exit(CHISUBMIT_FAIL)
    
    if conn.exists_team_repository(course, team) and not ignore_existing:
        print "Team %s already has a repository" % team_id
        ctx.exit(CHISUBMIT_FAIL)
    else:
        conn.create_team_repository(course, team, fail_if_exists = not ignore_existing, private = not public)

    return CHISUBMIT_SUCCESS
Exemplo n.º 11
0
def admin_course_team_repo_remove(ctx, course_id, team_id, ignore_non_existing, staging):
    course = get_course_or_exit(ctx, course_id) 
    team = get_team_or_exit(ctx, course, team_id) 

    conn = create_connection(course, ctx.obj['config'], staging)
    
    if conn is None:
        print "Could not connect to git server."
        ctx.exit(CHISUBMIT_FAIL)

    if not conn.exists_team_repository(course, team) and not ignore_non_existing:
        print "WARNING: Cannot delete repository because it doesn't exist"
        ctx.exit(CHISUBMIT_FAIL)
    else:
        conn.delete_team_repository(course, team, fail_if_not_exists = not ignore_non_existing)

    return CHISUBMIT_SUCCESS
Exemplo n.º 12
0
def instructor_grading_assign_grader(ctx, course, assignment_id, team_id, grader_id, none):
    
    if none and grader_id is not None:
        print("Cannot specify a grader and also --none")
        ctx.exit(CHISUBMIT_FAIL)

    if not none and grader_id is None:
        print("You must specify a grader or use --none")
        ctx.exit(CHISUBMIT_FAIL)

    team = get_team_or_exit(ctx, course, team_id)
    registration = get_assignment_registration_or_exit(ctx, team, assignment_id)

    if none:
        registration.grader_username = None
    else:
        grader = get_grader_or_exit(ctx, course, grader_id)
        registration.grader_username = grader.username
Exemplo n.º 13
0
def instructor_grading_assign_grader(ctx, course, assignment_id, team_id,
                                     grader_id, none):

    if none and grader_id is not None:
        print("Cannot specify a grader and also --none")
        ctx.exit(CHISUBMIT_FAIL)

    if not none and grader_id is None:
        print("You must specify a grader or use --none")
        ctx.exit(CHISUBMIT_FAIL)

    team = get_team_or_exit(ctx, course, team_id)
    registration = get_assignment_registration_or_exit(ctx, team,
                                                       assignment_id)

    if none:
        registration.grader_username = None
    else:
        grader = get_grader_or_exit(ctx, course, grader_id)
        registration.grader_username = grader.username
Exemplo n.º 14
0
def student_repo_check(ctx, course, team_id):
    team = get_team_or_exit(ctx, course, team_id)
    
    conn = create_connection(course, ctx.obj['config'])
    
    if conn is None:
        ctx.exit(CHISUBMIT_FAIL)

    if not conn.exists_team_repository(course, team):
        print "The repository for '%s' does not exist or you do not have permission to access it." % team_id
        ctx.exit(CHISUBMIT_FAIL)

    # TODO: Check that the user actually has push access
    print "Your repository exists and you have access to it."
    http_url = conn.get_repository_http_url(course, team)
    if http_url is not None:
        print "Repository website: %s" % conn.get_repository_http_url(course, team)
    print "Repository URL: %s" % conn.get_repository_git_url(course, team)

    return CHISUBMIT_SUCCESS
Exemplo n.º 15
0
def admin_course_team_repo_remove(ctx, course_id, team_id, ignore_non_existing,
                                  staging):
    course = get_course_or_exit(ctx, course_id)
    team = get_team_or_exit(ctx, course, team_id)

    conn = create_connection(course, ctx.obj['config'], staging)

    if conn is None:
        print("Could not connect to git server.")
        ctx.exit(CHISUBMIT_FAIL)

    if not conn.exists_team_repository(course,
                                       team) and not ignore_non_existing:
        print("WARNING: Cannot delete repository because it doesn't exist")
        ctx.exit(CHISUBMIT_FAIL)
    else:
        conn.delete_team_repository(course,
                                    team,
                                    fail_if_not_exists=not ignore_non_existing)

    return CHISUBMIT_SUCCESS
Exemplo n.º 16
0
def admin_course_team_repo_create(ctx, course_id, team_id, ignore_existing,
                                  public, staging):
    course = get_course_or_exit(ctx, course_id)
    team = get_team_or_exit(ctx, course, team_id)

    conn = create_connection(course, ctx.obj['config'], staging)

    if conn is None:
        print("Could not connect to git server.")
        ctx.exit(CHISUBMIT_FAIL)

    if conn.exists_team_repository(course, team) and not ignore_existing:
        print("Team %s already has a repository" % team_id)
        ctx.exit(CHISUBMIT_FAIL)
    else:
        conn.create_team_repository(course,
                                    team,
                                    fail_if_exists=not ignore_existing,
                                    private=not public)

    return CHISUBMIT_SUCCESS
Exemplo n.º 17
0
def student_repo_check(ctx, course, team_id):
    team = get_team_or_exit(ctx, course, team_id)

    conn = create_connection(course, ctx.obj['config'])

    if conn is None:
        ctx.exit(CHISUBMIT_FAIL)

    if not conn.exists_team_repository(course, team):
        print "The repository for '%s' does not exist or you do not have permission to access it." % team_id
        ctx.exit(CHISUBMIT_FAIL)

    # TODO: Check that the user actually has push access
    print "Your repository exists and you have access to it."
    http_url = conn.get_repository_http_url(course, team)
    if http_url is not None:
        print "Repository website: %s" % conn.get_repository_http_url(
            course, team)
    print "Repository URL: %s" % conn.get_repository_git_url(course, team)

    return CHISUBMIT_SUCCESS
Exemplo n.º 18
0
def instructor_assignment_cancel_submit(ctx, course, team_id, assignment_id,
                                        yes):
    assignment = get_assignment_or_exit(ctx, course, assignment_id)
    team = get_team_or_exit(ctx, course, team_id)
    registration = get_assignment_registration_or_exit(
        ctx, team, assignment.assignment_id)

    if registration.final_submission is None:
        print("Team %s has not made a submission for assignment %s," %
              (team.team_id, assignment_id))
        print("so there is nothing to cancel.")
        ctx.exit(CHISUBMIT_FAIL)

    if registration.grader_username is not None:
        print("This submission has already been assigned a grader (%s)" %
              registration.grader_username)
        print(
            "Make sure the grader has been notified to discard this submission."
        )
        print(
            "You must also remove the existing grading branch from the staging server."
        )

        print("Are you sure you want to proceed? (y/n): ", end=' ')

        if not yes:
            yesno = input()
        else:
            yesno = 'y'
            print('y')

        if yesno not in ('y', 'Y', 'yes', 'Yes', 'YES'):
            ctx.exit(CHISUBMIT_FAIL)
        else:
            print()

    if is_submission_ready_for_grading(
            assignment_deadline=registration.assignment.deadline,
            submission_date=registration.final_submission.submitted_at,
            extensions_used=registration.final_submission.extensions_used):
        print(
            "WARNING: You are canceling a submission that is ready for grading!"
        )

    conn = create_connection(course, ctx.obj['config'])

    if conn is None:
        print("Could not connect to git server.")
        ctx.exit(CHISUBMIT_FAIL)

    submission_commit = conn.get_commit(
        course, team, registration.final_submission.commit_sha)

    print()
    print("This is the existing submission for assignment %s:" % assignment_id)
    print()
    if submission_commit is None:
        print(
            "WARNING: Previously submitted commit '%s' is not in the repository!"
            % registration.final_submission.commit_sha)
    else:
        print_commit(submission_commit)
    print()

    print("Are you sure you want to cancel this submission? (y/n): ", end=' ')

    if not yes:
        yesno = input()
    else:
        yesno = 'y'
        print('y')

    if yesno in ('y', 'Y', 'yes', 'Yes', 'YES'):
        registration.final_submission_id = None
        registration.grader_username = None
        registration.grading_started = False

        print()
        print("The submission has been cancelled.")
Exemplo n.º 19
0
def instructor_assignment_submit(ctx, course, team_id, assignment_id, commit_sha, extensions):
    team = get_team_or_exit(ctx, course, team_id)
    registration = get_assignment_registration_or_exit(ctx, team, assignment_id)
            
    conn = create_connection(course, ctx.obj['config'])
    
    if conn is None:
        print("Could not connect to git server.")
        ctx.exit(CHISUBMIT_FAIL)
    
    commit = conn.get_commit(course, team, commit_sha)
    
    if commit is None:
        print("Commit %s does not exist in repository" % commit_sha)
        ctx.exit(CHISUBMIT_FAIL)
    
    if registration.final_submission is not None:
        prior_commit_sha = registration.final_submission.commit_sha
        prior_submitted_at_utc = registration.final_submission.submitted_at
        prior_submitted_at_local = convert_datetime_to_local(prior_submitted_at_utc)            
        
        submission_commit = conn.get_commit(course, team, prior_commit_sha)            
        
        if prior_commit_sha == commit_sha:
            print("The team has already submitted assignment %s" % registration.assignment.assignment_id)
            print("They submitted the following commit on %s:" % prior_submitted_at_local)
            print()
            if submission_commit is None:
                print("WARNING: Previously submitted commit '%s' is not in the repository!" % prior_commit_sha)
            else:
                print_commit(submission_commit)
            print()
            print("You are trying to submit the same commit again (%s)" % prior_commit_sha)
            print("If you want to re-submit, please specify a different commit")
            ctx.exit(CHISUBMIT_FAIL)
            
        print()
        print("WARNING: This team has already submitted assignment %s and you" % registration.assignment.assignment_id) 
        print("are about to overwrite the previous submission of the following commit:")
        print()
        if submission_commit is None:
            print("WARNING: Previously submitted commit '%s' is not in the repository!" % prior_commit_sha)
        else:
            print_commit(submission_commit)
        print()

    if registration.final_submission is not None:
        msg = "THE ABOVE SUBMISSION FOR %s (%s) WILL BE CANCELLED." % (registration.assignment.assignment_id, registration.assignment.name)
        
        print("!"*len(msg))
        print(msg)
        print("!"*len(msg))
        print()
        print("If you continue, their submission for %s (%s)" % (registration.assignment.assignment_id, registration.assignment.name))
        print("will now point to the following commit:")                
    else:
        print("You are going to make a submission for %s (%s)." % (registration.assignment.assignment_id, registration.assignment.name))
        print("The commit you are submitting is the following:")
    print()
    print_commit(commit)
    print()
    print("PLEASE VERIFY THIS IS THE EXACT COMMIT YOU WANT TO SUBMIT")
    print()
    print("Are you sure you want to continue? (y/n): ", end=' ') 
    
    yesno = input()
    
    if yesno in ('y', 'Y', 'yes', 'Yes', 'YES'):
        try:
            submit_response = registration.submit(commit_sha, extensions_override = extensions, dry_run=False)
                        
            print("The submission has been completed.")
            return CHISUBMIT_SUCCESS

        except BadRequestException as bre:        
            print("ERROR: The submission was not completed. The server reported the following errors:")
            bre.print_errors()
            ctx.exit(CHISUBMIT_FAIL)
Exemplo n.º 20
0
def instructor_assignment_cancel_submit(ctx, course, team_id, assignment_id, yes):
    assignment = get_assignment_or_exit(ctx, course, assignment_id)
    team = get_team_or_exit(ctx, course, team_id)
    registration = get_assignment_registration_or_exit(ctx, team, assignment.assignment_id)
        
    if registration.final_submission is None:
        print("Team %s has not made a submission for assignment %s," % (team.team_id, assignment_id))
        print("so there is nothing to cancel.")
        ctx.exit(CHISUBMIT_FAIL)
        
    if registration.grader_username is not None:
        print("This submission has already been assigned a grader (%s)" % registration.grader_username)
        print("Make sure the grader has been notified to discard this submission.")
        print("You must also remove the existing grading branch from the staging server.")
        
        print("Are you sure you want to proceed? (y/n): ", end=' ') 
        
        if not yes:
            yesno = input()
        else:
            yesno = 'y'
            print('y')
        
        if yesno not in ('y', 'Y', 'yes', 'Yes', 'YES'):
            ctx.exit(CHISUBMIT_FAIL)
        else:
            print()
        
    if is_submission_ready_for_grading(assignment_deadline=registration.assignment.deadline, 
                                       submission_date=registration.final_submission.submitted_at,
                                       extensions_used=registration.final_submission.extensions_used):
        print("WARNING: You are canceling a submission that is ready for grading!")
            
    conn = create_connection(course, ctx.obj['config'])
    
    if conn is None:
        print("Could not connect to git server.")
        ctx.exit(CHISUBMIT_FAIL)
        
    submission_commit = conn.get_commit(course, team, registration.final_submission.commit_sha)
        
    print()
    print("This is the existing submission for assignment %s:" % assignment_id)
    print()
    if submission_commit is None:
        print("WARNING: Previously submitted commit '%s' is not in the repository!" % registration.final_submission.commit_sha)
    else:
        print_commit(submission_commit)
    print()    

    print("Are you sure you want to cancel this submission? (y/n): ", end=' ') 
    
    if not yes:
        yesno = input()
    else:
        yesno = 'y'
        print('y')
    
    if yesno in ('y', 'Y', 'yes', 'Yes', 'YES'):
        registration.final_submission_id = None
        registration.grader_username = None
        registration.grading_started = False
        
        print()
        print("The submission has been cancelled.")
Exemplo n.º 21
0
def instructor_assignment_submit(ctx, course, team_id, assignment_id,
                                 commit_sha, extensions):
    team = get_team_or_exit(ctx, course, team_id)
    registration = get_assignment_registration_or_exit(ctx, team,
                                                       assignment_id)

    conn = create_connection(course, ctx.obj['config'])

    if conn is None:
        print "Could not connect to git server."
        ctx.exit(CHISUBMIT_FAIL)

    commit = conn.get_commit(course, team, commit_sha)

    if commit is None:
        print "Commit %s does not exist in repository" % commit_sha
        ctx.exit(CHISUBMIT_FAIL)

    if registration.final_submission is not None:
        prior_commit_sha = registration.final_submission.commit_sha
        prior_submitted_at_utc = registration.final_submission.submitted_at
        prior_submitted_at_local = convert_datetime_to_local(
            prior_submitted_at_utc)

        submission_commit = conn.get_commit(course, team, prior_commit_sha)

        if prior_commit_sha == commit_sha:
            print "The team has already submitted assignment %s" % registration.assignment.assignment_id
            print "They submitted the following commit on %s:" % prior_submitted_at_local
            print
            if submission_commit is None:
                print "WARNING: Previously submitted commit '%s' is not in the repository!" % prior_commit_sha
            else:
                print_commit(submission_commit)
            print
            print "You are trying to submit the same commit again (%s)" % prior_commit_sha
            print "If you want to re-submit, please specify a different commit"
            ctx.exit(CHISUBMIT_FAIL)

        print
        print "WARNING: This team has already submitted assignment %s and you" % registration.assignment.assignment_id
        print "are about to overwrite the previous submission of the following commit:"
        print
        if submission_commit is None:
            print "WARNING: Previously submitted commit '%s' is not in the repository!" % prior_commit_sha
        else:
            print_commit(submission_commit)
        print

    if registration.final_submission is not None:
        msg = "THE ABOVE SUBMISSION FOR %s (%s) WILL BE CANCELLED." % (
            registration.assignment.assignment_id,
            registration.assignment.name)

        print "!" * len(msg)
        print msg
        print "!" * len(msg)
        print
        print "If you continue, their submission for %s (%s)" % (
            registration.assignment.assignment_id,
            registration.assignment.name)
        print "will now point to the following commit:"
    else:
        print "You are going to make a submission for %s (%s)." % (
            registration.assignment.assignment_id,
            registration.assignment.name)
        print "The commit you are submitting is the following:"
    print
    print_commit(commit)
    print
    print "PLEASE VERIFY THIS IS THE EXACT COMMIT YOU WANT TO SUBMIT"
    print
    print "Are you sure you want to continue? (y/n): ",

    yesno = raw_input()

    if yesno in ('y', 'Y', 'yes', 'Yes', 'YES'):
        try:
            submit_response = registration.submit(
                commit_sha, extensions_override=extensions, dry_run=False)

            print "The submission has been completed."
            return CHISUBMIT_SUCCESS

        except BadRequestException, bre:
            print "ERROR: The submission was not completed. The server reported the following errors:"
            bre.print_errors()
            return CHISUBMIT_FAIL