Пример #1
0
def manage_repos(conf, args, action):
    """Performs an action (archive|unarchive) on all student repos
    """
    hw_name = args.name
    dry_run = args.dry_run

    if dry_run:
        raise NotImplementedError("'--dry-run' is not implemented")
    if action not in ['archive', 'unarchive']:
        raise ValueError("Unexpected action '{}', accepted actions are 'archive' and 'unarchive'.".format(action))

    host = conf.gitlab_host
    namespace = conf.namespace
    token = conf.token
    semester = conf.semester

    roster = get_filtered_roster(conf.roster, args.section, args.student)

    count = 0
    for student in roster:
        username = student["username"]
        student_section = student["section"]
        if "id" not in student:
            logging.warning(
                "Student {} does not have a gitlab account.".format(username)
            )
            continue
        full_name = StudentRepo.name(semester, student_section,
                                     hw_name, username)

        try:
            repo = StudentRepo(host, namespace, full_name, token)
            if action == 'archive':
                repo.archive()
            else:
                repo.unarchive()
            count += 1
        except HTTPError:
            raise

    print("Changed {} repositories.".format(count))