Robot Framework Integrated Development Environment (RIDE)
imports.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
17 
18 from robotide.lib.robot.utils import seq2str
19 
20 from .itemlist import ItemList
21 
22 
23 class Import():
24  ALLOWED_TYPES = ('Library', 'Resource', 'Variables')
25 
26  def __init__(self, type, name, args=(), alias=None, source=None):
27  if type not in self.ALLOWED_TYPESALLOWED_TYPES:
28  raise ValueError("Invalid import type '%s'. Should be one of %s."
29  % (type, seq2str(self.ALLOWED_TYPESALLOWED_TYPES, lastsep=' or ')))
30  self.typetype = type
31  self.namename = name
32  self.argsargs = args
33  self.aliasalias = alias
34  self.sourcesource = source
35 
36  @property
37  directory = property
38 
39  def directory(self):
40  if not self.sourcesource:
41  return None
42  if os.path.isdir(self.sourcesource):
43  return self.sourcesource
44  return os.path.dirname(self.sourcesource)
45 
46  def report_invalid_syntax(self, message, level='ERROR'):
47  from robotide.lib.robot.output import LOGGER
48  LOGGER.write("Error in file '%s': %s"
49  % (self.sourcesource or '<unknown>', message), level)
50 
51 
53 
54  def __init__(self, source, imports=None):
55  ItemList.__init__(self, Import, {'source': source}, items=imports)
56 
57  def library(self, name, args=(), alias=None):
58  self.createcreate('Library', name, args, alias)
59 
60  def resource(self, path):
61  self.createcreate('Resource', path)
62 
63  def variables(self, path, args=()):
64  self.createcreate('Variables', path, args)
def __init__(self, type, name, args=(), alias=None, source=None)
Definition: imports.py:26
def report_invalid_syntax(self, message, level='ERROR')
Definition: imports.py:46
def library(self, name, args=(), alias=None)
Definition: imports.py:57
def __init__(self, source, imports=None)
Definition: imports.py:54
def variables(self, path, args=())
Definition: imports.py:63
def create(self, *args, **kwargs)
Definition: itemlist.py:30
def seq2str(sequence, quote="'", sep=', ', lastsep=' and ')
Returns sequence in format ‘'item 1’, 'item 2' and 'item 3'`.
Definition: misc.py:115