def have_prefix_files(files): 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 if is_obj(path): continue if islink(path): continue try: with open(path) as fi: data = fi.read() except UnicodeDecodeError: continue if prefix not in data: continue st = os.stat(path) data = data.replace(prefix, prefix_placeholder) with open(path, 'w') as fo: fo.write(data) os.chmod(path, stat.S_IMODE(st.st_mode) | stat.S_IWUSR) # chmod u+w yield f
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)
def get_untracked_obj_files(prefix): res = [] files = untracked(prefix) for f in files: path = join(prefix, f) if post.is_obj(path): res.append(f) return res
def get_package_obj_files(dist, prefix): data = linked_data(prefix).get(dist) res = [] if data: for f in data.get('files', []): path = join(prefix, f) if post.is_obj(path): res.append(f) return res
def get_package_obj_files(dist, prefix): with open(join(prefix, 'conda-meta', dist + '.json')) as f: data = json.load(f) res = [] files = data['files'] for f in files: path = join(prefix, f) if post.is_obj(path): res.append(f) return res
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