<commit_before>from django.conf import settings
from sis_provisioner.builders import Builder
from sis_provisioner.csv.format import AdminCSV
from sis_provisioner.dao.user import get_person_by_regid
from sis_provisioner.exceptions import UserPolicyException
from logging import getLogger

logger = getLogger('astra')


class AdminBuilder(Builder):
    """
    Generates the data for sub-account admins.
    """
    def _process(self, admin):
        if admin.queue_id is not None:
            self.queue_id = admin.queue_id

        account_id = admin.account_id
        role = settings.ASTRA_ROLE_MAPPING[admin.role]
        status = 'deleted' if admin.is_deleted else 'active'
        action = 'REMOVE' if admin.is_deleted else 'ADD'

        try:
            person = get_person_by_regid(admin.reg_id)
            if not self.add_user_data_for_person(person):
                raise UserPolicyException('Invalid UWNetID')

        except UserPolicyException as err:
            logger.info(
                'SKIP ADMIN "{}", account: "{}", role: "{}", {}'.format(
                    admin.net_id, account_id, role, err))
            return

        if str(admin.canvas_id) == settings.RESTCLIENTS_CANVAS_ACCOUNT_ID:
            account_id = ''

        self.add_user_data_for_person(person)
        self.data.add(AdminCSV(admin.reg_id, account_id, role, status=status))

        logger.info('{} ADMIN "{}", account: "{}", role: "{}"'.format(
            action, admin.net_id, account_id, role))

        if admin.role in settings.ANCILLARY_CANVAS_ROLES:
            ancillary_role = settings.ANCILLARY_CANVAS_ROLES.get(
                admin.role).get('canvas_role')
            if ('root' == settings.ANCILLARY_CANVAS_ROLES.get(
                    admin.role).get('account')):
                ancillary_account_id = ''
            else:<commit_msg>drop duplicate add_user_data_for_person<commit_after>from django.conf import settings
from sis_provisioner.builders import Builder
from sis_provisioner.csv.format import AdminCSV
from sis_provisioner.dao.user import get_person_by_regid
from sis_provisioner.exceptions import UserPolicyException
from logging import getLogger

logger = getLogger('astra')


class AdminBuilder(Builder):
    """
    Generates the data for sub-account admins.
    """
    def _process(self, admin):
        if admin.queue_id is not None:
            self.queue_id = admin.queue_id

        account_id = admin.account_id
        role = settings.ASTRA_ROLE_MAPPING[admin.role]
        status = 'deleted' if admin.is_deleted else 'active'
        action = 'REMOVE' if admin.is_deleted else 'ADD'

        try:
            person = get_person_by_regid(admin.reg_id)
            if not self.add_user_data_for_person(person):
                raise UserPolicyException('Invalid UWNetID')

        except UserPolicyException as err:
            logger.info(
                'SKIP ADMIN "{}", account: "{}", role: "{}", {}'.format(
                    admin.net_id, account_id, role, err))
            return

        if str(admin.canvas_id) == settings.RESTCLIENTS_CANVAS_ACCOUNT_ID:
            account_id = ''

        self.data.add(AdminCSV(admin.reg_id, account_id, role, status=status))

        logger.info('{} ADMIN "{}", account: "{}", role: "{}"'.format(
            action, admin.net_id, account_id, role))

        if admin.role in settings.ANCILLARY_CANVAS_ROLES:
            ancillary_role = settings.ANCILLARY_CANVAS_ROLES.get(
                admin.role).get('canvas_role')
            if ('root' == settings.ANCILLARY_CANVAS_ROLES.get(
                    admin.role).get('account')):
                ancillary_account_id = ''
            else:
{'fraction_non_alphanumeric': 0.10124864277958741, 'fraction_numerical': 0.0, 'mean_word_length': 2.553519768563163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4919372', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1114, 'n_words': 230}