Пример #1
0
    def create_marking_projects(self,
                                students_csv,
                                markers_csv,
                                project_part,
                                icon="policy",
                                color="red"):
        """
        create_project creates projects in Phabricator from a csv.
        :param groups: A unique list of projects.
        :param icon: String of phab icon name.
        :param color: String of phab color.
        :return: None
        """
        all_group_codes = load_group_membership.unique_groups(students_csv)
        all_tutors = load_group_membership.usernames(markers_csv)
        allocations = self.get_random_tutor_marking_allocations(
            all_tutors, all_group_codes)

        for tutor, group_codes in allocations.iteritems():
            print("Tutor %s is marking groups: %s" % (tutor, group_codes)
                  )  # this is in a separate loop to make it print cleanly

        for tutor, group_codes in allocations.iteritems():
            tutor_phid = phab_user.get_phid_from_username(tutor)
            for group_code in group_codes:
                group_name = group_translator.get_project_name_from_group_code(
                    group_code=group_code,
                    project_part=project_part,
                    is_marking_group=True)
                phab_project.create(group_name, icon, color,
                                    [tutor_phid] + PHAB_SUPER_USER_PHIDS)
                print("Created group: %s" % (group_name, ))
Пример #2
0
    def create_repos(self, csv, repo_name):
        """
        create_repos creates repositories in Phabricator from a csv.
        :param csv: csv entries of each student and their group.
        :param repo_name: Name that each repository will be given.
        :return: None.
        """
        groups = load_group_membership.unique_groups(csv)
        for group_code in groups:
            group_num = group_translator.get_group_number_from_group_code(
                group_code)

            if not group_num is None:
                callsign = repos_util.callsign_from_group_num(group_num)
                uri = repos_util.generate_uri(PHAB_API_ADDRESS, callsign)

                phab_repo.create(repo_name, callsign, uri)

                # Sets the repository to be "Hosted on Phabricator".
                details = phab_repo.get_repository_phab_hosted(callsign)
                details = details.replace('importing":true',
                                          'importing":false')
                details = details.replace(
                    'false}',
                    'false,"hosting-enabled":true,"serve-over-http":"readwrite"}'
                )
                phab_repo.set_repository_phab_hosted(details, callsign)

                print("Created repo for group: %s" % (group_num, ))
            else:
                print("Skipped: %s" % (group_code, ))
Пример #3
0
    def create_student_projects(self,
                                csv,
                                project_part,
                                icon="policy",
                                color="red"):
        """
        create_project creates projects in Phabricator from a csv.
        :param groups: A unique list of projects.
        :param icon: String of phab icon name.
        :param color: String of phab color.
        :return: None
        """
        groups = load_group_membership.unique_groups(csv)
        for group_code in groups:
            group_name = group_translator.get_project_name_from_group_code(
                group_code=group_code,
                project_part=project_part,
                is_marking_group=False)
            if group_name:
                usernames = load_group_membership.users_for_group(
                    csv, group_code)
                phids = []
                for u in usernames:
                    phids.append(phab_user.get_phid_from_username(u))
                phids = phids + PHAB_SUPER_USER_PHIDS

                phab_project.create(group_name, icon, color, phids)
                print("Created group: %s" % (group_name, ))
            else:
                print("Skipped: %s" % (group_code, ))
Пример #4
0
    def create_repos(self, csv, repo_name):
        """
        create_repos creates repositories in Phabricator from a csv.
        :param csv: csv entries of each student and their group.
        :param repo_name: Name that each repository will be given.
        :return: None.
        """
        groups = load_group_membership.unique_groups(csv)
        for group_code in groups:
            group_num = group_translator.get_group_number_from_group_code(group_code)

            if group_num:
                callsign = repos_util.callsign_from_group_num(group_num)
                uri = repos_util.generate_uri(PHAB_API_ADDRESS, callsign)

                phab_repo.create(repo_name, callsign, uri)

                # Sets the repository to be "Hosted on Phabricator".
                details = phab_repo.get_repository_phab_hosted(callsign)
                details = details.replace('importing":true', 'importing":false')
                details = details.replace('false}', 'false,"hosting-enabled":true,"serve-over-http":"readwrite"}')
                phab_repo.set_repository_phab_hosted(details, callsign)

                print("Created repo for group: %s" % (group_num,))
            else:
                print("Skipped: %s" % (group_code,))
Пример #5
0
    def create_student_projects(self, csv, project_part, icon="policy", color="red"):
        """
        create_project creates projects in Phabricator from a csv.
        :param groups: A unique list of projects.
        :param icon: String of phab icon name.
        :param color: String of phab color.
        :return: None
        """
        groups = load_group_membership.unique_groups(csv)
        for group_code in groups:
            group_name = group_translator.get_project_name_from_group_code(
                group_code=group_code,
                project_part=project_part,
                is_marking_group=False
            )
            if group_name:
                usernames = load_group_membership.users_for_group(csv, group_code)
                phids = []
                for u in usernames:
                    phids.append(phab_user.get_phid_from_username(u))
                phids = phids + PHAB_SUPER_USER_PHIDS

                phab_project.create(group_name, icon, color, phids)
                print("Created group: %s" % (group_name,))
            else:
                print("Skipped: %s" % (group_code,))
Пример #6
0
    def create_marking_projects(self, students_csv, markers_csv, project_part, icon="policy", color="red"):
        """
        create_project creates projects in Phabricator from a csv.
        :param groups: A unique list of projects.
        :param icon: String of phab icon name.
        :param color: String of phab color.
        :return: None
        """
        all_group_codes = load_group_membership.unique_groups(students_csv)
        all_tutors = load_group_membership.usernames(markers_csv)
        allocations = self.get_random_tutor_marking_allocations(all_tutors, all_group_codes)

        for tutor, group_codes in allocations.iteritems():
            print("Tutor %s is marking groups: %s" % (tutor, group_codes)) # this is in a separate loop to make it print cleanly

        for tutor, group_codes in allocations.iteritems():
            tutor_phid = phab_user.get_phid_from_username(tutor)
            for group_code in group_codes:
                group_name = group_translator.get_project_name_from_group_code(
                    group_code=group_code,
                    project_part=project_part,
                    is_marking_group=True
                )
                phab_project.create(group_name, icon, color, [tutor_phid] + PHAB_SUPER_USER_PHIDS)
                print("Created group: %s" % (group_name,))
Пример #7
0
    def lockdown_repos(self, csv):
        """
        lockdown_repos sets custom policies on the repositories, such that only
        project members can view, edit, and push their repository.
        :param csv: csv entries of each student and their group.
        :return: None.
        """
        groups = load_group_membership.unique_groups(csv)
        for group_code in groups:
            group_num = group_translator.get_group_number_from_group_code(group_code)

            if group_num:
                student_project_name = group_translator.build_project_name(group_num, 1, False)
                student_project_phid = phab_project.get_phid_from_name(student_project_name)

                if student_project_phid is not None:
                    callsign = repos_util.callsign_from_group_num(group_num)

                    # Sets the repository policy to only the Project members.
                    policy = phab_policy.create_project_policy([student_project_phid])
                    phab_repo.set_repository_policy(callsign, policy, policy, policy)

                    print("Repo %s was assigned policy %s (View,Edit,Push) allowing access from student group %s" % (
                        callsign,
                        policy,
                        student_project_name,
                    ))
                else:
                    print("ERROR: Unable to determine student groups for group %s" % (group_num,))
            else:
                print("Skipped: %s" % (group_code,))
Пример #8
0
 def lockdown_student_projects(self, csv, project_part):
     groups = load_group_membership.unique_groups(csv)
     for group_code in groups:
         group_name = group_translator.get_project_name_from_group_code(
             group_code=group_code,
             project_part=project_part,
             is_marking_group=False
         )
         if group_name:
             project_phid = phab_project.get_phid_from_name(group_name)
             print("Locking down {0} ({1})".format(group_name, project_phid))
             phab_project.set_policy(project_phid, project_phid, project_phid, project_phid)
         else:
             print("Skipped: %s" % (group_code,))
Пример #9
0
 def lockdown_student_projects(self, csv, project_part):
     groups = load_group_membership.unique_groups(csv)
     for group_code in groups:
         group_name = group_translator.get_project_name_from_group_code(
             group_code=group_code,
             project_part=project_part,
             is_marking_group=False)
         if group_name:
             project_phid = phab_project.get_phid_from_name(group_name)
             print("Locking down {0} ({1})".format(group_name,
                                                   project_phid))
             phab_project.set_policy(project_phid, project_phid,
                                     project_phid, project_phid)
         else:
             print("Skipped: %s" % (group_code, ))
Пример #10
0
    def lockdown_repos(self, csv, projectPhid=False):
        """
        lockdown_repos sets custom policies on the repositories, such that only
        project members can view, edit, and push their repository.
        :param csv: csv entries of each student and their group.
        :return: None.
        """
        groups = load_group_membership.unique_groups(csv)
        for group_code in groups:
            group_num = group_translator.get_group_number_from_group_code(
                group_code)

            if not group_num is None:
                student_project_name = group_translator.build_project_name(
                    group_num, 1, False)
                student_project_phid = phab_project.get_phid_from_name(
                    student_project_name)

                if student_project_phid is not None:
                    callsign = repos_util.callsign_from_group_num(group_num)

                    if projectPhid == False:
                        # Sets the repository policy to only the Project members.
                        policy = phab_policy.create_project_policy(
                            [student_project_phid])
                        phab_repo.set_repository_policy(
                            callsign, policy, policy, policy)
                    else:
                        policy = student_project_phid
                        phab_repo.set_repository_policy(
                            callsign, policy, policy, policy)

                    print(
                        "Repo %s was assigned policy %s (View,Edit,Push) allowing access from student group %s"
                        % (
                            callsign,
                            policy,
                            student_project_name,
                        ))
                else:
                    print(
                        "ERROR: Unable to determine student groups for group %s"
                        % (group_num, ))
            else:
                print("Skipped: %s" % (group_code, ))