Robot Framework Integrated Development Environment (RIDE)
__init__.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 import sys
18 import inspect
19 import subprocess
20 
22 from robotide.lib.robot.utils.encoding import SYSTEM_ENCODING
23 from robotide.lib.robot.utils import printable_name, normalize, eq, ET, \
24  HtmlWriter, NormalizedDict, timestr_to_secs, secs_to_timestr, normpath,\
25  unic, asserts, unescape, html_escape, attribute_escape, robottime,\
26  get_timestamp, Matcher, is_list_like, is_dict_like, system_decode,\
27  ArgumentParser, get_error_details, is_unicode, is_string, py2to3
28 from .eventhandler import RideFSWatcherHandler
29 from .printing import Printing
30 
31 
32 def html_format(text):
33  return robotide.lib.robot.utils.html_format(text)
34 
35 
36 def name_from_class(item, drop=None):
37  cls = inspect.isclass(item) and item or item.__class__
38  name = cls.__name__
39  if drop and name.endswith(drop):
40  name = name[:-len(drop)]
41  return printable_name(name, code_style=True)
42 
43 
44 def split_value(value, sep='|'):
45  if not value:
46  return []
47  return [v.strip() for v in _split_value(value, sep)]
48 
49 
50 def _split_value(value, sep):
51  if '\\' not in value:
52  return value.split(sep)
53  ret = []
54  catenate_next = False
55  for item in value.split(sep):
56  bslash_count = len(item) - len(item.rstrip('\\'))
57  escaped = bslash_count % 2 == 1
58  if escaped:
59  item = item[:-1]
60  if catenate_next:
61  ret[-1] += sep + item
62  else:
63  ret.append(item)
64  catenate_next = escaped
65  return ret
66 
67 
68 def join_value(value, sep='|', joiner=None):
69  if not joiner:
70  joiner = ' %s ' % sep
71  return joiner.join([v.replace(sep, '\\' + sep) for v in value])
72 
73 
75  for dirpath in sys.path:
76  if not os.path.isdir(dirpath):
77  continue
78  path = os.path.join(dirpath, name)
79  if os.path.isfile(path):
80  return path
81  return None
82 
83 
84 def replace_extension(path, new_extension):
85  base = path.rsplit('.', 1)
86  return '%s.%s' % (base[0], new_extension.lower())
87 
88 
89 
94 def overrides(interface_class):
95  # type: (object) -> object
96  def overrider(method):
97  assert(method.__name__ in dir(interface_class))
98  return method
99  return overrider
100 
101 
102 def is_same_drive(path1, path2):
103  return os.path.splitdrive(path1)[0].lower() == \
104  os.path.splitdrive(path2)[0].lower()
105 
106 
107 def run_python_command(command, mode='c'):
108  cmd = [sys.executable, '-{0}'.format(mode)] + command
109  # TODO Let the user select which robot to use
110  process = subprocess.Popen(
111  cmd,
112  stdout=subprocess.PIPE,
113  stderr=subprocess.PIPE)
114  output, _ = process.communicate()
115  return output
116 
117 
118 
121 def converttypes(data, prefer_str=True):
122  enc = sys.stdout and sys.stdout.encoding or "utf-8"
123  data_type = type(data)
124 
125  if data_type == bytes:
126  if prefer_str:
127  return str(data.decode(enc))
128  return data.decode(enc)
129  if data_type in (str, int):
130  return str(data)
131 
132  if data_type == dict:
133  data = data.items()
134  return data_type(map(converttypes, data))
def printable_name(string, code_style=False)
Generates and returns printable name from the given string.
Definition: misc.py:76
def replace_extension(path, new_extension)
Definition: __init__.py:84
def is_same_drive(path1, path2)
Definition: __init__.py:102
def overrides(interface_class)
A decorator that can be used to validate method override.
Definition: __init__.py:94
def converttypes(data, prefer_str=True)
Convert all types from Python2 to Python3.
Definition: __init__.py:121
def _split_value(value, sep)
Definition: __init__.py:50
def html_format(text)
Definition: __init__.py:32
def run_python_command(command, mode='c')
Definition: __init__.py:107
def name_from_class(item, drop=None)
Definition: __init__.py:36
def join_value(value, sep='|', joiner=None)
Definition: __init__.py:68
def find_from_pythonpath(name)
Definition: __init__.py:74
def split_value(value, sep='|')
Definition: __init__.py:44