Example #1
0
def have_prefix_files(files):
    '''
    Yields files that contain the current prefix in them, and modifies them
    to replace the prefix with a placeholder.

    :param files: Filenames to check for instances of prefix
    :type files: list of tuples containing strings (prefix, mode, filename)
    '''
    prefix = config.build_prefix
    prefix_bytes = prefix.encode('utf-8')
    alt_prefix = prefix.replace('\\', '/')
    alt_prefix_bytes = alt_prefix.encode('utf-8')
    prefix_placeholder_bytes = prefix_placeholder.encode('utf-8')
    for f in files:
        if f.endswith(('.pyc', '.pyo', '.a', '.dylib')):
            continue
        path = join(prefix, f)
        if isdir(path):
            continue
        if sys.platform != 'darwin' and islink(path):
            # OSX does not allow hard-linking symbolic links, so we cannot
            # skip symbolic links (as we can on Linux)
            continue
        if sys.platform != 'win32' and is_obj(path):
            continue
        with open(path, 'rb') as fi:
            data = fi.read()
        mode = 'binary' if b'\x00' in data else 'text'
        if prefix_bytes in data:
            yield (prefix, mode, f)
        if (sys.platform == 'win32') and (alt_prefix_bytes in data):
            # some windows libraries use unix-style path separators
            yield (alt_prefix, mode, f)
        if prefix_placeholder_bytes in data:
            yield (prefix_placeholder, mode, f)
Example #2
0
def have_prefix_files(files):
    '''
    Yields files that contain the current prefix in them, and modifies them
    to replace the prefix with a placeholder.

    :param files: Filenames to check for instances of prefix
    :type files: list of tuples containing strings (prefix, mode, filename)
    '''
    prefix = config.build_prefix
    prefix_bytes = prefix.encode('utf-8')
    prefix_placeholder_bytes = prefix_placeholder.encode('utf-8')
    if on_win:
        forward_slash_prefix = prefix.replace('\\', '/')
        forward_slash_prefix_bytes = forward_slash_prefix.encode('utf-8')
        double_backslash_prefix = prefix.replace('\\', '\\\\')
        double_backslash_prefix_bytes = double_backslash_prefix.encode('utf-8')

    for f in files:
        if f.endswith(('.pyc', '.pyo', '.a')):
            continue
        path = join(prefix, f)
        if isdir(path):
            continue
        if sys.platform != 'darwin' and islink(path):
            # OSX does not allow hard-linking symbolic links, so we cannot
            # skip symbolic links (as we can on Linux)
            continue

        # dont try to mmap an empty file
        if os.stat(path).st_size == 0:
            continue

        fi = open(path, 'rb+')
        mm = mmap.mmap(fi.fileno(), 0)

        mode = 'binary' if mm.find(b'\x00') != -1 else 'text'
        if mode == 'text':
            if not on_win and mm.find(prefix_bytes) != -1:
                # Use the placeholder for maximal backwards compatibility, and
                # to minimize the occurrences of usernames appearing in built
                # packages.
                rewrite_file_with_new_prefix(path, mm[:], prefix_bytes,
                                             prefix_placeholder_bytes)
                mm.close() and fi.close()
                fi = open(path, 'rb+')
                mm = mmap.mmap(fi.fileno(), 0)
        if mm.find(prefix_bytes) != -1:
            yield (prefix, mode, f)
        if on_win and mm.find(forward_slash_prefix_bytes) != -1:
            # some windows libraries use unix-style path separators
            yield (forward_slash_prefix, mode, f)
        elif on_win and mm.find(double_backslash_prefix_bytes) != -1:
            # some windows libraries have double backslashes as escaping
            yield (double_backslash_prefix, mode, f)
        if mm.find(prefix_placeholder_bytes) != -1:
            yield (prefix_placeholder, mode, f)
        mm.close() and fi.close()
Example #3
0
def have_prefix_files(files):
    '''
    Yields files that contain the current prefix in them, and modifies them
    to replace the prefix with a placeholder.

    :param files: Filenames to check for instances of prefix
    :type files: list of tuples containing strings (prefix, mode, filename)
    '''
    prefix = config.build_prefix
    prefix_bytes = prefix.encode('utf-8')
    prefix_placeholder_bytes = prefix_placeholder.encode('utf-8')
    if on_win:
        forward_slash_prefix = prefix.replace('\\', '/')
        forward_slash_prefix_bytes = forward_slash_prefix.encode('utf-8')
        double_backslash_prefix = prefix.replace('\\', '\\\\')
        double_backslash_prefix_bytes = double_backslash_prefix.encode('utf-8')

    for f in files:
        if f.endswith(('.pyc', '.pyo', '.a')):
            continue
        path = join(prefix, f)
        if isdir(path):
            continue
        if sys.platform != 'darwin' and islink(path):
            # OSX does not allow hard-linking symbolic links, so we cannot
            # skip symbolic links (as we can on Linux)
            continue

        # dont try to mmap an empty file
        if os.stat(path).st_size == 0:
            continue

        fi = open(path, 'rb+')
        mm = mmap.mmap(fi.fileno(), 0)

        mode = 'binary' if mm.find(b'\x00') != -1 else 'text'
        if mode == 'text':
            if sys.platform != 'win32' and mm.find(prefix_bytes) != -1:
                # Use the placeholder for maximal backwards compatibility, and
                # to minimize the occurrences of usernames appearing in built
                # packages.
                rewrite_file_with_new_prefix(path, mm[:], prefix_bytes, prefix_placeholder_bytes)
                mm.close() and fi.close()
                fi = open(path, 'rb+')
                mm = mmap.mmap(fi.fileno(), 0)
        if mm.find(prefix_bytes) != -1:
            yield (prefix, mode, f)
        if on_win and mm.find(forward_slash_prefix_bytes) != -1:
            # some windows libraries use unix-style path separators
            yield (forward_slash_prefix, mode, f)
        elif on_win and mm.find(double_backslash_prefix_bytes) != -1:
            # some windows libraries have double backslashes as escaping
            yield (double_backslash_prefix, mode, f)
        if mm.find(prefix_placeholder_bytes) != -1:
            yield (prefix_placeholder, mode, f)
        mm.close() and fi.close()
Example #4
0
def have_prefix_files(files):
    '''
    Yields files that contain the current prefix in them, and modifies them
    to replace the prefix with a placeholder.

    :param files: Filenames to check for instances of prefix
    :type files: list of str
    '''
    prefix_bytes = config.build_prefix.encode('utf-8')
    placeholder_bytes = prefix_placeholder.encode('utf-8')
    alt_prefix_bytes = prefix_bytes.replace(b'\\', b'/')
    alt_placeholder_bytes = placeholder_bytes.replace(b'\\', b'/')
    for f in files:
        if f.endswith(('.pyc', '.pyo', '.a', '.dylib')):
            continue
        path = join(config.build_prefix, f)
        if isdir(path):
            continue
        if sys.platform != 'darwin' and islink(path):
            # OSX does not allow hard-linking symbolic links, so we cannot
            # skip symbolic links (as we can on Linux)
            continue
        if sys.platform != 'win32' and is_obj(path):
            continue
        # Open file as binary, since it might have any crazy encoding
        with open(path, 'rb') as fi:
            data = fi.read()
        # Skip files that are truly binary
        if b'\x00' in data:
            continue
        # This may end up mixing encodings, but since paths are usually ASCII,
        # this shouldn't be a problem very often. The only way to completely
        # avoid this would be to use chardet (or cChardet) to detect the
        # encoding on the fly.
        if prefix_bytes in data:
            data = data.replace(prefix_bytes, placeholder_bytes)
        elif (sys.platform == 'win32') and (alt_prefix_bytes in data):
            # some windows libraries use unix-style path separators
            data = data.replace(alt_prefix_bytes, alt_placeholder_bytes)
        else:
            continue
        st = os.stat(path)
        # Save as
        with open(path, 'wb') as fo:
            fo.write(data)
        os.chmod(path, stat.S_IMODE(st.st_mode) | stat.S_IWUSR)  # chmod u+w
        if sys.platform == 'win32':
            f = f.replace('\\', '/')
        yield f
Example #5
0
def have_prefix_files(files):
    '''
    Yields files that contain the current prefix in them, and modifies them
    to replace the prefix with a placeholder.

    :param files: Filenames to check for instances of prefix
    :type files: list of str
    '''
    prefix_bytes = config.build_prefix.encode('utf-8')
    placeholder_bytes = prefix_placeholder.encode('utf-8')
    alt_prefix_bytes = prefix_bytes.replace(b'\\', b'/')
    alt_placeholder_bytes = placeholder_bytes.replace(b'\\', b'/')
    for f in files:
        if f.endswith(('.pyc', '.pyo', '.a', '.dylib')):
            continue
        path = join(config.build_prefix, f)
        if isdir(path):
            continue
        if sys.platform != 'darwin' and islink(path):
            # OSX does not allow hard-linking symbolic links, so we cannot
            # skip symbolic links (as we can on Linux)
            continue
        if sys.platform != 'win32' and is_obj(path):
            continue
        # Open file as binary, since it might have any crazy encoding
        with open(path, 'rb') as fi:
            data = fi.read()
        # Skip files that are truly binary
        if b'\x00' in data:
            continue
        # This may end up mixing encodings, but since paths are usually ASCII,
        # this shouldn't be a problem very often. The only way to completely
        # avoid this would be to use chardet (or cChardet) to detect the
        # encoding on the fly.
        if prefix_bytes in data:
            data = data.replace(prefix_bytes, placeholder_bytes)
        elif (sys.platform == 'win32') and (alt_prefix_bytes in data):
            # some windows libraries use unix-style path separators
            data = data.replace(alt_prefix_bytes, alt_placeholder_bytes)
        else:
            continue
        st = os.stat(path)
        # Save as
        with open(path, 'wb') as fo:
            fo.write(data)
        os.chmod(path, stat.S_IMODE(st.st_mode) | stat.S_IWUSR) # chmod u+w
        if sys.platform == 'win32':
            f = f.replace('\\', '/')
        yield f
Example #6
0
def have_prefix_files(files):
    '''
    Yields files that contain the current prefix in them, and modifies them
    to replace the prefix with a placeholder.

    :param files: Filenames to check for instances of prefix
    :type files: list of tuples containing strings (prefix, mode, filename)
    '''
    prefix = config.build_prefix
    prefix_bytes = prefix.encode('utf-8')
    alt_prefix = prefix.replace('\\', '/')
    alt_prefix_bytes = alt_prefix.encode('utf-8')
    prefix_placeholder_bytes = prefix_placeholder.encode('utf-8')
    for f in files:
        if f.endswith(('.pyc', '.pyo', '.a')):
            continue
        path = join(prefix, f)
        if isdir(path):
            continue
        if sys.platform != 'darwin' and islink(path):
            # OSX does not allow hard-linking symbolic links, so we cannot
            # skip symbolic links (as we can on Linux)
            continue
        with open(path, 'rb') as fi:
            data = fi.read()
        mode = 'binary' if b'\x00' in data else 'text'
        if mode == 'text':
            if not (sys.platform == 'win32' and alt_prefix_bytes in data):
                # Use the placeholder for maximal backwards compatibility, and
                # to minimize the occurrences of usernames appearing in built
                # packages.
                data = rewrite_file_with_new_prefix(path, data, prefix_bytes,
                                                    prefix_placeholder_bytes)

        if prefix_bytes in data:
            yield (prefix, mode, f)
        if (sys.platform == 'win32') and (alt_prefix_bytes in data):
            # some windows libraries use unix-style path separators
            yield (alt_prefix, mode, f)
        if prefix_placeholder_bytes in data:
            yield (prefix_placeholder, mode, f)
Example #7
0
def have_prefix_files(files):
    """
    Yields files that contain the current prefix in them, and modifies them
    to replace the prefix with a placeholder.

    :param files: Filenames to check for instances of prefix
    :type files: list of tuples containing strings (prefix, mode, filename)
    """
    prefix = config.build_prefix
    prefix_bytes = prefix.encode("utf-8")
    alt_prefix = prefix.replace("\\", "/")
    alt_prefix_bytes = alt_prefix.encode("utf-8")
    prefix_placeholder_bytes = prefix_placeholder.encode("utf-8")
    for f in files:
        if f.endswith((".pyc", ".pyo", ".a")):
            continue
        path = join(prefix, f)
        if isdir(path):
            continue
        if sys.platform != "darwin" and islink(path):
            # OSX does not allow hard-linking symbolic links, so we cannot
            # skip symbolic links (as we can on Linux)
            continue
        with open(path, "rb") as fi:
            data = fi.read()
        mode = "binary" if b"\x00" in data else "text"
        if mode == "text":
            if not (sys.platform == "win32" and alt_prefix_bytes in data):
                # Use the placeholder for maximal backwards compatibility, and
                # to minimize the occurrences of usernames appearing in built
                # packages.
                data = rewrite_file_with_new_prefix(path, data, prefix_bytes, prefix_placeholder_bytes)

        if prefix_bytes in data:
            yield (prefix, mode, f)
        if (sys.platform == "win32") and (alt_prefix_bytes in data):
            # some windows libraries use unix-style path separators
            yield (alt_prefix, mode, f)
        if prefix_placeholder_bytes in data:
            yield (prefix_placeholder, mode, f)