mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
implemented 'create_hard_link' function in openpype lib
This commit is contained in:
parent
db06be99d5
commit
8088534caa
3 changed files with 37 additions and 1 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue