<commit_before>from plstackapi.openstack.client import OpenStackClient
from plstackapi.openstack.driver import OpenStackDriver
from plstackapi.core.api.auth import auth_check
from plstackapi.core.models import User, Site
 
def lookup_site(fields):
    site = None
    if 'site' in fields:
        if isinstance(fields['site'], int):
            sites = Site.objects.filter(id=fields['site'])
        else:
            sites = Site.objects.filter(login_base=fields['site'])
        if sites:
            site = sites[0]
    return site 

def add_user(auth, fields):
    driver = OpenStackDriver(client = auth_check(auth))
    site = lookup_site(fields) 
    if site: fields['site'] = site     
    user = User(**fields)
    nova_fields = {'name': user.email[:user.email.find('@')],
                   'email': user.email, 
                   'password': fields.get('password'),
                   'enabled': user.enabled}    <commit_msg>raise exception if site cannot be found<commit_after>from plstackapi.openstack.client import OpenStackClient
from plstackapi.openstack.driver import OpenStackDriver
from plstackapi.core.api.auth import auth_check
from plstackapi.core.models import User, Site
 
def lookup_site(fields):
    site = None
    if 'site' in fields:
        if isinstance(fields['site'], int):
            sites = Site.objects.filter(id=fields['site'])
        else:
            sites = Site.objects.filter(login_base=fields['site'])
        if sites:
            site = sites[0]
    if not site:
        raise Exception, "No such site", fields['site']
    return site 

def add_user(auth, fields):
    driver = OpenStackDriver(client = auth_check(auth))
    site = lookup_site(fields) 
    if site: fields['site'] = site     
    user = User(**fields)
    nova_fields = {'name': user.email[:user.email.find('@')],
                   'email': user.email, 
                   'password': fields.get('password'),
                   'enabled': user.enabled}    
{'fraction_non_alphanumeric': 0.11922881785895484, 'fraction_numerical': 0.0010147133434804667, 'mean_word_length': 2.6791044776119404, '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': '3193772', 'n_tokens_mistral': 567, 'n_tokens_neox': 550, 'n_words': 140}