collect_late.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:csci_tool 作者: vmagro 项目源码 文件源码
def run(self, args):
        assignment = args.assignment
        logger.info('Collecting late submissions for %s', assignment)

        config = Config.load_config()
        github = config.github

        failures = []

        for line in args.submissions:
            email, late_days, sha = line.strip().split(',')
            logger.info('Collecting %s from %s for %s, %s late day(s)',
                        sha, email, assignment, late_days)
            try:
                student = Student(email, None)

                # clone the repo into the subdirectory at args.destination
                dest_dir = path.join(args.destination, student.unix_name)
                # just add a submodule rather than downloading the whole repo
                with tempfile.TemporaryDirectory() as tmpdir:
                    # clone the repo into a temp directory and copy the assignment dir to the submissions dir
                    repo = git.Repo.clone_from(student.repo_url, tmpdir)

                    # make sure we got the right sha
                    repo.git.checkout(sha)

                    dir_util.copy_tree(path.join(tmpdir, assignment), dest_dir)

                # comment on the commit that we collected
                repo_fqn = config.github_org + '/' + student.repo_name
                # must use fully qualified repo name with org
                repo = github.get_repo(repo_fqn)
                commit = repo.get_commits(sha=sha)[0]

                comment = 'This commit was collected as part of "{}". \n \
This was a late submission using {} late day(s). If you think this is \
incorrect, please post on Piazza.'.format(assignment, late_days)
                logger.debug('Commenting on GitHub')
                commit.create_comment(comment)
            except Exception as e:
                logger.error('Failed for %s, %s', email, e)
                failures.append((email, late_days, sha))

        if failures:
            logger.error('Failed on %d students, please try them again', len(failures))
            logger.error('Failures have been written out to ./failures.txt')
            with open('failures.txt', 'w') as f:
                for s in failures:
                    f.write('{},{},{}\n'.format(email, late_days, sha))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号