mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
moved 'create_hard_link' to path_tools
This commit is contained in:
parent
3a09cc4795
commit
413e03cae1
3 changed files with 37 additions and 37 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue