Robot Framework Integrated Development Environment (RIDE)
Command.py
Go to the documentation of this file.
1 # Copyright 2010 Orbitz WorldWide
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 # Modified by NSN
16 # Copyright 2010-2012 Nokia Solutions and Networks
17 # Copyright 2013-2015 Nokia Networks
18 # Copyright 2016- Robot Framework Foundation
19 #
20 # Licensed under the Apache License, Version 2.0 (the "License");
21 # you may not use this file except in compliance with the License.
22 # You may obtain a copy of the License at
23 #
24 # http://www.apache.org/licenses/LICENSE-2.0
25 #
26 # Unless required by applicable law or agreed to in writing, software
27 # distributed under the License is distributed on an "AS IS" BASIS,
28 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 # See the License for the specific language governing permissions and
30 # limitations under the License.
31 
32 import inspect
33 import os
34 
35 from robotide.contrib.testrunner import TestRunnerAgent
36 try:
37  from robotide.lib.robot.utils import encoding
38 except ImportError:
39  from robotide.lib.robot.utils.encodingsniffer import get_system_encoding
40  encoding.SYSTEM_ENCODING = get_system_encoding()
41 
42 
43 class Command:
44  def __init__(self):
45  self._prefix_prefix = ''
46  self._tests_suite_file_tests_suite_file = ''
47  self._listener_listener = None
48  self._args_file_args_file = ''
49 
50  def with_prefix(self, prefix):
51  self._prefix_prefix = prefix
52  return self
53 
54  def with_listener(self, port, pause_on_failure=False):
55  if port:
56  self._listener_listener = (port, pause_on_failure)
57  else:
58  self._listener_listener = None
59  return self
60 
61  def with_tests_suite_file(self, tests_suit_file):
62  self._tests_suite_file_tests_suite_file = tests_suit_file
63  return self
64 
65  def with_args_file(self, args_file):
66  self._args_file_args_file = args_file
67  return self
68 
69  def build(self):
70  command = []
71  if self._prefix_prefix:
72  command.append(self._prefix_prefix)
73 
74  if self._args_file_args_file:
75  command.extend(["-A", self._args_file_args_file])
76 
77  if self._listener_listener:
78  command.extend(["--listener", self._get_listener_to_cmd_get_listener_to_cmd()])
79 
80  if self._tests_suite_file_tests_suite_file:
81  command.append(self._tests_suite_file_tests_suite_file)
82 
83  return self._format_command_format_command(command)
84 
86  path = self._get_listener_path_get_listener_path()
87  if path[-1] in ['c', 'o']:
88  path = path[:-1]
89  return '%s:%s:%s' % (path, self._listener_listener[0], self._listener_listener[1])
90 
91  def _get_listener_path(self):
92  return os.path.abspath(inspect.getfile(TestRunnerAgent))
93 
94  @staticmethod
95 
104  def _format_command(args):
105  result = []
106  for arg in args:
107  # arg = arg.encode(encoding.SYSTEM_ENCODING)
108  if "'" in arg or " " in arg or "&" in arg:
109  # for windows, if there are spaces we need to use
110  # double quotes. Single quotes cause problems
111  result.append('"%s"' % arg)
112  elif '"' in arg:
113  result.append("'%s'" % arg)
114  else:
115  result.append(arg)
116  return " ".join(result)
def with_listener(self, port, pause_on_failure=False)
Definition: Command.py:54
def _format_command(args)
Quote a list as if it were a command line command.
Definition: Command.py:104
def with_tests_suite_file(self, tests_suit_file)
Definition: Command.py:61