1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from ...utils.collections import merge
17 from ...utils.formatting import safe_repr
18 from ..validation import Issue
19 from .presentation import Presentation
22 class Presenter(Presentation):
24 Base class for ARIA presenters.
26 Presenters provide a robust API over agnostic raw data.
30 ALLOWED_IMPORTED_DSL_VERSIONS = None
33 def can_present(cls, raw):
34 dsl = raw.get('tosca_definitions_version')
35 assert cls.DSL_VERSIONS
36 return dsl in cls.DSL_VERSIONS
38 def _validate_import(self, context, presentation):
39 tosca_definitions_version = presentation.service_template.tosca_definitions_version
40 assert self.ALLOWED_IMPORTED_DSL_VERSIONS
41 if tosca_definitions_version is not None \
42 and tosca_definitions_version not in self.__class__.ALLOWED_IMPORTED_DSL_VERSIONS:
43 context.validation.report(
44 'import "tosca_definitions_version" is not one of %s: %s'
45 % (' or '.join([safe_repr(v)
46 for v in self.__class__.ALLOWED_IMPORTED_DSL_VERSIONS]),
47 presentation.service_template.tosca_definitions_version),
48 locator=presentation._get_child_locator('inputs'),
49 level=Issue.BETWEEN_TYPES)
53 def _merge_import(self, presentation):
54 merge(self._raw, presentation._raw)
55 if hasattr(self._raw, '_locator') and hasattr(presentation._raw, '_locator'):
56 self._raw._locator.merge(presentation._raw._locator)
58 def _link_locators(self):
59 if hasattr(self._raw, '_locator'):
60 locator = self._raw._locator
61 delattr(self._raw, '_locator')
62 locator.link(self._raw)
65 def _get_import_locations(context):
66 raise NotImplementedError
69 def _get_deployment_template(context):
70 raise NotImplementedError