buildframework/helium/sf/python/pythoncore/lib/configuration_model.py
author lorewang
Wed, 01 Dec 2010 16:05:36 +0800
changeset 715 e0739b8406dd
parent 587 85df38eb4012
permissions -rw-r--r--
Specify extenal tool with path
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
#Name        : configuration_model.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
""" the model definition of property, group of property and configuration of property"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import amara
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import copy
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
_logger = logging.getLogger('configurationmodel')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
#logging.basicConfig(level=logging.DEBUG)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
_handler = logging.StreamHandler()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
_logger.addHandler(_handler)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
class PropertyDef(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
    """ The model definition of a property. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
    def __init__(self, property_node):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
        """ Initialization. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
        if not hasattr(property_node, 'name'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
            raise Exception("Name is not defined for '" + str(property_node) + "'")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
        if not hasattr(property_node, 'type'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
            raise Exception("Type is not defined for '" + str(property_node.name) + "'")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
        if not hasattr(property_node, 'description'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
            raise Exception("Description is not defined for '" + str(property_node.name) + "'")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
        self.name = str(property_node.name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
        self.editStatus = str(property_node.editStatus)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        self.type = str(property_node.type)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
        self.description = str(property_node.description).strip()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        if len(self.description) == 0:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
            _logger.log(logging.ERROR, "Description has no content for '" + str(property_node.name) + "'")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        if hasattr(property_node, 'deprecated'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
            self.deprecated = str(property_node.deprecated)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
                        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
    def __repr__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
        return self.name
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
    def __str__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        return self.name
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
class GroupDef(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
    """ The model definition of a group of properties. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
    def __init__(self, group_node):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
        """ Initialization. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        self.name = str(group_node.name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        self.description = str(group_node.description)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
        self.properties = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        self.propref = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        for property_ in group_node.propertyRef:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
            self.properties[str(property_)] = property_.usage
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
    def check_config(self, config, items):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        """ Checks that the set of properties in a group are properly defined. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        defined_props = [p for p in self.properties.keys() if config.has_key(p)]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        if len(defined_props) > 0:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
            required_props = [p for p in self.properties.keys() if self.properties[p] == 'required']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
            required_not_defined_props = set(required_props).difference(set(defined_props))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
            for undefined_property in required_not_defined_props:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
                items.append(UndefinedRequiredInGroupItem((self.name, undefined_property)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
class DataModel(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
    """ A model of the configuration properties. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
    def __init__(self, modelpath):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
        """ Initialization. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        doc = amara.parse(open(modelpath, 'r'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        self.properties = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        self.required_props = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
        for property_ in doc.heliumDataModel.property:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
            self.properties[str(property_.name)] = PropertyDef(property_)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
                   
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
        self.nongroupedproperties = copy.copy(self.properties)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
        self.groups = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
        for group in doc.heliumDataModel.group:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
            groupobj = GroupDef(group)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
            self.groups[str(group.name)] = groupobj
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
            for prop in groupobj.properties:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
                groupobj.propref.append(self.properties[prop])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
                if prop in self.nongroupedproperties:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
                    del self.nongroupedproperties[prop]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
                    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
            groupobj.propref.sort()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
            required_props_in_group = [p for p in group.propertyRef if p.usage == 'required']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
            for required_prop in required_props_in_group:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
                self.required_props.append(required_prop)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
                if not self.properties.has_key(str(required_prop)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
                    raise Exception("Required property " + str(required_prop) + " is not defined!")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
    def validate_config(self, config):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
        """ Validate the Ant configuration against the model. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
        items = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
        self._check_deprecated_properties(config, items)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        self._check_undefined_properties(config, items)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
        self._check_undefined_properties_in_groups(config, items)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
        self._check_type_validation(config, items)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
        self._check_defined_properties_not_in_groups()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
        return items
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
    def validate_config_at_startup(self, config):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
        """ Validate the Ant configuration against the model at build startup. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
        items = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
        for p_props in self.required_props:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
            if not config.has_key(str(p_props)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
                print "Required property " + str(p_props) + " is not defined!"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
        return items
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
    def _check_deprecated_properties(self, config, items):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
        """ Check that deprecated properties not being used. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
        deprecated_props = [p for p in self.properties.values() if hasattr(p, 'deprecated')]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
        for deprecated_prop in deprecated_props:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
            _logger.debug('Checking deprecated property: ' + str(deprecated_prop))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
            if config.has_key(str(deprecated_prop)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
                items.append(UsingDeprecatedItem(deprecated_prop))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
    def _check_undefined_properties(self, config, items):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
        """ Check for any defined properties that are not in the model. """ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
        undefined_properties = [p_key for p_key in config.keys() if p_key not in self.properties]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
        undefined_properties.sort()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
        for undefined_property in undefined_properties:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
            items.append(MissingFromDataModelItem(undefined_property))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
    def _check_undefined_properties_in_groups(self, config, items):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
        """ Check for any undefined properties that are in the group. """ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
        for group in self.groups.values():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
            _logger.debug('Checking group: %s' % group.name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
            group.check_config(config, items)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
    def _check_defined_properties_not_in_groups(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
        """ Check for any defined properties that are not in the group. """ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
        g_props = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
        for group in self.groups.values():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
            g_props = g_props + group.properties.keys()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
        for p_props in self.properties.values():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
            if not str(p_props) in g_props:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
                raise Exception(str(p_props) + ' not in a group')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
    def _check_type_validation(self, config, items):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
        """ Check the type validation. """ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
        prop_string = [p_props for p_props in self.properties.values() if p_props.type == 'string']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
        prop_integer = [p_props for p_props in self.properties.values() if p_props.type == 'integer']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
        prop_boolean = [p_props for p_props in self.properties.values() if p_props.type == 'boolean']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
        #prop_flag = [p_props for p_props in self.properties.values() if p_props.type == 'flag']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
        for prop in prop_integer:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
            if config.has_key(str(prop)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
                if not config[str(prop)].isdigit():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
                    items.append(WrongTypeItem(("integer", prop)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
        for prop in prop_boolean:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
            if config.has_key(str(prop)) :
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
                if not (config[str(prop)] == 'false' or 'true'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
                    items.append(WrongTypeItem(("boolean", prop)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
                    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
        for prop in prop_string:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
            if config.has_key(str(prop)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
                if len(config[str(prop)]) == 0:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
                    items.append(WrongTypeItem(("string", prop)))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
class Item(object):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
    """ Base class item """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
    level = logging.INFO
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
    message = ''
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
    def __init__(self, values):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
        """ Initialization. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
        self.values = values
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
    def log(self, logger):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
        """log an error"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
        logger.log(self.level, str(self))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
    def __str__(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
        """string conversion"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
        return self.message % self.values
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
class MissingFromDataModelItem(Item):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
    """ info message """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
    level = logging.INFO
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
    message = 'Property not in data model: %s'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
class UsingDeprecatedItem(Item):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
    """ warning msg """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
    level = logging.WARNING
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
    message = 'Deprecated property used: %s'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
class UndefinedRequiredInGroupItem(Item):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
    """ warning msg """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
    level = logging.WARNING
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
    message = 'Required property in %s group is not defined: %s'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
class WrongTypeItem(Item):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
    """ warning msg """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
    level = logging.WARNING
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
    message = 'Invalid %s value: %s'