Merge "Provide file list about the difference between parser and upstreams."
[parser.git] / tosca2heat / tosca-parser / toscaparser / elements / artifacttype.py
1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
2 #    not use this file except in compliance with the License. You may obtain
3 #    a copy of the License at
4 #
5 #         http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #    Unless required by applicable law or agreed to in writing, software
8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 #    License for the specific language governing permissions and limitations
11 #    under the License.
12
13 from toscaparser.elements.statefulentitytype import StatefulEntityType
14
15
16 class ArtifactTypeDef(StatefulEntityType):
17     '''TOSCA built-in artifacts type.'''
18
19     def __init__(self, atype, custom_def=None):
20         super(ArtifactTypeDef, self).__init__(atype, self.ARTIFACT_PREFIX,
21                                               custom_def)
22         self.type = atype
23         self.custom_def = custom_def
24         self.properties = None
25         if self.PROPERTIES in self.defs:
26             self.properties = self.defs[self.PROPERTIES]
27         self.parent_artifacts = self._get_parent_artifacts()
28
29     def _get_parent_artifacts(self):
30         artifacts = {}
31         parent_artif = self.parent_type.type if self.parent_type else None
32         if parent_artif:
33             while parent_artif != 'tosca.artifacts.Root':
34                 artifacts[parent_artif] = self.TOSCA_DEF[parent_artif]
35                 parent_artif = artifacts[parent_artif]['derived_from']
36         return artifacts
37
38     @property
39     def parent_type(self):
40         '''Return a artifact entity from which this entity is derived.'''
41         if not hasattr(self, 'defs'):
42             return None
43         partifact_entity = self.derived_from(self.defs)
44         if partifact_entity:
45             return ArtifactTypeDef(partifact_entity, self.custom_def)
46
47     def get_artifact(self, name):
48         '''Return the definition of an artifact field by name.'''
49         if name in self.defs:
50             return self.defs[name]