fsp/site_scons/symlinkBuilder.py
2020-06-04 15:57:35 +02:00

35 lines
993 B
Python

#
# Relative symlink SCons builder
#
# Version 1.2
# 04-Jun-2020
#
def Symlink(target, source, env=None):
"""Create relative symlink target pointing to source.
This builder creates symlinks named target pointing to source.
Target is removed if exists.
Keyword arguments:
target -- list of symlink targets
source -- list of files to be compressed
env -- SCons environment (not used)
"""
import os
if not isinstance(target, list):
raise TypeError("target must be list")
elif not isinstance(source, list):
raise TypeError("source must be list")
if len(target) != len(source):
raise ValueError("target and source lists must have same size")
for i in range(0,len(target)):
try:
os.unlink(str(target[i]))
except OSError:
pass
if not str(source[i]).rfind('/') == -1:
source[i]=str(source[i])[str(source[i]).rfind('/')+1:]
os.symlink(str(source[i]),str(target[i]))
return None