<commit_before>"""
Validators library

Complex validators
"""
from .basic import BaseValidator
from dirty_validators.basic import NotNone
from collections import OrderedDict
from dirty_models.models import BaseModel

class Chain(BaseValidator):

    """
    Use a chain of validators for one value
    """

    def __init__(self, validators=None, stop_on_fail=True, *args, **kwargs):
        super(Chain, self).__init__(*args, **kwargs)

        self.stop_on_fail = stop_on_fail
        self.validators = validators.copy() if validators is not None else []

    def _internal_is_valid(self, value, *args, **kwargs):
        result = True
        for validator in self.validators:
            if not validator.is_valid(value, *args, **kwargs):
                self.messages.update(validator.messages)
                result = False
                if self.stop_on_fail:
                    return False
        return result

class Some(BaseValidator):

    """
    Pass some validators for one value
    """

    def __init__(self, validators=None, *args, **kwargs):
        super(Some, self).__init__(*args, **kwargs)

        self.validators = validators.copy() if validators is not None else []

    def _internal_is_valid(self, value, *args, **kwargs):
        messages = {}
        for validator in self.validators:
            if validator.is_valid(value, *args, **kwargs):
                return True
            messages.update(validator.messages)

        self.messages.update(messages)
        return False

class ComplexValidator(BaseValidator):

    """
    Base for validator which inject context
    """

    def is_valid(self, value, *args, **kwargs):
        context = kwargs.get('context', [])
        context.append(value)
        kwargs['context'] = context

        result = super(ComplexValidator, self).is_valid(value, *args, **kwargs)

        context.pop()
        return result

    def import_messages(self, prefix, messages):
        base_messages = {}
        for key, message in messages.items():
            if isinstance(message, dict):
                self.messages[str(prefix) + "." + str(key)] = message
            else:
                base_messages[key] = message

        if len(base_messages):
            self.messages[prefix] = base_messages

class ListValidator(ComplexValidator):

    """
    Validate items on list
    """

    def __init__(self, validator, stop_on_fail=True, *args, **kwargs):
        super(ListValidator, self).__init__(*args, **kwargs)

        self.validator = validator
        self.stop_on_fail = stop_on_fail

class AllItems(ListValidator):

    """
    Validate all items on list
    """

    def _internal_is_valid(self, value, *args, **kwargs):
        result = True
        for item_index in range(len(value)):
            if not self.validator.is_valid(value[item_index], *args, **kwargs):
                self.import_messages(item_index, self.validator.messages)
                result = False
                if self.stop_on_fail:
                    return False
        return result

class SomeItems(ListValidator):

    """
    Validate some items on list
    """

    TOO_MANY_VALID_ITEMS = 'tooManyValidItems'
    TOO_FEW_VALID_ITEMS = 'tooFewValidItems'

    error_messages = {
        TOO_MANY_VALID_ITEMS: "Too many items pass validation",
        TOO_FEW_VALID_ITEMS: "Too few items pass validation"
    }

    def __init__(self, min=1, max=-1, *args, **kwargs):
        super(SomeItems, self).__init__(*args, **kwargs)
        assert min != -1 or max != -1, 'At least one of `min` or `max` must be specified.'
        assert max == -1 or min <= max, '`min` cannot be more than `max`.'
        self.min = min
        self.max = max

        self.message_values.update({"min": self.min, "max": self.max})

    def _internal_is_valid(self, value, *args, **kwargs):
        item_pass = 0
        for item_index in range(len(value)):
            if not self.validator.is_valid(value[item_index], *args, **kwargs):
                self.import_messages(item_index, self.validator.messages)
            else:
                item_pass += 1
                if self.stop_on_fail and self.max != -1 and item_pass > self.max:
                    self.error(self.TOO_MANY_VALID_ITEMS, value)
                    return False

        if self.max != -1 and item_pass > self.max:
            self.error(self.TOO_MANY_VALID_ITEMS, value)
            return False

        if self.min != -1 and item_pass < self.min:
            self.error(self.TOO_FEW_VALID_ITEMS, value)
            return False

        self.messages = {}
        return True

class ItemLimitedOccurrences(BaseValidator):

    """
    Validate whether item in list are distincts
    """

    TOO_MANY_ITEM_OCCURRENCES = 'tooManyItemOccurrences'
    TOO_FEW_ITEM_OCCURRENCES = 'tooFewItemOccurrences'

    error_messages = {
        TOO_MANY_ITEM_OCCURRENCES: "Item '$value' is repeated to many times. Limit to $max_occ.",
        TOO_FEW_ITEM_OCCURRENCES: "Item '$value' is not enough repeated. Limit to $min_occ.",
    }

    def __init__(self, min_occ=0, max_occ=1, *args, **kwargs):
        super(ItemLimitedOccurrences, self).__init__(*args, **kwargs)
        self.min_occ = min_occ
        self.max_occ = max_occ

        self.message_values['min_occ'] = self.min_occ
        self.message_values['max_occ'] = self.max_occ

    def _get_checking_value(self, value):
        """
        It must be override on descendant validators
        """
        return value

    def _internal_is_valid(self, value, *args, **kwargs):

        def add_occurrence(val, counter):
            if val not in counter:
                counter[val] = 0

            counter[val] += 1

        counter = {}

        for item in value:
            val = self._get_checking_value(item)
            add_occurrence(val, counter)

            if counter[val] > self.max_occ:
                self.error(self.TOO_MANY_ITEM_OCCURRENCES, val)
                return False

        for val, occ in counter.items():
            if occ < self.min_occ:
                self.error(self.TOO_FEW_ITEM_OCCURRENCES, val)
                return False

        return True

def get_field_value_from_context(field_name, context_list):
    """
    Helper to get field value from string path.
    String '<context>' is used to go up on context stack. It just
    can be used at the beginning of path: <context>.<context>.field_name_1
    """
    field_path = field_name.split('.')
    context_index = -1
    while field_path[0] == '<context>':
        context_index -= 1
        field_path.pop(0)

    try:
        field_value = context_list[context_index]

        while len(field_path):
            field = field_path.pop(0)
            if isinstance(field_value, (list, tuple)):
                if field.isdigit():
                    field = int(field)
                field_value = field_value[field]
            elif isinstance(field_value, dict):
                try:
                    field_value = field_value[field]
                except KeyError:
                    if field.isdigit():
                        field = int(field)
                        field_value = field_value[field]
                    else:
                        field_value = None

            else:
                field_value = getattr(field_value, field)

        return field_value
    except (IndexError, AttributeError, KeyError):
        return None

class IfField(BaseValidator):

    """
    Conditional validator. It run validators if a specific field value pass validations.
    """

    NEEDS_VALIDATE = 'needsValidate'

    error_messages = {
        NEEDS_VALIDATE: "Some validate error due to field '$field_name' has value '$field_value'.",
    }

    def __init__(self, validator, field_name, field_validator=None,
                 run_if_none=False, add_check_info=True, *args, **kwargs):
        super(IfField, self).__init__(*args, **kwargs)

        self.validator = validator
        self.field_name = field_name
        self.field_validator = field_validator
        self.run_if_none = run_if_none
        self.add_check_info = add_check_info

        self.message_values['field_name'] = field_name

    def _internal_is_valid(self, value, *args, **kwargs):
        field_value = get_field_value_from_context(self.field_name, kwargs.get('context', []))

        if (self.run_if_none or field_value is not None) and \
                (self.field_validator is None or self.field_validator.is_valid(field_value, *args, **kwargs)) and \
                not self.validator.is_valid(value, *args, **kwargs):
            self.messages.update(self.validator.messages)
            if self.add_check_info:
                self.error(self.NEEDS_VALIDATE, value, field_value=field_value)
            return False

        return True

class BaseSpec(ComplexValidator):

    """
    Base class to use spec
    """

    def __init__(self, spec=None, stop_on_fail=True, *args, **kwargs):
        super(BaseSpec, self).__init__(*args, **kwargs)

        if spec is not None:
            self.spec = spec.copy()

        try:
            self.spec
        except AttributeError:
            self.spec = OrderedDict()

        self.stop_on_fail = stop_on_fail

    def _internal_field_validate(self, validator, field_name, field_value, *args, **kwargs):
        if not validator.is_valid(field_value, *args, **kwargs):
            self.import_messages(field_name, validator.messages)
            return False
        return True

    def _internal_is_valid(self, value, *args, **kwargs):
        result = True
        for field_name, validator in self.spec.items():
            field_value = self.get_field_value(field_name, value, kwargs)

            if not self._internal_field_validate(validator, field_name, field_value, *args, **kwargs):
                result = False
                if self.stop_on_fail:
                    return False

        return result

class DictValidate(BaseSpec):

    INVALID_TYPE = 'notDi   ct'

    error_messages = {
        INVALID_TYPE: "'$value' is not a dictionary",
    }

    def get_field_value(self, field_name, value, kwargs):
        return value.get(field_name, None)

    def _internal_is_valid(self, value, *args, **kwargs):
        if not isinstance(value, dict):
            self.error(self.INVALID_TYPE, value)
            return False
        return super(DictValidate, self)._internal_is_valid(value, *args, **kwargs)

class Required(Chain):

    REQUIRED = 'required'

    error_messages = {
        REQUIRED: "Value is required and can not be empty",
    }

    def __init__(self, empty_validator=None, *args, **kwargs):
        self.empty_validator = empty_validator or NotNone()
        super(Required, self).__init__(*args, **kwargs)

    def _internal_is_valid(self, value, *args, **kwargs):
        if not self.empty_validator.is_valid(value):
            self.error(self.REQUIRED, value)
            return False

        return super(Required, self)._internal_is_valid(value, *args, **kwargs)

class Optional(Chain):

    def __init__(self, empty_validator=None, *args, **kwargs):
        self.empty_validator = empty_validator or NotNone()
        super(Optional, self).__init__(*args, **kwargs)

    def _internal_is_valid(self, value, *args, **kwargs):
        if not self.empty_validator.is_valid(value):
            return True

        return Chain._internal_is_valid(self, value, *args, **kwargs)

class ModelValidateMetaclass(type):

    @classmethod
    def __prepare__(metacls, name, bases):  # No keywords in this case
        return OrderedDict()

    def __new__(cls, name, bases, classdict):

        result = super(ModelValidateMetaclass, cls).__new__(
            cls, name, bases, classdict)

        spec = OrderedDict([(field, validator) for field, validator in classdict.items()
                            if hasattr(validator, 'is_valid')])

        setattr(result, 'spec', spec)
        return result

class ModelValidate(BaseSpec, metaclass=ModelValidateMetaclass):

    __modelclass__ = BaseModel

    INVALID_MODEL = 'notModel'

    error_messages = {
        INVALID_MODEL: "'$value' is not an instance of $model",
    }

    def __init__(self, spec=None, *args, **kwargs):
        self.spec = self.spec.copy()
        if spec is not None:
            self.spec.update(spec)

        super(ModelValidate, self).__init__(*args, **kwargs)

    def get_field_value(self, field_name, value, kwargs):
        kwargs['is_modified'] = value.is_modified_field(field_name)

        try:
            return getattr(value, field_name)
        except AttributeError:
            return None

    def _internal_is_valid(self, value, *args, **kwargs):
        if not isinstance(value, self.__modelclass__):
            self.error(self.INVALID_MODEL, value, model=self.__modelclass__.__name__)
            return False

        return super(ModelValidate, self)._internal_is_valid(value, *args, **kwargs)
<commit_msg>Update complex.py<commit_after>"""
Validators library

Complex validators
"""
from .basic import BaseValidator
from dirty_validators.basic import NotNone
from collections import OrderedDict
from dirty_models.models import BaseModel, ListModel

class Chain(BaseValidator):

    """
    Use a chain of validators for one value
    """

    def __init__(self, validators=None, stop_on_fail=True, *args, **kwargs):
        super(Chain, self).__init__(*args, **kwargs)

        self.stop_on_fail = stop_on_fail
        self.validators = validators.copy() if validators is not None else []

    def _internal_is_valid(self, value, *args, **kwargs):
        result = True
        for validator in self.validators:
            if not validator.is_valid(value, *args, **kwargs):
                self.messages.update(validator.messages)
                result = False
                if self.stop_on_fail:
                    return False
        return result

class Some(BaseValidator):

    """
    Pass some validators for one value
    """

    def __init__(self, validators=None, *args, **kwargs):
        super(Some, self).__init__(*args, **kwargs)

        self.validators = validators.copy() if validators is not None else []

    def _internal_is_valid(self, value, *args, **kwargs):
        messages = {}
        for validator in self.validators:
            if validator.is_valid(value, *args, **kwargs):
                return True
            messages.update(validator.messages)

        self.messages.update(messages)
        return False

class ComplexValidator(BaseValidator):

    """
    Base for validator which inject context
    """

    def is_valid(self, value, *args, **kwargs):
        context = kwargs.get('context', [])
        context.append(value)
        kwargs['context'] = context

        result = super(ComplexValidator, self).is_valid(value, *args, **kwargs)

        context.pop()
        return result

    def import_messages(self, prefix, messages):
        base_messages = {}
        for key, message in messages.items():
            if isinstance(message, dict):
                self.messages[str(prefix) + "." + str(key)] = message
            else:
                base_messages[key] = message

        if len(base_messages):
            self.messages[prefix] = base_messages

class ListValidator(ComplexValidator):

    """
    Validate items on list
    """

    def __init__(self, validator, stop_on_fail=True, *args, **kwargs):
        super(ListValidator, self).__init__(*args, **kwargs)

        self.validator = validator
        self.stop_on_fail = stop_on_fail

class AllItems(ListValidator):

    """
    Validate all items on list
    """

    def _internal_is_valid(self, value, *args, **kwargs):
        result = True
        for item_index in range(len(value)):
            if not self.validator.is_valid(value[item_index], *args, **kwargs):
                self.import_messages(item_index, self.validator.messages)
                result = False
                if self.stop_on_fail:
                    return False
        return result

class SomeItems(ListValidator):

    """
    Validate some items on list
    """

    TOO_MANY_VALID_ITEMS = 'tooManyValidItems'
    TOO_FEW_VALID_ITEMS = 'tooFewValidItems'

    error_messages = {
        TOO_MANY_VALID_ITEMS: "Too many items pass validation",
        TOO_FEW_VALID_ITEMS: "Too few items pass validation"
    }

    def __init__(self, min=1, max=-1, *args, **kwargs):
        super(SomeItems, self).__init__(*args, **kwargs)
        assert min != -1 or max != -1, 'At least one of `min` or `max` must be specified.'
        assert max == -1 or min <= max, '`min` cannot be more than `max`.'
        self.min = min
        self.max = max

        self.message_values.update({"min": self.min, "max": self.max})

    def _internal_is_valid(self, value, *args, **kwargs):
        item_pass = 0
        for item_index in range(len(value)):
            if not self.validator.is_valid(value[item_index], *args, **kwargs):
                self.import_messages(item_index, self.validator.messages)
            else:
                item_pass += 1
                if self.stop_on_fail and self.max != -1 and item_pass > self.max:
                    self.error(self.TOO_MANY_VALID_ITEMS, value)
                    return False

        if self.max != -1 and item_pass > self.max:
            self.error(self.TOO_MANY_VALID_ITEMS, value)
            return False

        if self.min != -1 and item_pass < self.min:
            self.error(self.TOO_FEW_VALID_ITEMS, value)
            return False

        self.messages = {}
        return True

class ItemLimitedOccurrences(BaseValidator):

    """
    Validate whether item in list are distincts
    """

    TOO_MANY_ITEM_OCCURRENCES = 'tooManyItemOccurrences'
    TOO_FEW_ITEM_OCCURRENCES = 'tooFewItemOccurrences'

    error_messages = {
        TOO_MANY_ITEM_OCCURRENCES: "Item '$value' is repeated to many times. Limit to $max_occ.",
        TOO_FEW_ITEM_OCCURRENCES: "Item '$value' is not enough repeated. Limit to $min_occ.",
    }

    def __init__(self, min_occ=0, max_occ=1, *args, **kwargs):
        super(ItemLimitedOccurrences, self).__init__(*args, **kwargs)
        self.min_occ = min_occ
        self.max_occ = max_occ

        self.message_values['min_occ'] = self.min_occ
        self.message_values['max_occ'] = self.max_occ

    def _get_checking_value(self, value):
        """
        It must be override on descendant validators
        """
        return value

    def _internal_is_valid(self, value, *args, **kwargs):

        def add_occurrence(val, counter):
            if val not in counter:
                counter[val] = 0

            counter[val] += 1

        counter = {}

        for item in value:
            val = self._get_checking_value(item)
            add_occurrence(val, counter)

            if counter[val] > self.max_occ:
                self.error(self.TOO_MANY_ITEM_OCCURRENCES, val)
                return False

        for val, occ in counter.items():
            if occ < self.min_occ:
                self.error(self.TOO_FEW_ITEM_OCCURRENCES, val)
                return False

        return True

def get_field_value_from_context(field_name, context_list):
    """
    Helper to get field value from string path.
    String '<context>' is used to go up on context stack. It just
    can be used at the beginning of path: <context>.<context>.field_name_1
    """
    field_path = field_name.split('.')
    context_index = -1
    while field_path[0] == '<context>':
        context_index -= 1
        field_path.pop(0)

    try:
        field_value = context_list[context_index]

        while len(field_path):
            field = field_path.pop(0)
            if isinstance(field_value, (list, tuple, ListModel)):
                if field.isdigit():
                    field = int(field)
                field_value = field_value[field]
            elif isinstance(field_value, dict):
                try:
                    field_value = field_value[field]
                except KeyError:
                    if field.isdigit():
                        field = int(field)
                        field_value = field_value[field]
                    else:
                        field_value = None

            else:
                field_value = getattr(field_value, field)

        return field_value
    except (IndexError, AttributeError, KeyError):
        return None

class IfField(BaseValidator):

    """
    Conditional validator. It run validators if a specific field value pass validations.
    """

    NEEDS_VALIDATE = 'needsValidate'

    error_messages = {
        NEEDS_VALIDATE: "Some validate error due to field '$field_name' has value '$field_value'.",
    }

    def __init__(self, validator, field_name, field_validator=None,
                 run_if_none=False, add_check_info=True, *args, **kwargs):
        super(IfField, self).__init__(*args, **kwargs)

        self.validator = validator
        self.field_name = field_name
        self.field_validator = field_validator
        self.run_if_none = run_if_none
        self.add_check_info = add_check_info

        self.message_values['field_name'] = field_name

    def _internal_is_valid(self, value, *args, **kwargs):
        field_value = get_field_value_from_context(self.field_name, kwargs.get('context', []))

        if (self.run_if_none or field_value is not None) and \
                (self.field_validator is None or self.field_validator.is_valid(field_value, *args, **kwargs)) and \
                not self.validator.is_valid(value, *args, **kwargs):
            self.messages.update(self.validator.messages)
            if self.add_check_info:
                self.error(self.NEEDS_VALIDATE, value, field_value=field_value)
            return False

        return True

class BaseSpec(ComplexValidator):

    """
    Base class to use spec
    """

    def __init__(self, spec=None, stop_on_fail=True, *args, **kwargs):
        super(BaseSpec, self).__init__(*args, **kwargs)

        if spec is not None:
            self.spec = spec.copy()

        try:
            self.spec
        except AttributeError:
            self.spec = OrderedDict()

        self.stop_on_fail = stop_on_fail

    def _internal_field_validate(self, validator, field_name, field_value, *args, **kwargs):
        if not validator.is_valid(field_value, *args, **kwargs):
            self.import_messages(field_name, validator.messages)
            return False
        return True

    def _internal_is_valid(self, value, *args, **kwargs):
        result = True
        for field_name, validator in self.spec.items():
            field_value = self.get_field_value(field_name, value, kwargs)

            if not self._internal_field_validate(validator, field_name, field_value, *args, **kwargs):
                result = False
                if self.stop_on_fail:
                    return False

        return result

class DictValidate(BaseSpec):

    INVALID_TYPE = 'notDi   ct'

    error_messages = {
        INVALID_TYPE: "'$value' is not a dictionary",
    }

    def get_field_value(self, field_name, value, kwargs):
        return value.get(field_name, None)

    def _internal_is_valid(self, value, *args, **kwargs):
        if not isinstance(value, dict):
            self.error(self.INVALID_TYPE, value)
            return False
        return super(DictValidate, self)._internal_is_valid(value, *args, **kwargs)

class Required(Chain):

    REQUIRED = 'required'

    error_messages = {
        REQUIRED: "Value is required and can not be empty",
    }

    def __init__(self, empty_validator=None, *args, **kwargs):
        self.empty_validator = empty_validator or NotNone()
        super(Required, self).__init__(*args, **kwargs)

    def _internal_is_valid(self, value, *args, **kwargs):
        if not self.empty_validator.is_valid(value):
            self.error(self.REQUIRED, value)
            return False

        return super(Required, self)._internal_is_valid(value, *args, **kwargs)

class Optional(Chain):

    def __init__(self, empty_validator=None, *args, **kwargs):
        self.empty_validator = empty_validator or NotNone()
        super(Optional, self).__init__(*args, **kwargs)

    def _internal_is_valid(self, value, *args, **kwargs):
        if not self.empty_validator.is_valid(value):
            return True

        return Chain._internal_is_valid(self, value, *args, **kwargs)

class ModelValidateMetaclass(type):

    @classmethod
    def __prepare__(metacls, name, bases):  # No keywords in this case
        return OrderedDict()

    def __new__(cls, name, bases, classdict):

        result = super(ModelValidateMetaclass, cls).__new__(
            cls, name, bases, classdict)

        spec = OrderedDict([(field, validator) for field, validator in classdict.items()
                            if hasattr(validator, 'is_valid')])

        setattr(result, 'spec', spec)
        return result

class ModelValidate(BaseSpec, metaclass=ModelValidateMetaclass):

    __modelclass__ = BaseModel

    INVALID_MODEL = 'notModel'

    error_messages = {
        INVALID_MODEL: "'$value' is not an instance of $model",
    }

    def __init__(self, spec=None, *args, **kwargs):
        self.spec = self.spec.copy()
        if spec is not None:
            self.spec.update(spec)

        super(ModelValidate, self).__init__(*args, **kwargs)

    def get_field_value(self, field_name, value, kwargs):
        kwargs['is_modified'] = value.is_modified_field(field_name)

        try:
            return getattr(value, field_name)
        except AttributeError:
            return None

    def _internal_is_valid(self, value, *args, **kwargs):
        if not isinstance(value, self.__modelclass__):
            self.error(self.INVALID_MODEL, value, model=self.__modelclass__.__name__)
            return False

        return super(ModelValidate, self)._internal_is_valid(value, *args, **kwargs)
<|endoftext|>


<commit_before>########################################################################################################################
# Robot Turtles
# Copyright Alexander L Gutierrez 2015
#
# Released under Apache open source license
########################################################################################################################

import subprocess

class NetworkManager:
    '''
    https://github.com/dpaleino/wicd/blob/master/cli/README.cli
    '''

    def __init__(self):
        pass

    def connect(self, saveID, networkName, networkType, networkPassword):
        available_networks = subprocess.check_output(['/usr/bin/wicd-cli','-y','-S', '-l']).split('\n')

        network_count = len(available_networks)

        network_num = None

        for network in available_networks:
            # match network name to available networks
            available_network = network.split('\t')
            print str(available_network)

            network_name = available_network[3]

            if(network_name == networkName):
                print 'Matched Network: '+str(network_name)
                network_num = available_network[0]
                network_bssid = available_network[1]
                break

        network_details = None

        if(network_num == None):
            raise ValueError('Network ' + str(networkName) + ' not found')

        network_details = subprocess.check_output(['/usr/bin/wicd-cli','-y','-n '+ str(network_num),'-d']).split('\n')

        properties = None
        for detail in network_details:
            propertyPair = detail.split(':')
            print(str(propertyPair))
            properties[str(propertyPair[0])] = propertyPair[1]

        encryptionMethod = None
        if(properties.has_key('Encryption')):
            if(properties['Encryption'] == 'On'):
                encryptionMethod = properties['Encryption Method']

        if(encryptionMethod != None):
            print 'Encryption: ' + str(encryptionMethod)

        print str(network_details)

        # Once Found, Configure that specific network
        pass

if(__name__ == '__main__'):
    NetworkManager().connect('default','bananas','WPA2','mysteryspot2')<commit_msg>Slowly working encryption<commit_after>########################################################################################################################
# Robot Turtles
# Copyright Alexander L Gutierrez 2015
#
# Released under Apache open source license
########################################################################################################################

import subprocess

class NetworkManager:
    '''
    https://github.com/dpaleino/wicd/blob/master/cli/README.cli
    '''

    def __init__(self):
        pass

    def connect(self, saveID, networkName, networkType, networkPassword):
        available_networks = subprocess.check_output(['/usr/bin/wicd-cli','-y','-S', '-l']).split('\n')

        network_count = len(available_networks)

        network_num = None

        for network in available_networks:
            # match network name to available networks
            available_network = network.split('\t')
            print str(available_network)

            network_name = available_network[3]

            if(network_name == networkName):
                print 'Matched Network: '+str(network_name)
                network_num = available_network[0]
                network_bssid = available_network[1]
                break

        network_details = None

        if(network_num == None):
            raise ValueError('Network ' + str(networkName) + ' not found')

        network_details = subprocess.check_output(['/usr/bin/wicd-cli','-y','-n '+ str(network_num),'-d']).split('\n')

        properties = None
        for detail in network_details:
            propertyPair = detail.split(':')
            print(str(propertyPair))
            properties[str(propertyPair[0])] = str(propertyPair[1])

        encryptionMethod = None
        if(properties.has_key('Encryption')):
            if(properties['Encryption'] == 'On'):
                encryptionMethod = properties['Encryption Method']

        if(encryptionMethod != None):
            print 'Encryption: ' + str(encryptionMethod)

        print str(network_details)

        # Once Found, Configure that specific network
        pass

if(__name__ == '__main__'):
    NetworkManager().connect('default','bananas','WPA2','mysteryspot2')<|endoftext|>


<commit_before>import sys

from polyjit.buildbot.builders import register
from polyjit.buildbot import slaves
from polyjit.buildbot.utils import (builder, define, git, cmd, ip,
                                    s_abranch, s_dependent, s_force, s_trigger,
                                    hash_upload_to_master,
                                    hash_download_from_master,
                                    clean_unpack, mkdir)
from polyjit.buildbot.repos import make_cb, make_new_cb, codebases
from polyjit.buildbot.master import URL
from buildbot.plugins import util
from buildbot.changes import filter

CODEBASE = make_cb(['polli-sb', 'benchbuild', 'polli'])
FORCE_CODEBASE = make_new_cb(['polli-sb', 'benchbuild', 'polli'])

P = util.Property
BF = util.BuildFactory

ACCEPTED_BUILDERS = \
    slaves.get_hostlist(slaves.infosun,
                        predicate=lambda host: host["host"] in {'debussy', 'ligeti'})

def get_sb_debug_steps(c):
    return [
        define("SUPERBUILD_ROOT", ip("%(prop:builddir)s/polli-sb")),
        define("UCHROOT_SUPERBUILD_ROOT", "/mnt/polli-sb"),
        define("POLYJIT_DEFAULT_BRANCH", "master"),

        git('polli-sb', 'master', codebases, workdir=P("SUPERBUILD_ROOT"),
            mode="full", method="fresh"),
        cmd(ip('%(prop:cmake_prefix)s/bin/cmake'), P("SUPERBUILD_ROOT"),
            ip('-DCMAKE_CXX_COMPILER=%(prop:cxx)s'),
            ip('-DCMAKE_C_COMPILER=%(prop:cc)s'),
            '-DCMAKE_BUILD_TYPE=Debug',
            '-DCMAKE_INSTALL_PREFIX=./_install',
            '-DBUILD_SHARED_LIBS=Off',
            '-DPOLYJIT_PAPI_PREFIX=/scratch/pjtest/opt/papi-5.5.1/install',
            ip('-DPOLYJIT_BRANCH_CLANG=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_LLVM=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_POLLI=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_POLLY=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            '-G', 'Ninja',
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            name="cmake",
            logEnviron=True,
            description="[uchroot] cmake: release build",
            descriptionDone="[uchroot] configured."),
        cmd("/usr/bin/ninja", "llvm-configure",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="configure LLVM",
            description="configuring LLVM",
            descriptionDone="configured LLVM",
            timeout=4800),
        cmd("/usr/bin/ninja", "polli-configure",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="configure PolyJIT",
            description="configuring PolyJIT",
            descriptionDone="configured PolyJIT",
            timeout=4800),
        cmd("/usr/bin/ninja",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="build jit",
            description="[uchroot] building PolyJIT",
            descriptionDone="[uchroot] built PolyJIT",
            timeout=4800),
    ]

def configure(c):
    sb_steps = [
        define("SUPERBUILD_ROOT", ip("%(prop:builddir)s/polli-sb")),
        define("UCHROOT_SUPERBUILD_ROOT", "/mnt/polli-sb"),
        define("POLYJIT_DEFAULT_BRANCH", "master"),

        git('polli-sb', 'master', codebases, workdir=P("SUPERBUILD_ROOT"),
            mode="full", method="fresh"),
        cmd(ip('%(prop:cmake_prefix)s/bin/cmake'), P("SUPERBUILD_ROOT"),
            ip('-DCMAKE_CXX_COMPILER=%(prop:cxx)s'),
            ip('-DCMAKE_C_COMPILER=%(prop:cc)s'),
            '-DCMAKE_BUILD_TYPE=Release',
            '-DCMAKE_INSTALL_PREFIX=./_install',
            '-DCMAKE_CXX_FLAGS_RELEASE=-O3 -DNDEBUG -DLLVM_ENABLE_STATS',
            '-DBUILD_SHARED_LIBS=Off',
            '-DPOLYJIT_PAPI_PREFIX=/scratch/pjtest/opt/papi-5.5.1/install',
            ip('-DPOLYJIT_BRANCH_CLANG=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_LLVM=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_POLLI=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_POLLY=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            '-G', 'Ninja',
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            name="cmake",
            logEnviron=True,
            description="[uchroot] cmake: release build",
            descriptionDone="[uchroot] configured."),
        cmd("/usr/bin/ninja", "llvm-configure",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="configure LLVM",
            description="configuring LLVM",
            descriptionDone="configured LLVM",
            timeout=4800),
        cmd("/usr/bin/ninja", "polli-configure",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="configure PolyJIT",
            description="configuring PolyJIT",
            descriptionDone="configured PolyJIT",
            timeout=4800),
        cmd("/usr/bin/ninja",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="build jit",
            description="[uchroot] building PolyJIT",
            descriptionDone="[uchroot] built PolyJIT",
            timeout=4800),
        cmd("tar", "czf", "../polyjit_sb.tar.gz", "-C", "./_install", ".")
    ]

    sb_steps.extend(hash_upload_to_master(
        "polyjit_sb.tar.gz",
        "../polyjit_sb.tar.gz",
        "public_html/polyjit_sb.tar.gz", URL))

    slurm_steps = [
        define("scratch", ip("/scratch/pjtest/sb-%(prop:buildnumber)s/"))
    ]
    slurm_steps.extend(hash_download_from_master(
        "public_html/polyjit_sb.tar.gz", "polyjit_sb.tar.gz", "polyjit"))
    slurm_steps.extend(clean_unpack("polyjit_sb.tar.gz", "llvm"))
    slurm_steps.extend([
        define("BENCHBUILD_ROOT", ip("%(prop:builddir)s/build/benchbuild/")),
        git('benchbuild', 'master', codebases, workdir=P("BENCHBUILD_ROOT")),
        define('benchbuild', ip('%(prop:scratch)s/env/bin/benchbuild')),
        define('llvm', ip('%(prop:scratch)s/llvm')),
        define('bb_src', ip('%(prop:scratch)s/benchbuild')),

        cmd('virtualenv', '-ppython3', ip('%(prop:scratch)s/env')),
        cmd(ip('%(prop:scratch)s/env/bin/pip3'), 'install',
            P("BENCHBUILD_ROOT")),
        mkdir(P("scratch")),
        cmd("rsync", "-var", "llvm", P("scratch")),
        cmd(P('benchbuild'), 'bootstrap', '-s', logEnviron=True, env={
            'BB_CONFIG_FILE': '/scratch/pjtest/.benchbuild.json',
            'BB_TMP_DIR': '/scratch/pjtest/src/',
            'BB_TEST_DIR': P("testinputs"),
            'BB_GENTOO_AUTOTEST_LOC': '/scratch/pjtest/gentoo-autotest',
            'BB_SLURM_PARTITION': 'anywhere',
            'BB_SLURM_NODE_DIR': '/local/hdd/buildbot-polyjit/',
            'BB_SLURM_ACCOUNT': 'anywhere',
            'BB_SLURM_TIMELIMIT': '24:00:00',
            'BB_CONTAINER_MOUNTS': ip('["%(prop:llvm)s", "%(prop:bb_src)s"]'),
            'BB_CONTAINER_PREFIXES':
                '["/opt/benchbuild", '
                '"/", '
                '"/usr", '
                '"/usr/local"]',
            'BB_ENV_PATH':
                ip('["/scratch/pjtest/opt/papi-5.5.1/install/bin", '
                   '"%(prop:llvm)s/bin", '
                   '"%(prop:llvm_prefix)s/bin", '
                   '"/scratch/pjtest/erlent/build"]'),
            'BB_ENV_LD_LIBRARY_PATH':
                ip('["/scratch/pjtest/opt/papi-5.5.1/install/lib", '
                   '"%(prop:llvm)s/lib", '
                   '"%(prop:llvm_libs)s", '
                   '"/scratch/pjtest/erlent/build"]'),
            'BB_LLVM_DIR': ip('%(prop:scratch)s/llvm'),
            'BB_LIKWID_PREFIX': '/usr',
            'BB_PAPI_INCLUDE': '/usr/include',
            'BB_PAPI_LIBRARY': '/usr/lib',
            'BB_SRC_DIR': ip('%(prop:bb_src)s'),
            'BB_SLURM_LOGS': ip('%(prop:scratch)s/slurm.log'),
            'BB_UNIONFS_ENABLE': 'false'
            },
            workdir=P('scratch')),
        # This only works on infosun machines
        cmd("ln", "-s", ip("/scratch/pjtest/benchbuild-src/"),
            ip("%(prop:bb_src)s")),
        mkdir(ip("%(prop:scratch)s/results"))
    ])

    c['builders'].append(
        builder("polyjit-superbuild-debug", None,
                ACCEPTED_BUILDERS, tags=['polyjit'],
                collapseRequests=True,
                factory=BF(get_sb_debug_steps(c))))
    c['builders'].append(
        builder("polyjit-superbuild", None,
                ACCEPTED_BUILDERS, tags=['polyjit'],
                collapseRequests=True,
                factory=BF(sb_steps)))
    c['builders'].append(
        builder("polyjit-superbuild-slurm", None,
                ACCEPTED_BUILDERS, tags=['polyjit'],
                collapseRequests=True,
                factory=BF(slurm_steps)))

def schedule(c):
    superbuild_sched = s_abranch("bs_polyjit-superbuild",
                                 CODEBASE, [
                                     "polyjit-superbuild",
                                     "polyjit-superbuild-debug"],
                                 treeStableTimer=10 * 60)
    c['schedulers'].extend([
        superbuild_sched,
        s_force("fs_polyjit-superbuild", FORCE_CODEBASE,
                ["polyjit-superbuild"]),
        s_trigger("ts_polyjit-superbuild", CODEBASE,
                  ["polyjit-superbuild"]),

        s_force("fs_polyjit-superbuild-debug", FORCE_CODEBASE,
                ["polyjit-superbuild-debug"]),
        s_trigger("ts_polyjit-superbuild-debug", CODEBASE,
                  ["polyjit-superbuild-debug"]),

        s_dependent("ds_polyjit-superbuild-slurm",
                    superbuild_sched,
                    ["polyjit-superbuild-slurm"]),
        s_force("fs_polyjit-superbuild-slurm", FORCE_CODEBASE,
                ["polyjit-superbuild-slurm"])
    ])

register(sys.modules[__name__])
<commit_msg>superbuild: reduce stable timer to 2 min<commit_after>import sys

from polyjit.buildbot.builders import register
from polyjit.buildbot import slaves
from polyjit.buildbot.utils import (builder, define, git, cmd, ip,
                                    s_abranch, s_dependent, s_force, s_trigger,
                                    hash_upload_to_master,
                                    hash_download_from_master,
                                    clean_unpack, mkdir)
from polyjit.buildbot.repos import make_cb, make_new_cb, codebases
from polyjit.buildbot.master import URL
from buildbot.plugins import util
from buildbot.changes import filter

CODEBASE = make_cb(['polli-sb', 'benchbuild', 'polli'])
FORCE_CODEBASE = make_new_cb(['polli-sb', 'benchbuild', 'polli'])

P = util.Property
BF = util.BuildFactory

ACCEPTED_BUILDERS = \
    slaves.get_hostlist(slaves.infosun,
                        predicate=lambda host: host["host"] in {'debussy', 'ligeti'})

def get_sb_debug_steps(c):
    return [
        define("SUPERBUILD_ROOT", ip("%(prop:builddir)s/polli-sb")),
        define("UCHROOT_SUPERBUILD_ROOT", "/mnt/polli-sb"),
        define("POLYJIT_DEFAULT_BRANCH", "master"),

        git('polli-sb', 'master', codebases, workdir=P("SUPERBUILD_ROOT"),
            mode="full", method="fresh"),
        cmd(ip('%(prop:cmake_prefix)s/bin/cmake'), P("SUPERBUILD_ROOT"),
            ip('-DCMAKE_CXX_COMPILER=%(prop:cxx)s'),
            ip('-DCMAKE_C_COMPILER=%(prop:cc)s'),
            '-DCMAKE_BUILD_TYPE=Debug',
            '-DCMAKE_INSTALL_PREFIX=./_install',
            '-DBUILD_SHARED_LIBS=Off',
            '-DPOLYJIT_PAPI_PREFIX=/scratch/pjtest/opt/papi-5.5.1/install',
            ip('-DPOLYJIT_BRANCH_CLANG=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_LLVM=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_POLLI=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_POLLY=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            '-G', 'Ninja',
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            name="cmake",
            logEnviron=True,
            description="[uchroot] cmake: release build",
            descriptionDone="[uchroot] configured."),
        cmd("/usr/bin/ninja", "llvm-configure",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="configure LLVM",
            description="configuring LLVM",
            descriptionDone="configured LLVM",
            timeout=4800),
        cmd("/usr/bin/ninja", "polli-configure",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="configure PolyJIT",
            description="configuring PolyJIT",
            descriptionDone="configured PolyJIT",
            timeout=4800),
        cmd("/usr/bin/ninja",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="build jit",
            description="[uchroot] building PolyJIT",
            descriptionDone="[uchroot] built PolyJIT",
            timeout=4800),
    ]

def configure(c):
    sb_steps = [
        define("SUPERBUILD_ROOT", ip("%(prop:builddir)s/polli-sb")),
        define("UCHROOT_SUPERBUILD_ROOT", "/mnt/polli-sb"),
        define("POLYJIT_DEFAULT_BRANCH", "master"),

        git('polli-sb', 'master', codebases, workdir=P("SUPERBUILD_ROOT"),
            mode="full", method="fresh"),
        cmd(ip('%(prop:cmake_prefix)s/bin/cmake'), P("SUPERBUILD_ROOT"),
            ip('-DCMAKE_CXX_COMPILER=%(prop:cxx)s'),
            ip('-DCMAKE_C_COMPILER=%(prop:cc)s'),
            '-DCMAKE_BUILD_TYPE=Release',
            '-DCMAKE_INSTALL_PREFIX=./_install',
            '-DCMAKE_CXX_FLAGS_RELEASE=-O3 -DNDEBUG -DLLVM_ENABLE_STATS',
            '-DBUILD_SHARED_LIBS=Off',
            '-DPOLYJIT_PAPI_PREFIX=/scratch/pjtest/opt/papi-5.5.1/install',
            ip('-DPOLYJIT_BRANCH_CLANG=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_LLVM=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_POLLI=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            ip('-DPOLYJIT_BRANCH_POLLY=%(prop:POLYJIT_DEFAULT_BRANCH)s'),
            '-G', 'Ninja',
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            name="cmake",
            logEnviron=True,
            description="[uchroot] cmake: release build",
            descriptionDone="[uchroot] configured."),
        cmd("/usr/bin/ninja", "llvm-configure",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="configure LLVM",
            description="configuring LLVM",
            descriptionDone="configured LLVM",
            timeout=4800),
        cmd("/usr/bin/ninja", "polli-configure",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="configure PolyJIT",
            description="configuring PolyJIT",
            descriptionDone="configured PolyJIT",
            timeout=4800),
        cmd("/usr/bin/ninja",
            usePTY=True,
            env={"LD_LIBRARY_PATH": P("llvm_libs")},
            logEnviron=True,
            haltOnFailure=True,
            name="build jit",
            description="[uchroot] building PolyJIT",
            descriptionDone="[uchroot] built PolyJIT",
            timeout=4800),
        cmd("tar", "czf", "../polyjit_sb.tar.gz", "-C", "./_install", ".")
    ]

    sb_steps.extend(hash_upload_to_master(
        "polyjit_sb.tar.gz",
        "../polyjit_sb.tar.gz",
        "public_html/polyjit_sb.tar.gz", URL))

    slurm_steps = [
        define("scratch", ip("/scratch/pjtest/sb-%(prop:buildnumber)s/"))
    ]
    slurm_steps.extend(hash_download_from_master(
        "public_html/polyjit_sb.tar.gz", "polyjit_sb.tar.gz", "polyjit"))
    slurm_steps.extend(clean_unpack("polyjit_sb.tar.gz", "llvm"))
    slurm_steps.extend([
        define("BENCHBUILD_ROOT", ip("%(prop:builddir)s/build/benchbuild/")),
        git('benchbuild', 'master', codebases, workdir=P("BENCHBUILD_ROOT")),
        define('benchbuild', ip('%(prop:scratch)s/env/bin/benchbuild')),
        define('llvm', ip('%(prop:scratch)s/llvm')),
        define('bb_src', ip('%(prop:scratch)s/benchbuild')),

        cmd('virtualenv', '-ppython3', ip('%(prop:scratch)s/env')),
        cmd(ip('%(prop:scratch)s/env/bin/pip3'), 'install',
            P("BENCHBUILD_ROOT")),
        mkdir(P("scratch")),
        cmd("rsync", "-var", "llvm", P("scratch")),
        cmd(P('benchbuild'), 'bootstrap', '-s', logEnviron=True, env={
            'BB_CONFIG_FILE': '/scratch/pjtest/.benchbuild.json',
            'BB_TMP_DIR': '/scratch/pjtest/src/',
            'BB_TEST_DIR': P("testinputs"),
            'BB_GENTOO_AUTOTEST_LOC': '/scratch/pjtest/gentoo-autotest',
            'BB_SLURM_PARTITION': 'anywhere',
            'BB_SLURM_NODE_DIR': '/local/hdd/buildbot-polyjit/',
            'BB_SLURM_ACCOUNT': 'anywhere',
            'BB_SLURM_TIMELIMIT': '24:00:00',
            'BB_CONTAINER_MOUNTS': ip('["%(prop:llvm)s", "%(prop:bb_src)s"]'),
            'BB_CONTAINER_PREFIXES':
                '["/opt/benchbuild", '
                '"/", '
                '"/usr", '
                '"/usr/local"]',
            'BB_ENV_PATH':
                ip('["/scratch/pjtest/opt/papi-5.5.1/install/bin", '
                   '"%(prop:llvm)s/bin", '
                   '"%(prop:llvm_prefix)s/bin", '
                   '"/scratch/pjtest/erlent/build"]'),
            'BB_ENV_LD_LIBRARY_PATH':
                ip('["/scratch/pjtest/opt/papi-5.5.1/install/lib", '
                   '"%(prop:llvm)s/lib", '
                   '"%(prop:llvm_libs)s", '
                   '"/scratch/pjtest/erlent/build"]'),
            'BB_LLVM_DIR': ip('%(prop:scratch)s/llvm'),
            'BB_LIKWID_PREFIX': '/usr',
            'BB_PAPI_INCLUDE': '/usr/include',
            'BB_PAPI_LIBRARY': '/usr/lib',
            'BB_SRC_DIR': ip('%(prop:bb_src)s'),
            'BB_SLURM_LOGS': ip('%(prop:scratch)s/slurm.log'),
            'BB_UNIONFS_ENABLE': 'false'
            },
            workdir=P('scratch')),
        # This only works on infosun machines
        cmd("ln", "-s", ip("/scratch/pjtest/benchbuild-src/"),
            ip("%(prop:bb_src)s")),
        mkdir(ip("%(prop:scratch)s/results"))
    ])

    c['builders'].append(
        builder("polyjit-superbuild-debug", None,
                ACCEPTED_BUILDERS, tags=['polyjit'],
                collapseRequests=True,
                factory=BF(get_sb_debug_steps(c))))
    c['builders'].append(
        builder("polyjit-superbuild", None,
                ACCEPTED_BUILDERS, tags=['polyjit'],
                collapseRequests=True,
                factory=BF(sb_steps)))
    c['builders'].append(
        builder("polyjit-superbuild-slurm", None,
                ACCEPTED_BUILDERS, tags=['polyjit'],
                collapseRequests=True,
                factory=BF(slurm_steps)))

def schedule(c):
    superbuild_sched = s_abranch("bs_polyjit-superbuild",
                                 CODEBASE, [
                                     "polyjit-superbuild",
                                     "polyjit-superbuild-debug"],
                                 treeStableTimer=2 * 60)
    c['schedulers'].extend([
        superbuild_sched,
        s_force("fs_polyjit-superbuild", FORCE_CODEBASE,
                ["polyjit-superbuild"]),
        s_trigger("ts_polyjit-superbuild", CODEBASE,
                  ["polyjit-superbuild"]),

        s_force("fs_polyjit-superbuild-debug", FORCE_CODEBASE,
                ["polyjit-superbuild-debug"]),
        s_trigger("ts_polyjit-superbuild-debug", CODEBASE,
                  ["polyjit-superbuild-debug"]),

        s_dependent("ds_polyjit-superbuild-slurm",
                    superbuild_sched,
                    ["polyjit-superbuild-slurm"]),
        s_force("fs_polyjit-superbuild-slurm", FORCE_CODEBASE,
                ["polyjit-superbuild-slurm"])
    ])

register(sys.modules[__name__])
<|endoftext|>


<commit_before>from odoo.tests.common import TransactionCase

class ConfigurationRules(TransactionCase):

    def setUp(self):
        super(ConfigurationRules, self).setUp()

        self.cfg_session = self.env['product.config.session']
        self.cfg_tmpl = self.env.ref('product_configurator.bmw_2_series')

        attribute_vals = self.cfg_tmpl.attribute_line_ids.mapped('value_ids')
        self.attr_vals = self.cfg_tmpl.attribute_line_ids.mapped('value_ids')

        self.attr_val_ext_ids = {
            v: k for k, v in attribute_vals.get_external_id().items()
        }

    def get_attr_val_ids(self, ext_ids):
        """Return a list of database ids using the external_ids
        passed via ext_ids argument"""

        value_ids = []

        attr_val_prefix = 'product_configurator.product_attribute_value_%s'

        for ext_id in ext_ids:
            if ext_id in self.attr_val_ext_ids:
                value_ids.append(self.attr_val_ext_ids[ext_id])
            elif attr_val_prefix % ext_id in self.attr_val_ext_ids:
                value_ids.append(
                    self.attr_val_ext_ids[attr_val_prefix % ext_id]
                )

        return value_ids

    def test_valid_configuration(self):
        """Test validation of a valid configuration"""

        conf = [
            'gasoline', '228i', 'model_luxury_line', 'silver', 'rims_384',
            'tapistry_black', 'steptronic', 'smoker_package', 'tow_hook'
        ]

        attr_val_ids = self.get_attr_val_ids(conf)
        validation = self.cfg_session.validate_configuration(attr_val_ids)
        self.assertTrue(validation, "Valid configuration failed validation")

    def test_invalid_configuration(self):

        conf = [
            'diesel', '228i', 'model_luxury_line', 'silver', 'rims_384',
            'tapistry_black', 'steptronic', 'smoker_package', 'tow_hook'
        ]

        attr_val_ids = self.get_attr_val_ids(conf)
        validation = self.cfg_session.validate_configuration(attr_val_ids)
        self.assertFalse(validation, "Incompatible values (Diesel Fuel -> "
                         "Gasoline Engine) configuration passed validation")

    def test_missing_val_configuration(self):
        conf = [
            'diesel', '228i', 'model_luxury_line', 'rims_384',
            'tapistry_black', 'steptronic', 'smoker_package', 'tow_hook'
        ]

        attr_val_ids = self.get_attr_val_ids(conf)
        validation = self.cfg_session.validate_configuration(attr_val_ids)
        self.assertFalse(validation, "Configuration with missing required "
                         "values passed validation")

    def test_invalid_multi_configuration(self):
        conf = [
            'gasoline', '228i', 'model_luxury_line', 'silver', 'red',
            'rims_384', 'tapistry_black', 'steptronic', 'smoker_package',
            'tow_hook'
        ]

        attr_val_ids = self.get_attr_val_ids(conf)
        validation = self.cfg_session.validate_configuration(attr_val_ids)
        self.assertFalse(validation, "Configuration with multiple values for "
                         "attribute color passed validation")

    def test_invalid_custom_value_configuration(self):
        conf = [
            'gasoline', '228i', 'model_luxury_line', 'rims_384',
            'tapistry_black', 'steptronic', 'smoker_package',
            'tow_hook'
        ]

        attr_color_id = self.env.ref(
            'product_configurator.product_attribute_color')

        custom_vals = {
            attr_color_id: {'value': '#fefefe'}
        }

        attr_val_ids = self.get_attr_val_ids(conf)
        validation = self.cfg_session.validate_configuration(
            attr_val_ids, custom_vals)

        self.assertFalse(validation, "Custom value accepted for fixed "
                         "attribute color")

    # TODO: Test configuration with disallowed custom type value
<commit_msg>Creating new config.session for testcases, adapting to new design<commit_after>from odoo.tests.common import TransactionCase
from odoo import SUPERUSER_ID

class ConfigurationRules(TransactionCase):

    def setUp(self):
        super(ConfigurationRules, self).setUp()

        self.cfg_tmpl = self.env.ref('product_configurator.bmw_2_series')
        self.cfg_session = self.env['product.config.session'].create({
            'product_tmpl_id': self.cfg_tmpl.id,
            'user_id': SUPERUSER_ID
        })

        attribute_vals = self.cfg_tmpl.attribute_line_ids.mapped('value_ids')
        self.attr_vals = self.cfg_tmpl.attribute_line_ids.mapped('value_ids')

        self.attr_val_ext_ids = {
            v: k for k, v in attribute_vals.get_external_id().items()
        }

    def get_attr_val_ids(self, ext_ids):
        """Return a list of database ids using the external_ids
        passed via ext_ids argument"""

        value_ids = []

        attr_val_prefix = 'product_configurator.product_attribute_value_%s'

        for ext_id in ext_ids:
            if ext_id in self.attr_val_ext_ids:
                value_ids.append(self.attr_val_ext_ids[ext_id])
            elif attr_val_prefix % ext_id in self.attr_val_ext_ids:
                value_ids.append(
                    self.attr_val_ext_ids[attr_val_prefix % ext_id]
                )

        return value_ids

    def test_valid_configuration(self):
        """Test validation of a valid configuration"""

        conf = [
            'gasoline', '228i', 'model_luxury_line', 'silver', 'rims_384',
            'tapistry_black', 'steptronic', 'smoker_package', 'tow_hook'
        ]

        attr_val_ids = self.get_attr_val_ids(conf)
        validation = self.cfg_session.validate_configuration(attr_val_ids)
        self.assertTrue(validation, "Valid configuration failed validation")

    def test_invalid_configuration(self):

        conf = [
            'diesel', '228i', 'model_luxury_line', 'silver', 'rims_384',
            'tapistry_black', 'steptronic', 'smoker_package', 'tow_hook'
        ]

        attr_val_ids = self.get_attr_val_ids(conf)
        validation = self.cfg_session.validate_configuration(attr_val_ids)
        self.assertFalse(validation, "Incompatible values (Diesel Fuel -> "
                         "Gasoline Engine) configuration passed validation")

    def test_missing_val_configuration(self):
        conf = [
            'diesel', '228i', 'model_luxury_line', 'rims_384',
            'tapistry_black', 'steptronic', 'smoker_package', 'tow_hook'
        ]

        attr_val_ids = self.get_attr_val_ids(conf)
        validation = self.cfg_session.validate_configuration(attr_val_ids)
        self.assertFalse(validation, "Configuration with missing required "
                         "values passed validation")

    def test_invalid_multi_configuration(self):
        conf = [
            'gasoline', '228i', 'model_luxury_line', 'silver', 'red',
            'rims_384', 'tapistry_black', 'steptronic', 'smoker_package',
            'tow_hook'
        ]

        attr_val_ids = self.get_attr_val_ids(conf)
        validation = self.cfg_session.validate_configuration(attr_val_ids)
        self.assertFalse(validation, "Configuration with multiple values for "
                         "attribute color passed validation")

    def test_invalid_custom_value_configuration(self):
        conf = [
            'gasoline', '228i', 'model_luxury_line', 'rims_384',
            'tapistry_black', 'steptronic', 'smoker_package',
            'tow_hook'
        ]

        attr_color_id = self.env.ref(
            'product_configurator.product_attribute_color')

        custom_vals = {
            attr_color_id: {'value': '#fefefe'}
        }

        attr_val_ids = self.get_attr_val_ids(conf)
        validation = self.cfg_session.validate_configuration(
            attr_val_ids, custom_vals)

        self.assertFalse(validation, "Custom value accepted for fixed "
                         "attribute color")

    # TODO: Test configuration with disallowed custom type value
<|endoftext|>


<commit_before>import cbor
from grpc.beta import implementations

from mediachain.datastore.data_objects import MultihashReference
from mediachain.proto import Transactor_pb2  # pylint: disable=no-name-in-module
from mediachain.proto import Types_pb2  # pylint: disable=no-name-in-module
import mediachain.reader.api as reader

TIMEOUT_SECS = 120

class TransactorClient(object):

    def __init__(self, host, port):
        self.host = host
        self.port = port
        channel = implementations.insecure_channel(host, port)
        self.client = Transactor_pb2.beta_create_TransactorService_stub(channel)

    def insert_canonical(self, record, timeout=TIMEOUT_SECS):
        try:
            cbor_bytes = record.to_cbor_bytes()
        except AttributeError:
            cbor_bytes = cbor.dumps(record)

        req = Transactor_pb2.InsertRequest(canonicalCbor=cbor_bytes)
        ref = self.client.InsertCanonical(req, timeout)
        return MultihashReference.from_base58(ref.reference)

    def get_chain_head(self, ref, timeout=TIMEOUT_SECS):
        req = Types_pb2.MultihashReference(reference=ref)
        response = self.client.LookupChain(req, timeout)
        if response.WhichOneof('reference') == 'chain':
            return MultihashReference.from_base58(
                response.chain.reference
            )
        return None

    def update_chain(self, cell, timeout=TIMEOUT_SECS):
        try:
            cbor_bytes = cell.to_cbor_bytes()
        except AttributeError:
            cbor_bytes = cbor.dumps(cell)

        req = Transactor_pb2.UpdateRequest(chainCellCbor=cbor_bytes)
        ref = self.client.UpdateChain(req, timeout)
        return MultihashReference.from_base58(ref.reference)

    def journal_stream(self, timeout=TIMEOUT_SECS):
        req = Transactor_pb2.JournalStreamRequest()
        return self.client.JournalStream(req, timeout)

    def canonical_stream(self, timeout=TIMEOUT_SECS):
        for event in self.journal_stream(timeout):
            if event.WhichOneof("event") == "updateChainEvent":
                ref = event.updateChainEvent.canonical.reference
                obj = reader.get_object(self, ref)
                yield obj
<commit_msg>use backoff / retry for transient transactor rpc errors<commit_after>import cbor
from grpc.beta import implementations
from mediachain.rpc.utils import with_retry
from mediachain.datastore.data_objects import MultihashReference
from mediachain.proto import Transactor_pb2  # pylint: disable=no-name-in-module
from mediachain.proto import Types_pb2  # pylint: disable=no-name-in-module
import mediachain.reader.api as reader

TIMEOUT_SECS = 120

class TransactorClient(object):

    def __init__(self, host, port):
        self.host = host
        self.port = port
        channel = implementations.insecure_channel(host, port)
        self.client = Transactor_pb2.beta_create_TransactorService_stub(channel)

    def insert_canonical(self, record, timeout=TIMEOUT_SECS):
        try:
            cbor_bytes = record.to_cbor_bytes()
        except AttributeError:
            cbor_bytes = cbor.dumps(record)

        req = Transactor_pb2.InsertRequest(canonicalCbor=cbor_bytes)
        ref = with_retry(self.client.InsertCanonical, req, timeout)
        return MultihashReference.from_base58(ref.reference)

    def get_chain_head(self, ref, timeout=TIMEOUT_SECS):
        req = Types_pb2.MultihashReference(reference=ref)
        response = with_retry(self.client.LookupChain, req, timeout)
        if response.WhichOneof('reference') == 'chain':
            return MultihashReference.from_base58(
                response.chain.reference
            )
        return None

    def update_chain(self, cell, timeout=TIMEOUT_SECS):
        try:
            cbor_bytes = cell.to_cbor_bytes()
        except AttributeError:
            cbor_bytes = cbor.dumps(cell)

        req = Transactor_pb2.UpdateRequest(chainCellCbor=cbor_bytes)
        ref = with_retry(self.client.UpdateChain, req, timeout)
        return MultihashReference.from_base58(ref.reference)

    def journal_stream(self, timeout=TIMEOUT_SECS):
        req = Transactor_pb2.JournalStreamRequest()
        return with_retry(self.client.JournalStream, req, timeout)

    def canonical_stream(self, timeout=TIMEOUT_SECS):
        for event in self.journal_stream(timeout):
            if event.WhichOneof("event") == "updateChainEvent":
                ref = event.updateChainEvent.canonical.reference
                obj = reader.get_object(self, ref)
                yield obj
<|endoftext|>


<commit_before>from bottle import route, request, error, abort, static_file
from bottle import template, jinja2_view
import bottle, waitress, os, glob, string, pprint

cache = dict()

def find_file(type, name):
  """ searches file within directory by name, ignoring extension and case """
  assert type.isalpha() and name.replace('-', '').isalpha()
  type = type.lower()
  name = name.lower()
  dir = 'files/' + type

  if os.path.isdir(dir):
    iname = ''.join(['[' + c.lower() + c.upper() + ']' for c in name])
    options = [os.path.basename(f)[1:] for f in glob.glob(dir + '/.*')]
    files = [os.path.basename(f) for f in glob.glob(dir + '/' + iname + '.*')]
    if len(files) >= 1:
      return [options, dir, files[0]]
  return False

def list_files(type):
  """ lists file within directory, ignoring extension and case """
  assert type.isalpha()
  type = type.lower()
  dir = 'files/' + type
  if os.path.isdir(dir):
    files = []
    for root, dirs, _files in os.walk(dir):
      for f in _files:
        if f[0] != '.':
          split = string.split(f, '.')
          files.append(split[0].lower())
    files.sort()
    return files
  return False

def list_types():
  """ lists types (directories), ignoring case and symlinks """
  types = []
  for root, dirs, files in os.walk('files'):
    for d in dirs:
      if os.path.islink('files/' + d) is False:
        types.append(d)
  types.sort()
  return types

@error(404)
@jinja2_view('404.html')
def error404(error):
  return dict()

@route('/static/<filepath:path>')
def serve_static(filepath):
  return static_file(filepath, root='./static')

@route('/')
@jinja2_view('home.html')
def get_home():
  if 'types' in cache:
    types = cache['types']
  else:
    types = list_types()
    cache['types'] = types
  return dict(types=types)

@route('/<type:re:[a-zA-Z]+/?>')
@jinja2_view('listing.html')
def get_type(type):
  type = type.replace('/', '')

  if 'files.' + type in cache:
    files = cache['files.' + type]
  else:
    files = list_files(type)
    cache['files.' + type] = files

  if files:
    return dict(type=type, files=files)
  else:
    abort(404, 'Category not found')

@route('/<type:re:[a-zA-Z]+>/<name:re:[a-zA-Z-]+>')
def get_file(type, name):
  lookup = find_file(type, name)

  if lookup:
    options, dir, filename = lookup

    download = False
    # todo: make dl flag logic more concise
    if request.query_string == 'download' or request.query_string == 'dl':
      split = string.split(filename, '.')
      download = True

      if 'no-dot' in options:
        # name.ext -> ext
        download = split[1]
      elif 'no-name' in options:
        # name.ext -> .ext
        download = '.' + split[1]
    return static_file(filename, dir, mimetype='text/plain', download=download)
  else:
    abort(404, 'File not found')

if os.environ['ENV'] == 'dev':
  waitress.serve(bottle.default_app())
else:
  waitress.serve(bottle.default_app(), unix_socket='/tmp/quickstart.sock')<commit_msg>fix keyerror<commit_after>from bottle import route, request, error, abort, static_file
from bottle import template, jinja2_view
import bottle, waitress, os, glob, string, pprint

cache = dict()

def find_file(type, name):
  """ searches file within directory by name, ignoring extension and case """
  assert type.isalpha() and name.replace('-', '').isalpha()
  type = type.lower()
  name = name.lower()
  dir = 'files/' + type

  if os.path.isdir(dir):
    iname = ''.join(['[' + c.lower() + c.upper() + ']' for c in name])
    options = [os.path.basename(f)[1:] for f in glob.glob(dir + '/.*')]
    files = [os.path.basename(f) for f in glob.glob(dir + '/' + iname + '.*')]
    if len(files) >= 1:
      return [options, dir, files[0]]
  return False

def list_files(type):
  """ lists file within directory, ignoring extension and case """
  assert type.isalpha()
  type = type.lower()
  dir = 'files/' + type
  if os.path.isdir(dir):
    files = []
    for root, dirs, _files in os.walk(dir):
      for f in _files:
        if f[0] != '.':
          split = string.split(f, '.')
          files.append(split[0].lower())
    files.sort()
    return files
  return False

def list_types():
  """ lists types (directories), ignoring case and symlinks """
  types = []
  for root, dirs, files in os.walk('files'):
    for d in dirs:
      if os.path.islink('files/' + d) is False:
        types.append(d)
  types.sort()
  return types

@error(404)
@jinja2_view('404.html')
def error404(error):
  return dict()

@route('/static/<filepath:path>')
def serve_static(filepath):
  return static_file(filepath, root='./static')

@route('/')
@jinja2_view('home.html')
def get_home():
  if 'types' in cache:
    types = cache['types']
  else:
    types = list_types()
    cache['types'] = types
  return dict(types=types)

@route('/<type:re:[a-zA-Z]+/?>')
@jinja2_view('listing.html')
def get_type(type):
  type = type.replace('/', '')

  if 'files.' + type in cache:
    files = cache['files.' + type]
  else:
    files = list_files(type)
    cache['files.' + type] = files

  if files:
    return dict(type=type, files=files)
  else:
    abort(404, 'Category not found')

@route('/<type:re:[a-zA-Z]+>/<name:re:[a-zA-Z-]+>')
def get_file(type, name):
  lookup = find_file(type, name)

  if lookup:
    options, dir, filename = lookup

    download = False
    # todo: make dl flag logic more concise
    if request.query_string == 'download' or request.query_string == 'dl':
      split = string.split(filename, '.')
      download = True

      if 'no-dot' in options:
        # name.ext -> ext
        download = split[1]
      elif 'no-name' in options:
        # name.ext -> .ext
        download = '.' + split[1]
    return static_file(filename, dir, mimetype='text/plain', download=download)
  else:
    abort(404, 'File not found')

if 'ENV' in os.environ and os.environ['ENV'] == 'dev':
  waitress.serve(bottle.default_app())
else:
  waitress.serve(bottle.default_app(), unix_socket='/tmp/quickstart.sock')<|endoftext|>


<commit_before>#
# Copyright (c) 2004 Specifix, Inc.
# All rights reserved
#
import os
import versions
import sys

class SrsConfiguration:

    def read(self, file):
	if os.path.exists(file):
	    f = open(file, "r")
	    for line in f:
		self.configLine(line)
	    f.close()

    def configLine(self, line):
	line = line.strip()
	if not line or line[0] == '#':
	    return
	(key, val) = line.split()
	if not self.__dict__.has_key(key):
	    raise KeyError, ("configuration value %s unknown" % key)

	self.__dict__[key] = val

	if key == "defaultbranch":
	    self.defaultbranch = versions.VersionFromString(self.defaultbranch)

	    if self.defaultbranch.isVersion():
		sys.stderr.write("The configured default branch %s specifies " +
		     "version, not a branch.\n" % self.defaultbranch.asString())
	elif key == "installbranch":
	    self.installbranch = versions.BranchName(self.installbranch)

    def display(self):
	keys = self.__dict__.keys()
	keys.sort()
	for item in keys:
	    if type(self.__dict__[item]) is str:
		print "%-20s %s" % (item, self.__dict__[item])
	    elif isinstance(self.__dict__[item], versions.Version):
		print "%-20s %s" % (item, self.__dict__[item].asString())
	    elif isinstance(self.__dict__[item], versions.BranchName):
		print "%-20s %s" % (item, self.__dict__[item])
	    else:
		print "%-20s (unknown type)" % (item)

    def __init__(self):
	self.reppath = "/var/lib/srsrep"
	self.root = "/"
	self.sourcepath = "/usr/src/srs/sources"
	self.buildpath = "/usr/src/srs/builds"
	self.packagenamespace = ":localhost"
	self.defaultbranch = None
	self.installbranch = None
	self.lookaside = "/var/cache/srs"
	self.dbpath = "/var/lib/srsdb"
        self.tmpdir = "/var/tmp/"
	self.defaultbranch = versions.VersionFromString("/localhost@local")

	self.read("/etc/srsrc")
	self.read(os.environ["HOME"] + "/" + ".srsrc")
<commit_msg>implemented some exceptions for ParseError<commit_after>#
# Copyright (c) 2004 Specifix, Inc.
# All rights reserved
#
import os
import versions
import sys

class SrsConfiguration:

    def read(self, file):
	if os.path.exists(file):
	    f = open(file, "r")
	    for line in f:
		self.configLine(line)
	    f.close()

    def configLine(self, line):
	line = line.strip()
	if not line or line[0] == '#':
	    return
	(key, val) = line.split()
	if not self.__dict__.has_key(key):
	    raise ParseError, ("configuration value %s unknown" % key)

	self.__dict__[key] = val

	try:
	    if key == "defaultbranch":
		self.defaultbranch = \
			versions.VersionFromString(self.defaultbranch)

		if self.defaultbranch.isVersion():
		    sys.stderr.write("The configured default branch %s " +
			"specifies version, not a branch.\n" %
			   self.defaultbranch.asString())
	    elif key == "installbranch":
		self.installbranch = versions.BranchName(self.installbranch)
	except versions.ParseError, e:
	    raise ParseError, str(e)

    def display(self):
	keys = self.__dict__.keys()
	keys.sort()
	for item in keys:
	    if type(self.__dict__[item]) is str:
		print "%-20s %s" % (item, self.__dict__[item])
	    elif isinstance(self.__dict__[item], versions.Version):
		print "%-20s %s" % (item, self.__dict__[item].asString())
	    elif isinstance(self.__dict__[item], versions.BranchName):
		print "%-20s %s" % (item, self.__dict__[item])
	    else:
		print "%-20s (unknown type)" % (item)

    def __init__(self):
	self.reppath = "/var/lib/srsrep"
	self.root = "/"
	self.sourcepath = "/usr/src/srs/sources"
	self.buildpath = "/usr/src/srs/builds"
	self.packagenamespace = ":localhost"
	self.defaultbranch = None
	self.installbranch = None
	self.lookaside = "/var/cache/srs"
	self.dbpath = "/var/lib/srsdb"
        self.tmpdir = "/var/tmp/"
	self.defaultbranch = versions.VersionFromString("/localhost@local")

	self.read("/etc/srsrc")
	self.read(os.environ["HOME"] + "/" + ".srsrc")

class SrsCfgError(Exception):

    """
    Ancestor for all exceptions raised by the srscfg module.
    """

    pass

class ParseError(SrsCfgError):

    """
    Indicates that an error occured parsing the config file.
    """

    def __str__(self):
	return self.str

    def __init__(self, str):
	self.str = str
<|endoftext|>


<commit_before># This is a template config file for b2g emulator unittest production.

config = {
    # mozharness options
    "application": "b2g",
    "busybox_url": "http://runtime-binaries.pvt.build.mozilla.org/tooltool/sha512/0748e900821820f1a42e2f1f3fa4d9002ef257c351b9e6b78e7de0ddd0202eace351f440372fbb1ae0b7e69e8361b036f6bd3362df99e67fc585082a311fc0df",
    "xre_url": "http://runtime-binaries.pvt.build.mozilla.org/tooltool/sha512/cba263cef46b57585334f4b71fbbd15ce740fa4b7260571a9f7a76f8f0d6b492b93b01523cb01ee54697cc9b1de1ccc8e89ad64da95a0ea31e0f119fe744c09f",
    "tooltool_servers": ["http://runtime-binaries.pvt.build.mozilla.org/tooltool/"],

    "exes": {
        'python': '/tools/buildbot/bin/python',
        'virtualenv': ['/tools/buildbot/bin/python', '/tools/misc-python/virtualenv.py'],
        'tooltool.py': "/tools/tooltool.py",
    },

    "find_links": [
        "http://repos/python/packages",
        "http://releng-puppet2.srv.releng.use1.mozilla.com/python/packages/",
        "http://releng-puppet1.srv.releng.use1.mozilla.com/python/packages/",
        "http://releng-puppet2.build.mtv1.mozilla.com/python/packages/",
        "http://releng-puppet2.srv.releng.usw2.mozilla.com/python/packages/",
        "http://releng-puppet1.srv.releng.usw2.mozilla.com/python/packages/",
        "http://releng-puppet2.srv.releng.scl3.mozilla.com/python/packages/",
        "http://releng-puppet2.build.scl1.mozilla.com/python/packages/",
        "http://puppetagain.pub.build.mozilla.org/data/python/packages/",
    ],
    "pip_index": False,

    "buildbot_json_path": "buildprops.json",

    "default_actions": [
        'clobber',
        'read-buildbot-config',
        'download-and-extract',
        'create-virtualenv',
        'install',
        'run-tests',
    ],
    "download_symbols": "ondemand",
    "download_minidump_stackwalk": True,

    # test harness options
    "run_file_names": {
        "jsreftest": "runreftestb2g.py",
        "mochitest": "runtestsb2g.py",
        "reftest": "runreftestb2g.py",
        "crashtest": "runreftestb2g.py",
        "xpcshell": "runtestsb2g.py"
    },

    "jsreftest_options": [
        "--adbpath=%(adbpath)s", "--b2gpath=%(b2gpath)s", "--emulator=%(emulator)s",
        "--emulator-res=800x1000", "--logcat-dir=%(logcat_dir)s",
        "--remote-webserver=%(remote_webserver)s", "--ignore-window-size",
        "--xre-path=%(xre_path)s", "--symbols-path=%(symbols_path)s", "--busybox=%(busybox)s",
        "--total-chunks=%(total_chunks)s", "--this-chunk=%(this_chunk)s",
        "--extra-profile-file=jsreftest/tests/user.js",
        "%(test_manifest)s",
    ],

    "mochitest_options": [
        "--adbpath=%(adbpath)s", "--b2gpath=%(b2gpath)s", "--console-level=INFO",
        "--emulator=%(emulator)s", "--logcat-dir=%(logcat_dir)s",
        "--remote-webserver=%(remote_webserver)s", "--test-manifest=%(test_manifest)s",
        "--xre-path=%(xre_path)s", "--symbols-path=%(symbols_path)s", "--busybox=%(busybox)s",
        "--total-chunks=%(total_chunks)s", "--this-chunk=%(this_chunk)s",
    ],

    "reftest_options": [
        "--adbpath=%(adbpath)s", "--b2gpath=%(b2gpath)s", "--emulator=%(emulator)s",
        "--emulator-res=800x1000", "--logcat-dir=%(logcat_dir)s",
        "--remote-webserver=%(remote_webserver)s", "--ignore-window-size",
        "--xre-path=%(xre_path)s", "--symbols-path=%(symbols_path)s", "--busybox=%(busybox)s",
        "--total-chunks=%(total_chunks)s", "--this-chunk=%(this_chunk)s",
        "%(test_manifest)s",
    ],

    "crashtest_options": [
        "--adbpath=%(adbpath)s", "--b2gpath=%(b2gpath)s", "--emulator=%(emulator)s",
        "--emulator-res=800x1000", "--logcat-dir=%(logcat_dir)s",
        "--remote-webserver=%(remote_webserver)s", "--ignore-window-size",
        "--xre-path=%(xre_path)s", "--symbols-path=%(symbols_path)s", "--busybox=%(busybox)s",
        "--total-chunks=%(total_chunks)s", "--this-chunk=%(this_chunk)s",
        "%(test_manifest)s",
    ],

    "xpcshell_options": [
        "--adbpath=%(adbpath)s", "--b2gpath=%(b2gpath)s", "--emulator=%(emulator)s",
        "--logcat-dir=%(logcat_dir)s", "--manifest=%(test_manifest)s",
        "--testing-modules-dir=%(modules_dir)s", "--symbols-path=%(symbols_path)s",
        "--busybox=%(busybox)s", "--total-chunks=%(total_chunks)s", "--this-chunk=%(this_chunk)s",
    ],
}
<commit_msg>Bug 913281 - Mozharness should explicitly pass --use-device-libs to runtestsb2g.py, r=jgriffin<commit_after># This is a template config file for b2g emulator unittest production.

config = {
    # mozharness options
    "application": "b2g",
    "busybox_url": "http://runtime-binaries.pvt.build.mozilla.org/tooltool/sha512/0748e900821820f1a42e2f1f3fa4d9002ef257c351b9e6b78e7de0ddd0202eace351f440372fbb1ae0b7e69e8361b036f6bd3362df99e67fc585082a311fc0df",
    "xre_url": "http://runtime-binaries.pvt.build.mozilla.org/tooltool/sha512/cba263cef46b57585334f4b71fbbd15ce740fa4b7260571a9f7a76f8f0d6b492b93b01523cb01ee54697cc9b1de1ccc8e89ad64da95a0ea31e0f119fe744c09f",
    "tooltool_servers": ["http://runtime-binaries.pvt.build.mozilla.org/tooltool/"],

    "exes": {
        'python': '/tools/buildbot/bin/python',
        'virtualenv': ['/tools/buildbot/bin/python', '/tools/misc-python/virtualenv.py'],
        'tooltool.py': "/tools/tooltool.py",
    },

    "find_links": [
        "http://repos/python/packages",
        "http://releng-puppet2.srv.releng.use1.mozilla.com/python/packages/",
        "http://releng-puppet1.srv.releng.use1.mozilla.com/python/packages/",
        "http://releng-puppet2.build.mtv1.mozilla.com/python/packages/",
        "http://releng-puppet2.srv.releng.usw2.mozilla.com/python/packages/",
        "http://releng-puppet1.srv.releng.usw2.mozilla.com/python/packages/",
        "http://releng-puppet2.srv.releng.scl3.mozilla.com/python/packages/",
        "http://releng-puppet2.build.scl1.mozilla.com/python/packages/",
        "http://puppetagain.pub.build.mozilla.org/data/python/packages/",
    ],
    "pip_index": False,

    "buildbot_json_path": "buildprops.json",

    "default_actions": [
        'clobber',
        'read-buildbot-config',
        'download-and-extract',
        'create-virtualenv',
        'install',
        'run-tests',
    ],
    "download_symbols": "ondemand",
    "download_minidump_stackwalk": True,

    # test harness options
    "run_file_names": {
        "jsreftest": "runreftestb2g.py",
        "mochitest": "runtestsb2g.py",
        "reftest": "runreftestb2g.py",
        "crashtest": "runreftestb2g.py",
        "xpcshell": "runtestsb2g.py"
    },

    "jsreftest_options": [
        "--adbpath=%(adbpath)s", "--b2gpath=%(b2gpath)s", "--emulator=%(emulator)s",
        "--emulator-res=800x1000", "--logcat-dir=%(logcat_dir)s",
        "--remote-webserver=%(remote_webserver)s", "--ignore-window-size",
        "--xre-path=%(xre_path)s", "--symbols-path=%(symbols_path)s", "--busybox=%(busybox)s",
        "--total-chunks=%(total_chunks)s", "--this-chunk=%(this_chunk)s",
        "--extra-profile-file=jsreftest/tests/user.js",
        "%(test_manifest)s",
    ],

    "mochitest_options": [
        "--adbpath=%(adbpath)s", "--b2gpath=%(b2gpath)s", "--console-level=INFO",
        "--emulator=%(emulator)s", "--logcat-dir=%(logcat_dir)s",
        "--remote-webserver=%(remote_webserver)s", "--test-manifest=%(test_manifest)s",
        "--xre-path=%(xre_path)s", "--symbols-path=%(symbols_path)s", "--busybox=%(busybox)s",
        "--total-chunks=%(total_chunks)s", "--this-chunk=%(this_chunk)s",
    ],

    "reftest_options": [
        "--adbpath=%(adbpath)s", "--b2gpath=%(b2gpath)s", "--emulator=%(emulator)s",
        "--emulator-res=800x1000", "--logcat-dir=%(logcat_dir)s",
        "--remote-webserver=%(remote_webserver)s", "--ignore-window-size",
        "--xre-path=%(xre_path)s", "--symbols-path=%(symbols_path)s", "--busybox=%(busybox)s",
        "--total-chunks=%(total_chunks)s", "--this-chunk=%(this_chunk)s",
        "%(test_manifest)s",
    ],

    "crashtest_options": [
        "--adbpath=%(adbpath)s", "--b2gpath=%(b2gpath)s", "--emulator=%(emulator)s",
        "--emulator-res=800x1000", "--logcat-dir=%(logcat_dir)s",
        "--remote-webserver=%(remote_webserver)s", "--ignore-window-size",
        "--xre-path=%(xre_path)s", "--symbols-path=%(symbols_path)s", "--busybox=%(busybox)s",
        "--total-chunks=%(total_chunks)s", "--this-chunk=%(this_chunk)s",
        "%(test_manifest)s",
    ],

    "xpcshell_options": [
        "--adbpath=%(adbpath)s", "--b2gpath=%(b2gpath)s", "--emulator=%(emulator)s",
        "--logcat-dir=%(logcat_dir)s", "--manifest=%(test_manifest)s", "--use-device-libs",
        "--testing-modules-dir=%(modules_dir)s", "--symbols-path=%(symbols_path)s",
        "--busybox=%(busybox)s", "--total-chunks=%(total_chunks)s", "--this-chunk=%(this_chunk)s",
    ],
}
<|endoftext|>