implemented 'create_hard_link' function in openpype lib

This commit is contained in:
Jakub Trllo 2022-03-07 14:49:55 +01:00
parent db06be99d5
commit 8088534caa
3 changed files with 37 additions and 1 deletions

View file

@ -58,6 +58,7 @@ from .anatomy import (
from .config import get_datetime_data
from .vendor_bin_utils import (
create_hard_link,
get_vendor_bin_path,
get_oiio_tools_path,
get_ffmpeg_tool_path,
@ -208,6 +209,7 @@ __all__ = [
"get_paths_from_environ",
"get_global_environments",
"create_hard_link",
"get_vendor_bin_path",
"get_oiio_tools_path",
"get_ffmpeg_tool_path",

View file

@ -6,7 +6,6 @@ import logging
import six
from openpype.settings import get_project_settings
from openpype.settings.lib import get_site_local_overrides
from .anatomy import Anatomy
from .profiles_filtering import filter_profiles

View file

@ -8,6 +8,41 @@ import distutils
log = logging.getLogger("FFmpeg utils")
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.