Example #1
0
    def create_grading_repo(cls, config, course, team, registration, staging_only):
        base_dir = config.work_dir
        
        if not staging_only:
            conn_server = create_connection(course, config)
            if conn_server is None:
                raise ChisubmitException("Could not connect to git server")
        
        conn_staging = create_connection(course, config, staging = True)
        if conn_staging is None:
            raise ChisubmitException("Could not connect to git staging server")        
        
        repo_path = cls.get_grading_repo_path(base_dir, course, team, registration)
        staging_url = conn_staging.get_repository_git_url(course, team)

        if staging_only:
            repo = LocalGitRepo.create_repo(repo_path, clone_from_url = staging_url)
        else:
            server_url = conn_server.get_repository_git_url(course, team)
            repo = LocalGitRepo.create_repo(repo_path, clone_from_url = server_url, remotes = [("staging", staging_url)])

        if registration.final_submission is None:
            commit_sha = None
        else:
            commit_sha = registration.final_submission.commit_sha        
        return cls(team, registration, repo, repo_path, commit_sha, staging_only)
Example #2
0
    def create_grading_repo(cls, config, course, team, registration,
                            staging_only):
        base_dir = config.work_dir

        if not staging_only:
            conn_server = create_connection(course, config)
            if conn_server is None:
                raise ChisubmitException("Could not connect to git server")

        conn_staging = create_connection(course, config, staging=True)
        if conn_staging is None:
            raise ChisubmitException("Could not connect to git staging server")

        repo_path = cls.get_grading_repo_path(base_dir, course, team,
                                              registration)
        staging_url = conn_staging.get_repository_git_url(course, team)

        if staging_only:
            repo = LocalGitRepo.create_repo(repo_path,
                                            clone_from_url=staging_url)
        else:
            server_url = conn_server.get_repository_git_url(course, team)
            repo = LocalGitRepo.create_repo(repo_path,
                                            clone_from_url=server_url,
                                            remotes=[("staging", staging_url)])

        if registration.final_submission is None:
            commit_sha = None
        else:
            commit_sha = registration.final_submission.commit_sha
        return cls(team, registration, repo, repo_path, commit_sha,
                   staging_only)
Example #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
Example #4
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
Example #5
0
 def create_team_repository(self, course, team, fail_if_exists=True, private=True):
     repo_path = self.__get_team_path(course, team)
     
     if os.path.exists(repo_path) and fail_if_exists:
         raise ChisubmitException("Repository %s already exists" % repo_path)
     
     repo = LocalGitRepo.create_repo(repo_path, bare=True)
Example #6
0
 def create_team_repository(self, course, team, fail_if_exists=True, private=True):
     repo_path = self.__get_team_path(course, team)
     
     if os.path.exists(repo_path) and fail_if_exists:
         raise ChisubmitException("Repository %s already exists" % repo_path)
     
     repo = LocalGitRepo.create_repo(repo_path, bare=True)
Example #7
0
def instructor_team_pull_repos(ctx, course, assignment_id, directory, only_ready_for_grading, reset, only):
    assignment = course.get_assignment(assignment_id)
    if assignment is None:
        print "Assignment %s does not exist" % assignment_id
        ctx.exit(CHISUBMIT_FAIL)

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

    teams = get_teams(course, assignment, only = only)

    directory = os.path.expanduser(directory)
    
    if not os.path.exists(directory):
        os.makedirs(directory)

    max_len = max([len(t.id) for t in teams])

    for team in sorted([t for t in teams if t.active], key=operator.attrgetter("id")):
        team_dir = "%s/%s" % (directory, team.id)
        team_git_url = conn.get_repository_git_url(course, team) 
        ta = team.get_assignment(assignment.id)

        if not team.has_assignment_ready_for_grading(assignment) and only_ready_for_grading:
            print "%-*s  SKIPPING (not ready for grading)" % (max_len, team.id)
            continue
        
        try:
            msg = ""
            if not os.path.exists(team_dir):
                r = LocalGitRepo.create_repo(team_dir, clone_from_url=team_git_url)
                msg = "Cloned repo"
            else:
                r = LocalGitRepo(team_dir)
                if reset:
                    r.fetch("origin")
                    r.reset_branch("origin", "master")
                    msg = "Reset to match origin/master" 
                else:
                    if r.repo.is_dirty():
                        print "%-*s  ERROR: Cannot pull. Local repository has unstaged changes." % (max_len, team.id)
                        continue
                    r.checkout_branch("master")
                    r.pull("origin", "master")
                    msg = "Pulled latest changes"
            if only_ready_for_grading:
                r.checkout_commit(ta.commit_sha)
                msg += " and checked out commit %s" % (ta.commit_sha)               
            print "%-*s  %s" % (max_len, team.id, msg)
        except ChisubmitException, ce:
            print "%-*s  ERROR: Could not checkout or pull master branch (%s)" % (max_len, team.id, ce.message)
        except GitCommandError, gce:
            print "%-*s  ERROR: Could not checkout or pull master branch" % (max_len, team.id)
            print gce
Example #8
0
def instructor_team_pull_repos(ctx, course, assignment_id, directory, only_ready_for_grading, reset, only):
    assignment = get_assignment_or_exit(ctx, course, assignment_id)

    conn = create_connection(course, ctx.obj['config'])
    
    teams_registrations = get_teams_registrations(course, assignment, only = only)

    directory = os.path.expanduser(directory)
    
    if not os.path.exists(directory):
        os.makedirs(directory)

    teams = sorted([t for t in teams_registrations.keys() if t.active], key = operator.attrgetter("team_id"))

    max_len = max([len(t.team_id) for t in teams])

    for team in teams:
        registration = teams_registrations[team]
        team_dir = "%s/%s" % (directory, team.team_id)
        team_git_url = conn.get_repository_git_url(course, team) 

        if not registration.is_ready_for_grading() and only_ready_for_grading:
            print "%-*s  SKIPPING (not ready for grading)" % (max_len, team.team_id)
            continue
        
        try:
            msg = ""
            if not os.path.exists(team_dir):
                r = LocalGitRepo.create_repo(team_dir, clone_from_url=team_git_url)
                msg = "Cloned repo"
            else:
                r = LocalGitRepo(team_dir)
                if reset:
                    r.fetch("origin")
                    r.reset_branch("origin", "master")
                    msg = "Reset to match origin/master" 
                else:
                    if r.repo.is_dirty():
                        print "%-*s  ERROR: Cannot pull. Local repository has unstaged changes." % (max_len, team.team_id)
                        continue
                    r.checkout_branch("master")
                    r.pull("origin", "master")
                    msg = "Pulled latest changes"
            if only_ready_for_grading:
                r.checkout_commit(registration.final_submission.commit_sha)
                msg += " and checked out commit %s" % (registration.final_submission.commit_sha)               
            print "%-*s  %s" % (max_len, team.team_id, msg)
        except ChisubmitException, ce:
            print "%-*s  ERROR: Could not checkout or pull master branch (%s)" % (max_len, team.team_id, ce.message)
        except GitCommandError, gce:
            print "%-*s  ERROR: Could not checkout or pull master branch" % (max_len, team.team_id)
            print gce
Example #9
0
def student_repo_pristine_clone(ctx, course, team_id):
    team = course.get_team(team_id)
    if team is None:
        print "Team %s does not exist or you do not have access to it" % team_id
        ctx.exit(CHISUBMIT_FAIL)

    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.id, team.id))

    repo_url = conn.get_repository_git_url(course, team)

    try:
        LocalGitRepo.create_repo(tempdir, clone_from_url=repo_url)
    except Exception, e:
        print "Unable to create a clone of repository %s" % repo_url
        ctx.exit(CHISUBMIT_FAIL)
Example #10
0
    def create_grading_repo(cls, config, course, team, assignment):
        base_dir = config["directory"]
        
        conn_server = create_connection(course, config)
        if conn_server is None:
            raise ChisubmitException("Could not connect to git server")
        
        conn_staging = create_connection(course, config, staging = True)
        if conn_server is None:
            raise ChisubmitException("Could not connect to git staging server")        
        
        repo_path = cls.get_grading_repo_path(base_dir, course, team, assignment)
        server_url = conn_server.get_repository_git_url(course, team)
        staging_url = conn_staging.get_repository_git_url(course, team)

        ta = team.get_assignment(assignment.id)

        repo = LocalGitRepo.create_repo(repo_path, clone_from_url = server_url, remotes = [("staging", staging_url)])
        return cls(team, assignment, repo, repo_path, ta.commit_sha)
Example #11
0
    def create_grading_repo(cls, config, course, team, assignment):
        base_dir = config["directory"]

        conn_server = create_connection(course, config)
        if conn_server is None:
            raise ChisubmitException("Could not connect to git server")

        conn_staging = create_connection(course, config, staging=True)
        if conn_server is None:
            raise ChisubmitException("Could not connect to git staging server")

        repo_path = cls.get_grading_repo_path(base_dir, course, team,
                                              assignment)
        server_url = conn_server.get_repository_git_url(course, team)
        staging_url = conn_staging.get_repository_git_url(course, team)

        ta = team.get_assignment(assignment.id)

        repo = LocalGitRepo.create_repo(repo_path,
                                        clone_from_url=server_url,
                                        remotes=[("staging", staging_url)])
        return cls(team, assignment, repo, repo_path, ta.commit_sha)
Example #12
0
def instructor_team_pull_repos(ctx, course, directory, assignment,
                               only_ready_for_grading, reset, only):
    if only_ready_for_grading and assignment is None:
        print(
            "--only-ready-for-grading can only be used with --assignment option"
        )
        ctx.exit(CHISUBMIT_FAIL)

    if assignment is not None:
        assignment = get_assignment_or_exit(ctx, course, assignment)

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

    directory = os.path.expanduser(directory)
    if not os.path.exists(directory):
        os.makedirs(directory)

    if assignment is None:
        teams = sorted(course.get_teams(), key=operator.attrgetter("team_id"))
    else:
        teams_registrations = get_teams_registrations(course,
                                                      assignment,
                                                      only=only)
        teams = sorted(
            [t for t in list(teams_registrations.keys()) if t.active],
            key=operator.attrgetter("team_id"))

    max_len = max([len(t.team_id) for t in teams])

    for team in teams:
        team_dir = "%s/%s" % (directory, team.team_id)
        team_git_url = conn.get_repository_git_url(course, team)

        if only_ready_for_grading:
            registration = teams_registrations[team]

            if not registration.is_ready_for_grading(
            ) and only_ready_for_grading:
                print("%-*s  SKIPPING (not ready for grading)" %
                      (max_len, team.team_id))
                continue

        try:
            msg = ""
            if not os.path.exists(team_dir):
                r = LocalGitRepo.create_repo(team_dir,
                                             clone_from_url=team_git_url)
                msg = "Cloned repo"
            else:
                r = LocalGitRepo(team_dir)
                if reset:
                    r.fetch("origin")
                    r.reset_branch("origin", "master")
                    msg = "Reset to match origin/master"
                else:
                    if r.repo.is_dirty():
                        print(
                            "%-*s  ERROR: Cannot pull. Local repository has unstaged changes."
                            % (max_len, team.team_id))
                        continue
                    r.checkout_branch("master")
                    r.pull("origin", "master")
                    msg = "Pulled latest changes"
            if only_ready_for_grading:
                r.checkout_commit(registration.final_submission.commit_sha)
                msg += " and checked out commit %s" % (
                    registration.final_submission.commit_sha)
            print("%-*s  %s" % (max_len, team.team_id, msg))
        except ChisubmitException as ce:
            print(
                "%-*s  ERROR: Could not checkout or pull master branch (%s)" %
                (max_len, team.team_id, ce))
        except GitCommandError as gce:
            print("%-*s  ERROR: Could not checkout or pull master branch" %
                  (max_len, team.team_id))
            print(gce)
        except InvalidGitRepositoryError as igre:
            print(
                "%-*s  ERROR: Directory %s exists but does not contain a valid git repository"
                % (max_len, team.team_id, team_dir))
        except Exception as e:
            print(
                "%-*s  ERROR: Unexpected exception when trying to checkout/pull"
                % (max_len, team.team_id))
            raise

    return CHISUBMIT_SUCCESS
Example #13
0
def instructor_team_pull_repos(ctx, course, directory, assignment, only_ready_for_grading, reset, only):
    if only_ready_for_grading and assignment is None:
        print("--only-ready-for-grading can only be used with --assignment option")
        ctx.exit(CHISUBMIT_FAIL)
    
    if assignment is not None:
        assignment = get_assignment_or_exit(ctx, course, assignment)

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

    directory = os.path.expanduser(directory)
    if not os.path.exists(directory):
        os.makedirs(directory)
    
    if assignment is None:
        teams = sorted(course.get_teams(), key = operator.attrgetter("team_id"))
    else:
        teams_registrations = get_teams_registrations(course, assignment, only = only)
        teams = sorted([t for t in list(teams_registrations.keys()) if t.active], key = operator.attrgetter("team_id"))

    max_len = max([len(t.team_id) for t in teams])

    for team in teams:
        team_dir = "%s/%s" % (directory, team.team_id)
        team_git_url = conn.get_repository_git_url(course, team) 

        if only_ready_for_grading:
            registration = teams_registrations[team]
    
            if not registration.is_ready_for_grading() and only_ready_for_grading:
                print("%-*s  SKIPPING (not ready for grading)" % (max_len, team.team_id))
                continue
        
        try:
            msg = ""
            if not os.path.exists(team_dir):
                r = LocalGitRepo.create_repo(team_dir, clone_from_url=team_git_url)
                msg = "Cloned repo"
            else:
                r = LocalGitRepo(team_dir)
                if reset:
                    r.fetch("origin")
                    r.reset_branch("origin", "master")
                    msg = "Reset to match origin/master" 
                else:
                    if r.repo.is_dirty():
                        print("%-*s  ERROR: Cannot pull. Local repository has unstaged changes." % (max_len, team.team_id))
                        continue
                    r.checkout_branch("master")
                    r.pull("origin", "master")
                    msg = "Pulled latest changes"
            if only_ready_for_grading:
                r.checkout_commit(registration.final_submission.commit_sha)
                msg += " and checked out commit %s" % (registration.final_submission.commit_sha)               
            print("%-*s  %s" % (max_len, team.team_id, msg))
        except ChisubmitException as ce:
            print("%-*s  ERROR: Could not checkout or pull master branch (%s)" % (max_len, team.team_id, ce))
        except GitCommandError as gce:
            print("%-*s  ERROR: Could not checkout or pull master branch" % (max_len, team.team_id))
            print(gce)
        except InvalidGitRepositoryError as igre:
            print("%-*s  ERROR: Directory %s exists but does not contain a valid git repository"  % (max_len, team.team_id, team_dir))
        except Exception as e:
            print("%-*s  ERROR: Unexpected exception when trying to checkout/pull" % (max_len, team.team_id))
            raise
    
    return CHISUBMIT_SUCCESS