Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | |
| 6 | # Create a *relative* symlink, just like ln --relative does but without needing |
| 7 | # coreutils 8.16. |
| 8 | |
| 9 | import sys, os |
| 10 | |
| 11 | if len(sys.argv) != 3: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 12 | print("$ lnr TARGET LINK_NAME") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | sys.exit(1) |
| 14 | |
| 15 | target = sys.argv[1] |
| 16 | linkname = sys.argv[2] |
| 17 | |
| 18 | if os.path.isabs(target): |
| 19 | if not os.path.isabs(linkname): |
| 20 | linkname = os.path.abspath(linkname) |
| 21 | start = os.path.dirname(linkname) |
| 22 | target = os.path.relpath(target, start) |
| 23 | |
| 24 | os.symlink(target, linkname) |