@classmethod
    def _shell_command_list_to_single_command(cls, commands):
        """
        Combines a list of commands into a single command string

        :param commands: a list of commands, optionally ending with semicolons
        :type commands: list[str|None]
        :return: returns the concatenated shell command on success, or None if there was an error
        :rtype: string|None
        """
        if not isinstance(commands, list):
            return None

        # We should join the commands with double ampersands UNLESS the command already ends with a single ampersand.
        # A semicolon (or a double ampersand) is invalid syntax after a single ampersand.
        sanitized_commands = []
        for command in commands:
            if command is None:
                # skip `None` command in the commands list
                continue
            stripped_command = command.strip().rstrip(';')
            # If the command ends with an ampersand (single or double) we can leave the command alone (empty postfix)
            postfix = ' ' if stripped_command.strip().endswith('&') else ' && '
            sanitized_commands.append(stripped_command + postfix)

        # '&&' must not be appended to the command for the last shell command. For the sake of homogeneity of the
        # loop above, we just strip out the '&&' here.
        joined_commands = ''.join(sanitized_commands).strip()

        if joined_commands.endswith('&&'):
            joined_commands = joined_commands.rstrip('&').strip()

        return joined_commands
dataset/ETHPy150Open box/ClusterRunner/app/master/job_config.py/JobConfig._shell_command_list_to_single_command/original