def join(cls, command): """ Note: Default to unix sh/bash- friendly behaviour. Args: command: A sequence of program arguments to be joined into a single string that can be executed in the current shell. Returns: A string object representing the command. """ replacements = [ # escape ` as \` ('`', "\\`"), # use double quotes, and put double quotes into single quotes - # the string $"b is then quoted as "$"'"'"b". This mimics py3.8+ # shlex.join function, except with double instead of single quotes. # # We do this because a command like rez-env -- echo 'hey $FOO' needs # to be interpreted as echo "hey $FOO" in the runtime - ie we would # expect $FOO to get expanded. # ('"', '"\'"\'"') ] return shlex_join(command, replacements=replacements)
def join(cls, command): """ Args: command: A sequence of program arguments to be joined into a single string that can be executed in the current shell. Returns: A string object representing the command. """ return shlex_join(command)
def join(cls, command): replacements = [ # escape ! as \! ('!', "\\!"), # see Shell.join() ('"', '"\'"\'"'), # similar to above, but for backticks ('`', '"\'`\'"'), # escape $ if not part of a valid var ref like $FOO, ${FOO} (re.compile(r"\$([^a-zA-Z{])"), '"\'$\'"\\1'), (re.compile(r"\$$"), '"\'$\'"') # edge case, $ at end ] return shlex_join(command, replacements=replacements)
def command(self, value): if self.passive: return if hasattr(value, '__iter__'): it = iter(value) cmd = EscapedString.disallow(it.next()) value = [cmd] + [self.escape_string(x) for x in it] else: value = EscapedString.disallow(value) value = self.escape_string(value) try: p = self.subprocess(value) p.communicate() except Exception as e: cmd = shlex_join(value) raise RexError('Error executing command: %s\n%s' % (cmd, str(e)))
def command(self, value): if self.passive: return if is_non_string_iterable(value): it = iter(value) cmd = EscapedString.disallow(next(it)) value = [cmd] + [self.escape_string(x) for x in it] else: value = EscapedString.disallow(value) value = self.escape_string(value) try: p = self.subprocess(value) p.communicate() except Exception as e: cmd = shlex_join(value) raise RexError('Error executing command: %s\n%s' % (cmd, str(e)))
def join(cls, command): if isinstance(command, six.string_types): return command replacements = [ # escape ` as `` ('`', "``"), # escape " as `" ('"', '`"') ] joined = shlex_join(command, replacements=replacements) # add call operator in case executable gets quotes applied # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.1#call-operator- # return "& " + joined
def join(self, command): return shlex_join(command)
def join(cls, command): return shlex_join(command)
def join(self, command): return shlex_join(command).replace("'", '"')