Ejemplo n.º 1
0
def create_symlink(src_symlink, target_dir):
    ''' Creates symbolic link if supported by the running win32 platform(typically available from Win Vista).       
     
     @param src_symlink: full path including name of symlink that's to be created 
         (for e.g. C:\test\sample_symlink); Parent directory (C:\test, here) must exist  
     @param target_dir: for which symlink has to be created; must exist; if relative,  
         assumed that its present in same directory where link is to be created
    '''
    ensure_win32_presence('symlink creation')
    
    errmsg = _errmsg_sym_cre('', '')
    ensure_symlink_support(errmsg)
    
    import jaraco.windows.filesystem as fs;
    fs.symlink(target_dir, src_symlink, True)
    LOG.info('Successfully created symlink ' + src_symlink + ' to target ' + target_dir)    
Ejemplo n.º 2
0
def create_symlink(src_symlink, target_dir):
    ''' Creates symbolic link if supported by the running win32 platform(typically available from Win Vista).       
     
     @param src_symlink: full path including name of symlink that's to be created 
         (for e.g. C:\test\sample_symlink); Parent directory (C:\test, here) must exist  
     @param target_dir: for which symlink has to be created; must exist; if relative,  
         assumed that its present in same directory where link is to be created
    '''
    ensure_win32_presence('symlink creation')

    errmsg = _errmsg_sym_cre('', '')
    ensure_symlink_support(errmsg)

    import jaraco.windows.filesystem as fs
    fs.symlink(target_dir, src_symlink, True)
    LOG.info('Successfully created symlink ' + src_symlink + ' to target ' +
             target_dir)
Ejemplo n.º 3
0
def test_is_symlink(tmpdir):
    with tmpdir.as_cwd():
        filesystem.symlink('foobaz', 'foobar')
        assert filesystem.is_symlink('foobar')
try:
    from jaraco.windows.filesystem import symlink
except ImportError:
    # a dirty reimplementation of symlink from jaraco.windows
    from ctypes import windll
    from ctypes.wintypes import LPWSTR, DWORD, BOOLEAN
    CreateSymbolicLink = windll.kernel32.CreateSymbolicLinkW
    CreateSymbolicLink.argtypes = (
        LPWSTR,
        LPWSTR,
        DWORD,
    )
    CreateSymbolicLink.restype = BOOLEAN

    def symlink(link, target, target_is_directory=False):
        """
		An implementation of os.symlink for Windows (Vista and greater)
		"""
        target_is_directory = target_is_directory or os.path.isdir(target)
        CreateSymbolicLink(link, target, target_is_directory)


assert sys.platform in ('win32', )
os.makedirs(r'.\foo')
assert os.path.isdir(r'.\foo')

symlink(r'.\foo_sym', r'.\foo')
assert os.path.isdir(r'.\foo_sym')
assert os.path.islink(r'.\foo_sym')  # fails
Ejemplo n.º 5
0
def test_is_symlink(tmpdir):
	with tmpdir.as_cwd():
		filesystem.symlink('foobaz', 'foobar')
		assert filesystem.is_symlink('foobar')
Ejemplo n.º 6
0
 def symlink(self, src, dst):
     flag = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
     if os.getenv('APPVEYOR'):
         flag = 0
     fs.symlink(src, dst, flag)
import sys

try:
	from jaraco.windows.filesystem import symlink
except ImportError:
	# a dirty reimplementation of symlink from jaraco.windows
	from ctypes import windll
	from ctypes.wintypes import LPWSTR, DWORD, BOOLEAN
	CreateSymbolicLink = windll.kernel32.CreateSymbolicLinkW
	CreateSymbolicLink.argtypes = (
		LPWSTR,
		LPWSTR,
		DWORD,
		)
	CreateSymbolicLink.restype = BOOLEAN

	def symlink(link, target, target_is_directory = False):
		"""
		An implementation of os.symlink for Windows (Vista and greater)
		"""
		target_is_directory = target_is_directory or os.path.isdir(target)
		CreateSymbolicLink(link, target, target_is_directory)

assert sys.platform in ('win32',)
os.makedirs(r'.\foo')
assert os.path.isdir(r'.\foo')

symlink(r'.\foo_sym', r'.\foo')
assert os.path.isdir(r'.\foo_sym')
assert os.path.islink(r'.\foo_sym') # fails