mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Move WindowsSymlinkOverride logic to Runtime
This commit is contained in:
+2
-27
@@ -1,30 +1,5 @@
|
||||
import os
|
||||
import ctypes
|
||||
|
||||
|
||||
class WindowsSymlinkOverride(object):
|
||||
FUNC = None
|
||||
|
||||
def __init__(self):
|
||||
func = ctypes.windll.kernel32.CreateSymbolicLinkW
|
||||
func.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
|
||||
func.restype = ctypes.c_ubyte
|
||||
|
||||
WindowsSymlinkOverride.FUNC = func
|
||||
|
||||
@staticmethod
|
||||
def symlink(source, link_name):
|
||||
'''symlink(source, link_name) - DVC override for Windows
|
||||
Creates a symbolic link pointing to source named link_name'''
|
||||
|
||||
flags = 0
|
||||
if source is not None and os.path.isdir(source):
|
||||
flags = 1
|
||||
if WindowsSymlinkOverride.FUNC(link_name, source, flags) == 0:
|
||||
raise ctypes.WinError()
|
||||
from dvc.runtime import Runtime
|
||||
|
||||
|
||||
def setup():
|
||||
if os.name == 'nt':
|
||||
os.symlink = WindowsSymlinkOverride().symlink
|
||||
pass
|
||||
Runtime.symlink_setup()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
import ctypes
|
||||
|
||||
from dvc.config import Config, ConfigI
|
||||
from dvc.exceptions import DvcException
|
||||
@@ -10,6 +11,31 @@ from dvc.settings import Settings
|
||||
|
||||
class Runtime(object):
|
||||
CONFIG = 'dvc.conf'
|
||||
SYMLINC_OVERRIDE = None
|
||||
|
||||
@staticmethod
|
||||
def symlink_setup():
|
||||
if os.name != 'nt':
|
||||
return
|
||||
|
||||
func = ctypes.windll.kernel32.CreateSymbolicLinkW
|
||||
func.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
|
||||
func.restype = ctypes.c_ubyte
|
||||
|
||||
Runtime.SYMLINC_OVERRIDE = func
|
||||
|
||||
os.symlink = Runtime.symlink
|
||||
|
||||
@staticmethod
|
||||
def symlink(source, link_name):
|
||||
'''symlink(source, link_name) - DVC override for Windows
|
||||
Creates a symbolic link pointing to source named link_name'''
|
||||
|
||||
flags = 0
|
||||
if source is not None and os.path.isdir(source):
|
||||
flags = 1
|
||||
if Runtime.SYMLINC_OVERRIDE(link_name, source, flags) == 0:
|
||||
raise ctypes.WinError()
|
||||
|
||||
@staticmethod
|
||||
def conf_file_path(git_dir):
|
||||
@@ -18,6 +44,7 @@ class Runtime(object):
|
||||
@staticmethod
|
||||
def run(cmd_class, parse_config=True):
|
||||
try:
|
||||
Runtime.symlink_setup()
|
||||
runtime_git = GitWrapper()
|
||||
|
||||
if parse_config:
|
||||
|
||||
Reference in New Issue
Block a user