Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | import sys |
| 3 | import os |
| 4 | |
| 5 | # Take a sysroot directory and turn all the abolute symlinks and turn them into |
| 6 | # relative ones such that the sysroot is usable within another system. |
| 7 | |
| 8 | if len(sys.argv) != 2: |
| 9 | print("Usage is " + sys.argv[0] + "<directory>") |
| 10 | sys.exit(1) |
| 11 | |
| 12 | topdir = sys.argv[1] |
| 13 | topdir = os.path.abspath(topdir) |
| 14 | |
| 15 | def handlelink(filep, subdir): |
| 16 | link = os.readlink(filep) |
| 17 | if link[0] != "/": |
| 18 | return |
| 19 | if link.startswith(topdir): |
| 20 | return |
| 21 | #print("Replacing %s with %s for %s" % (link, topdir+link, filep)) |
| 22 | print("Replacing %s with %s for %s" % (link, os.path.relpath(topdir+link, subdir), filep)) |
| 23 | os.unlink(filep) |
| 24 | os.symlink(os.path.relpath(topdir+link, subdir), filep) |
| 25 | |
| 26 | for subdir, dirs, files in os.walk(topdir): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 27 | for f in dirs + files: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | filep = os.path.join(subdir, f) |
| 29 | if os.path.islink(filep): |
| 30 | #print("Considering %s" % filep) |
| 31 | handlelink(filep, subdir) |