# Copyright 2014-2016 ARM Limited # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import re from copy import copy from collections import OrderedDict, defaultdict from devlib import TargetError from wlauto.exceptions import ConfigError from wlauto.utils.misc import (get_article, merge_config_values) from wlauto.utils.types import (identifier, integer, boolean, list_of_strings, toggle_set, obj_dict) from wlauto.core.configuration.tree import SectionNode # Mapping for kind conversion; see docs for convert_types below KIND_MAP = { int: integer, bool: boolean, dict: OrderedDict, } ########################## ### CONFIG POINT TYPES ### ########################## class RebootPolicy(object): """ Represents the reboot policy for the execution -- at what points the device should be rebooted. This, in turn, is controlled by the policy value that is passed in on construction and would typically be read from the user's settings. Valid policy values are: :never: The device will never be rebooted. :as_needed: Only reboot the device if it becomes unresponsive, or needs to be flashed, etc. :initial: The device will be rebooted when the execution first starts, just before executing the first workload spec. :each_spec: The device will be rebooted before running a new workload spec. :each_iteration: The device will be rebooted before each new iteration. """ valid_policies = ['never', 'as_needed', 'initial', 'each_spec', 'each_iteration'] def __init__(self, policy): policy = policy.strip().lower().replace(' ', '_') if policy not in self.valid_policies: message = 'Invalid reboot policy {}; must be one of {}'.format(policy, ', '.join(self.valid_policies)) raise ConfigError(message) self.policy = policy @property def can_reboot(self): return self.policy != 'never' @property def perform_initial_boot(self): return self.policy not in ['never', 'as_needed'] @property def reboot_on_each_spec(self): return self.policy in ['each_spec', 'each_iteration'] @property def reboot_on_each_iteration(self): return self.policy == 'each_iteration' def __str__(self): return self.policy __repr__ = __str__ def __cmp__(self, other): if isinstance(other, RebootPolicy): return cmp(self.policy, other.policy) else: return cmp(self.policy, other) def to_pod(self): return self.policy @staticmethod def from_pod(pod): return RebootPolicy(pod) class status_list(list): def append(self, item): list.append(self, str(item).upper()) class LoggingConfig(dict): defaults = { 'file_format': '%(asctime)s %(levelname)-8s %(name)s: %(message)s', 'verbose_format': '%(asctime)s %(levelname)-8s %(name)s: %(message)s', 'regular_format': '%(levelname)-8s %(message)s', 'color': True, } def __init__(self, config=None): dict.__init__(self) if isinstance(config, dict): config = {identifier(k.lower()): v for k, v in config.iteritems()} self['regular_format'] = config.pop('regular_format', self.defaults['regular_format']) self['verbose_format'] = config.pop('verbose_format', self.defaults['verbose_format']) self['file_format'] = config.pop('file_format', self.defaults['file_format']) self['color'] = config.pop('colour_enabled', self.defaults['color']) # legacy self['color'] = config.pop('color', self.defaults['color']) if config: message = 'Unexpected logging configuation parameters: {}' raise ValueError(message.format(bad_vals=', '.join(config.keys()))) elif config is None: for k, v in self.defaults.iteritems(): self[k] = v else: raise ValueError(config) def get_type_name(kind): typename = str(kind) if '\'' in typename: typename = typename.split('\'')[1] elif typename.startswith('