3
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
from cone.public import api
|
|
18 |
from cone.confml import model
|
|
19 |
from cone.validation.confmlvalidation import ValidatorBase
|
|
20 |
|
|
21 |
class ExampleValidator(ValidatorBase):
|
|
22 |
PROBLEM_TYPES = ['model.confml.foo_missing']
|
|
23 |
|
|
24 |
def validate(self):
|
|
25 |
for ref, feature in self.context.feature_dict.iteritems():
|
|
26 |
if isinstance(feature._obj, model.ConfmlStringSetting) and feature.ref.startswith('FOO_'):
|
|
27 |
value = feature.get_value()
|
|
28 |
if isinstance(value, basestring) and 'foo' not in value:
|
|
29 |
dataobj = feature.datas['data'][-1]
|
|
30 |
|
|
31 |
prob = api.Problem(
|
|
32 |
msg = "String 'foo' missing from value of feature '%s'" % ref,
|
|
33 |
type = self.PROBLEM_TYPES[0],
|
|
34 |
line = dataobj.lineno,
|
|
35 |
file = dataobj.get_configuration_path(),
|
|
36 |
severity = api.Problem.SEVERITY_WARNING)
|
|
37 |
self.context.problems.append(prob)
|
|
38 |
|
|
39 |
VALIDATOR_CLASSES = [ExampleValidator]
|