git @ Cat's Eye Technologies Dipple / master python / relativize-symlinks.py
master

Tree @master (Download .tar.gz)

relativize-symlinks.py @masterraw · history · blame

#!/usr/bin/env python3

# SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
# For more information, please refer to <https://unlicense.org/>
# SPDX-License-Identifier: Unlicense

import os
import subprocess


for fname in os.listdir('.'):
    #print(fname)
    if os.path.islink(fname):
        r = os.readlink(fname)
        subprocess.check_call('ln -s "{}" "{}_"'.format(os.path.relpath(r), fname), shell=True)
        subprocess.check_call('mv "{}_" "{}"'.format(fname, fname), shell=True)