diff --git a/openpype/lib/__init__.py b/openpype/lib/__init__.py index c4097086e0..34b217f690 100644 --- a/openpype/lib/__init__.py +++ b/openpype/lib/__init__.py @@ -17,7 +17,6 @@ site.addsitedir(python_version_dir) from .vendor_bin_utils import ( - create_hard_link, find_executable, get_vendor_bin_path, get_oiio_tools_path, @@ -160,6 +159,7 @@ from .plugin_tools import ( ) from .path_tools import ( + create_hard_link, version_up, get_version_from_path, get_last_version_from_path, @@ -210,7 +210,6 @@ __all__ = [ "get_paths_from_environ", "get_global_environments", - "create_hard_link", "get_vendor_bin_path", "get_oiio_tools_path", "get_ffmpeg_tool_path", @@ -293,6 +292,7 @@ __all__ = [ "get_unique_layer_name", "get_background_layers", + "create_hard_link", "version_up", "get_version_from_path", "get_last_version_from_path", diff --git a/openpype/lib/path_tools.py b/openpype/lib/path_tools.py index 71fc0fe25c..c36e45c51f 100644 --- a/openpype/lib/path_tools.py +++ b/openpype/lib/path_tools.py @@ -13,6 +13,41 @@ from .profiles_filtering import filter_profiles log = logging.getLogger(__name__) +def create_hard_link(src_path, dst_path): + """Create hardlink of file. + + Args: + src_path(str): Full path to a file which is used as source for + hardlink. + dst_path(str): Full path to a file where a link of source will be + added. + """ + # Use `os.link` if is available + # - should be for all platforms with newer python versions + if hasattr(os, "link"): + os.link(src_path, dst_path) + return + + # Windows implementation of hardlinks + # - used in Python 2 + if platform.system().lower() == "windows": + import ctypes + from ctypes.wintypes import BOOL + CreateHardLink = ctypes.windll.kernel32.CreateHardLinkW + CreateHardLink.argtypes = [ + ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_void_p + ] + CreateHardLink.restype = BOOL + + res = CreateHardLink(dst_path, src_path, None) + if res == 0: + raise ctypes.WinError() + # Raises not implemented error if gets here + raise NotImplementedError( + "Implementation of hardlink for current environment is missing." + ) + + def _rreplace(s, a, b, n=1): """Replace a with b in string s from right side n times.""" return b.join(s.rsplit(a, n)) diff --git a/openpype/lib/vendor_bin_utils.py b/openpype/lib/vendor_bin_utils.py index 4a62da8f0c..4be016f656 100644 --- a/openpype/lib/vendor_bin_utils.py +++ b/openpype/lib/vendor_bin_utils.py @@ -86,41 +86,6 @@ def find_executable(executable): return None -def create_hard_link(src_path, dst_path): - """Create hardlink of file. - - Args: - src_path(str): Full path to a file which is used as source for - hardlink. - dst_path(str): Full path to a file where a link of source will be - added. - """ - # Use `os.link` if is available - # - should be for all platforms with newer python versions - if hasattr(os, "link"): - os.link(src_path, dst_path) - return - - # Windows implementation of hardlinks - # - used in Python 2 - if platform.system().lower() == "windows": - import ctypes - from ctypes.wintypes import BOOL - CreateHardLink = ctypes.windll.kernel32.CreateHardLinkW - CreateHardLink.argtypes = [ - ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_void_p - ] - CreateHardLink.restype = BOOL - - res = CreateHardLink(dst_path, src_path, None) - if res == 0: - raise ctypes.WinError() - # Raises not implemented error if gets here - raise NotImplementedError( - "Implementation of hardlink for current environment is missing." - ) - - def get_vendor_bin_path(bin_app): """Path to OpenPype vendorized binaries.