Robot Framework Integrated Development Environment (RIDE)
specbuilder.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15 
16 import os.path
17 
18 from robotide.lib.robot.errors import DataError
19 from robotide.lib.robot.utils import ET, ETSource
20 
21 from .model import LibraryDoc, KeywordDoc
22 
23 
25 
26  def build(self, path):
27  spec = self._parse_spec_parse_spec(path)
28  libdoc = LibraryDoc(name=spec.get('name'),
29  type=spec.get('type'),
30  version=spec.find('version').text or '',
31  doc=spec.find('doc').text or '',
32  scope=spec.find('scope').text or '',
33  named_args=self._get_named_args_get_named_args(spec),
34  doc_format=spec.get('format', 'ROBOT'))
35  libdoc.inits = self._create_keywords_create_keywords(spec, 'init')
36  libdoc.keywords = self._create_keywords_create_keywords(spec, 'kw')
37  return libdoc
38 
39  def _parse_spec(self, path):
40  if not os.path.isfile(path):
41  raise DataError("Spec file '%s' does not exist." % path)
42  with ETSource(path) as source:
43  root = ET.parse(source).getroot()
44  if root.tag != 'keywordspec':
45  raise DataError("Invalid spec file '%s'." % path)
46  return root
47 
48  def _get_named_args(self, spec):
49  elem = spec.find('namedargs')
50  if elem is None:
51  return False # Backwards compatiblity with RF < 2.6.2
52  return elem.text == 'yes'
53 
54  def _create_keywords(self, spec, path):
55  return [self._create_keyword_create_keyword(elem) for elem in spec.findall(path)]
56 
57  def _create_keyword(self, elem):
58  return KeywordDoc(name=elem.get('name', ''),
59  args=[a.text for a in elem.findall('arguments/arg')],
60  doc=elem.find('doc').text or '',
61  tags=[t.text for t in elem.findall('tags/tag')])
Used when variable does not exist.
Definition: errors.py:67