Created
December 11, 2018 06:26
-
-
Save arcivanov/afe3eb430b7e3005321993e9615e6b1f to your computer and use it in GitHub Desktop.
Repoint absolute symlinks to relative using PREFIX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
PREFIX = "some prefix" | |
for root, dirs, files in os.walk("."): | |
dir_fd = os.open(root, os.O_DIRECTORY) | |
for f in files: | |
link_path = os.path.join(root, f) | |
if os.path.islink(link_path): | |
real_path = os.path.realpath(link_path) | |
new_real_path = real_path[len(PREFIX):] | |
print(new_real_path, "|", f, "|", root) | |
os.unlink(link_path) | |
os.symlink(new_real_path, f, dir_fd=dir_fd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment