Beispiel #1
0
def _copy2_ignoring_special_files(src, dest):

    # type: (str, str) -> None
    """Copying special files is not supported, but as a convenience to users

    we skip errors copying them. This supports tools that may create e.g.

    socket files in the project source directory.

    """

    try:

        copy2_fixed(src, dest)

    except shutil.SpecialFileError as e:

        # SpecialFileError may be raised due to either the source or

        # destination. If the destination was the cause then we would actually

        # care, but since the destination directory is deleted prior to

        # copy we ignore all of them assuming it is caused by the source.

        logger.warning(
            "Ignoring special file error '%s' encountered copying %s to %s.",
            str(e),
            path_to_display(src),
            path_to_display(dest),
        )
Beispiel #2
0
def make_subprocess_output_error(
        cmd_args,  # type: Union[List[str], CommandArgs]
        cwd,  # type: Optional[str]
        lines,  # type: List[str]
        exit_status,  # type: int
):

    # type: (...) -> str
    """

    Create and return the error message to use to log a subprocess error

    with command output.



    :param lines: A list of lines, each ending with a newline.

    """

    command = format_command_args(cmd_args)

    # Convert `command` and `cwd` to text (unicode in Python 2) so we can use

    # them as arguments in the unicode format string below. This avoids

    # "UnicodeDecodeError: 'ascii' codec can't decode byte ..." in Python 2

    # if either contains a non-ascii character.

    command_display = str_to_display(command, desc='command bytes')

    cwd_display = path_to_display(cwd)

    # We know the joined output value ends in a newline.

    output = ''.join(lines)

    msg = (

        # Use a unicode string to avoid "UnicodeEncodeError: 'ascii'

        # codec can't encode character ..." in Python 2 when a format

        # argument (e.g. `output`) has a non-ascii character.
        'Command errored out with exit status {exit_status}:\n'
        ' command: {command_display}\n'
        '     cwd: {cwd_display}\n'
        'Complete output ({line_count} lines):\n{output}{divider}').format(
            exit_status=exit_status,
            command_display=command_display,
            cwd_display=cwd_display,
            line_count=len(lines),
            output=output,
            divider=LOG_DIVIDER,
        )

    return msg
Beispiel #3
0
def test_path_to_display(monkeypatch, path, fs_encoding, expected):
    monkeypatch.setattr(sys, 'getfilesystemencoding', lambda: fs_encoding)
    actual = path_to_display(path)
    assert actual == expected, 'actual: {!r}'.format(actual)