Skip to content

Commit

Permalink
Fix #1891 (#1991)
Browse files Browse the repository at this point in the history
* Ignore validation of shell commands as arguments to options. Makes possible to use -d date +%F_%X in runner arguments.

* Parses arguments in Windows. Fixes #1891
  • Loading branch information
HelioGuilherme66 authored Sep 3, 2019
1 parent 23c24f7 commit cd09b3b
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/robotide/contrib/testrunner/runprofiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from robotide.robotapi import DataError, Information
from robotide.utils import (overrides, SYSTEM_ENCODING, ArgumentParser,
is_unicode, PY3)
from robotide.context import IS_WINDOWS
from robotide.contrib.testrunner.usages import USAGE
from sys import getfilesystemencoding

Expand Down Expand Up @@ -150,8 +151,20 @@ def get_command_prefix(self):
return [self.get_command()] + self._get_arguments()

def _get_arguments(self):
if IS_WINDOWS:
self._parse_windows_command()
return self.arguments.split()

def _parse_windows_command(self):
from subprocess import Popen, PIPE
try:
p = Popen(['echo', self.arguments], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
output, _ = p.communicate()
output = str(output).lstrip("b\'").strip()
self.arguments = output.replace('"', '').replace('\'', '').replace('\\r\\n', '')
except IOError:
pass

def get_command(self): # TODO Test on Windows
from subprocess import call
from tempfile import TemporaryFile
Expand Down Expand Up @@ -301,8 +314,7 @@ def OnArgumentsChanged(self, evt):

def _validate_arguments(self, args):
# assert type(args) is unicode
# print("DEBUG: runprofiles: type(args)=%s
# is_unicode(args)=%s" % (type(args), is_unicode(args)))
# print("DEBUG: runprofiles: args=%s is_unicode(args)=%s" % (args, is_unicode(args)))
invalid_message = self._get_invalid_message(args)
self._arguments.SetBackgroundColour(
'red' if invalid_message else 'white')
Expand All @@ -322,8 +334,17 @@ def MySetToolTip(self, obj, tip):

def _get_invalid_message(self, args):
invalid = None
if not args:
return None
try:
# print("DEBUG: runprofiles get inv msg: %s\n" % args)
clean_args = args.split("`") # Shell commands
for idx, item in enumerate(clean_args):
clean_args[idx] = item.strip()
if clean_args[idx][0] != '-': # Not option, then is argument
clean_args[idx] = 'arg'
args = " ".join(clean_args)
# print("DEBUG: runprofiles join args: %s\n" % args)
# raw: %s\n" % (bytes(args), args) )
#if PY3:
# args = args.encode(SYSTEM_ENCODING) # DEBUG SYSTEM_ENCODING
Expand Down

0 comments on commit cd09b3b

Please sign in to comment.