Permalink
Browse files

working on it...

  • Loading branch information...
mortenvp committed Dec 20, 2017
1 parent 1e1c939 commit f3abb90fde67fc37c5594d6fe170463d4caae7c4
Showing with 19 additions and 1 deletion.
  1. +15 −1 src/wurf/symlink.py
  2. +4 −0 test/python/test_symlink.py
View
@@ -10,6 +10,9 @@
def create_symlink(from_path, to_path, overwrite=False):
if overwrite and os.path.lexists(path=to_path):
_remove_symlink(path=to_path)
if IS_PY2 and sys.platform == 'win32':
_py2_win32_create_symlink(from_path=from_path, to_path=to_path)
elif IS_PY2:
@@ -18,6 +21,17 @@ def create_symlink(from_path, to_path, overwrite=False):
_py3_create_symlink(from_path=from_path, to_path=to_path)
def _remove_symlink(path):
if sys.platform == 'win32':
# On Windows, the symlink is not considered a link, but
# a directory, so it is removed with rmdir. The contents
# of the original folder will not be removed.
os.rmdir(path)
else:
# On Unix, we remove the symlink with unlink
os.unlink(path)
def _py2_win32_create_symlink(from_path, to_path):
# os.symlink() is not available in Python 2.7 on Windows.
@@ -28,7 +42,7 @@ def _py2_win32_create_symlink(from_path, to_path):
# https://stackoverflow.com/a/22225651/1717320
cmd = ['mklink']
if os.path.isdir(from_path):
cmd += ['/J']
@@ -18,6 +18,8 @@ def test_symlink_directory(testdirectory):
assert os.path.exists(link_dir)
assert os.path.isdir(link_dir)
create_symlink(from_path=foo_dir.path(), to_path=link_dir, overwrite=True)
def test_symlink_file(testdirectory):
sub1 = testdirectory.mkdir('sub1')
@@ -31,3 +33,5 @@ def test_symlink_file(testdirectory):
assert sub2.contains_file('ok.txt')
assert os.path.isfile(link_path)
create_symlink(from_path=ok_path, to_path=link_path, overwrite=True)

0 comments on commit f3abb90

Please sign in to comment.