Skip to content

Commit

Permalink
Working on it
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenvp committed Dec 30, 2017
1 parent 297f32b commit 22f46fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
2 changes: 2 additions & 0 deletions NEWS.rst
Expand Up @@ -6,6 +6,8 @@ of every change, see the Git log.

Latest
------
* Patch: Refactor symlink code into a standalone utility. This makes it reusable by other tools which needs to make
symlinks.
* Patch: Update to newest pytest-testdirectory plugin
* Minor: Adding override attribute.
* Minor: Added post_resolve.
Expand Down
32 changes: 4 additions & 28 deletions src/wurf/create_symlink_resolver.py
Expand Up @@ -2,7 +2,6 @@
# encoding: utf-8

import os
import sys

from .symlink import create_symlink

Expand Down Expand Up @@ -50,37 +49,14 @@ def resolve(self):
self.dependency.real_path = os.path.realpath(path)
return link_path

# os.symlink() is not available in Python 2.7 on Windows.
# We use the original function if it is available, otherwise we
# create a helper function for Windows
os_symlink = getattr(os, "symlink", None)
if not callable(os_symlink) and sys.platform == 'win32':

def symlink_windows(target, link_path):
# mklink is used to create an NTFS junction, i.e. symlink
cmd = 'mklink /J "{}" "{}"'.format(
link_path.replace('/', '\\'), target.replace('/', '\\'))
self.ctx.cmd_and_log(cmd)

os_symlink = symlink_windows

try:

self.ctx.to_log('wurf: CreateSymlinkResolver {} -> {}'.format(
link_path, path))

# We need to remove the symlink if it already exists,
# since it may point to an incorrect folder
if os.path.lexists(link_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(link_path)
else:
# On Unix, we remove the symlink with unlink
os.unlink(link_path)

os_symlink(path, link_path)
# We set overwrite True since We need to remove the symlink if it
# already exists since it may point to an incorrect folder
create_symlink(from_path=path, to_path=link_path, overwrite=True)

except Exception:

Expand Down

0 comments on commit 22f46fd

Please sign in to comment.