From 21fb804c39b428f17f584bffa41a20ac54a545f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Andr=C3=A9e?= Date: Tue, 11 Sep 2012 11:35:55 +0200 Subject: [PATCH] setup linking fix --- setup.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 9e18aafc..0800afc8 100755 --- a/setup.py +++ b/setup.py @@ -705,7 +705,7 @@ class Setup(): print('Creating symbolic link %s with target directory %s' % (dest, target)) if os.path.exists(dest): self.removeLists([], [dest]) - os.symlink(target, dest) + self.symlink(target, dest) if os.path.islink(source) and (self.linking != COPY) and os.path.isfile(os.path.realpath(source)): target = os.readlink(source) if self.linking == HARD: @@ -718,13 +718,13 @@ class Setup(): os.link(mytarget, dest) else: print('\033[31mTarget did not exists, using symlink instead\033[39m') - os.symlink(target, dest) + self.symlink(target, dest) else: for dest in destinations: print('Creating symbolic link %s with target file %s' % (dest, target)) if os.path.exists(dest): self.removeLists([], [dest]) - os.symlink(target, dest) + self.symlink(target, dest) for dest in destinations: dir = dest[:dest.rfind('/') + 1] if not os.path.exists(dir): @@ -750,7 +750,7 @@ class Setup(): print('Creating symbolic link %s with target directory %s' % (dest, target)) if os.path.exists(dest): self.removeLists([], [dest]) - os.symlink(target, dest) + self.symlink(target, dest) else: target = destinations[0] for dest in destinations if self.linking == COPY else [target]: @@ -767,7 +767,32 @@ class Setup(): print('Creating symbolic link %s with target file %s' % (dest, target)) if os.path.exists(dest): os.unlink(dest) - os.symlink(target, dest) + self.symlink(target, dest) + + + ''' + Create a symlink with a relative path + ''' + def symlink(self, target, dest): + if target.startswith('./') or target.startswith('../'): + os.symlink(target, dest) + elif '/' not in target: + os.symlink('./' + target, dest) + else: + targets = target.split('/') + dests = dest.split('/') + + while (len(targets) > 1) and (len(target) > 1) and (targets[0] == dests[0]): + targets = targets[1:] + dests = dests[1:] + + if (len(dests) == 1): + targets = ['.'] + targets + else: + targets = (['..'] * (len(dests) - 1)) + targets + + print('>>> ' + str(targets) + ' -> ' + dest) + os.symlink('/'.join(targets), dest) '''