Esempio n. 1
0
File: shells.py Progetto: maxnbk/rez
    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)
Esempio n. 2
0
 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)
Esempio n. 3
0
File: csh.py Progetto: sdot-b/rez
    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)
Esempio n. 4
0
    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)))
Esempio n. 5
0
    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)))
Esempio n. 6
0
    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
Esempio n. 7
0
File: shells.py Progetto: rvsiy/rez
 def join(self, command):
     return shlex_join(command)
Esempio n. 8
0
 def join(self, command):
     return shlex_join(command)
Esempio n. 9
0
 def join(cls, command):
     return shlex_join(command)
Esempio n. 10
0
 def join(self, command):
     return shlex_join(command).replace("'", '"')
Esempio n. 11
0
 def join(self, command):
     return shlex_join(command).replace("'", '"')