90 lines
2.5 KiB
Python
90 lines
2.5 KiB
Python
"""
|
|
Package clone backend abstraction
|
|
"""
|
|
|
|
from core.pkg.backend import PKG_CORE_BACKEND_REMOTE, PKG_CORE_BACKEND_LOCAL
|
|
from core.pkg.version import VxVersion
|
|
from core.pkg.find import pkg_find
|
|
from core.logger import log
|
|
|
|
__all__ = [
|
|
'pkg_clone'
|
|
]
|
|
|
|
#---
|
|
# Internals
|
|
#---
|
|
|
|
def _pkg_clone_core(pkg, prefix):
|
|
"""
|
|
|
|
@args
|
|
> pkg (dict) - package information
|
|
|
|
@return
|
|
> the package path if successfully cloned, None otherwise
|
|
"""
|
|
version = pkg['version']
|
|
|
|
# be sure that the package target is in the global storage
|
|
log.user(f"cloning package {pkg['name']}...")
|
|
pkg_path = PKG_CORE_BACKEND_REMOTE.package_clone(pkg)
|
|
if not pkg_path:
|
|
log.error(
|
|
f"{pkg['name']}@{version.name}: unable to clone the package, abord",
|
|
)
|
|
return None
|
|
|
|
# "clone" the package (create a symbolic link)
|
|
pkg['url'] = pkg_path
|
|
return PKG_CORE_BACKEND_LOCAL.package_clone(pkg, prefix)
|
|
|
|
#---
|
|
# Public
|
|
#---
|
|
|
|
def pkg_clone(name, version, prefix, confirm=False):
|
|
r""" Clone the package
|
|
|
|
This function will try to clone the package with the exact selected
|
|
version, with all of its dependencies. See <core/pkg/backend> for more
|
|
information about the process.
|
|
|
|
@args
|
|
> name (str) - exact valid package name
|
|
> version (str) - version query string
|
|
> prefix (str) - clone path prefix
|
|
> confirm (bool) - display user input to confirm the clone
|
|
|
|
@return
|
|
> the package path if successfully cloned, None otherwise
|
|
"""
|
|
# try to find the package anywhere that the vxSDK allow
|
|
pkg_list = pkg_find(name, version, local=True, remote=True)
|
|
if not pkg_list:
|
|
log.error("[pkg] pacakge find error")
|
|
return None
|
|
if len(pkg_list) != 1:
|
|
log.warn("[pkg] multiple package found, other will be ignored")
|
|
|
|
# check version information
|
|
pkg_info = pkg_list[0]
|
|
if not pkg_info['version']:
|
|
if version:
|
|
log.error(f"{name}@{version}: unable to find the version")
|
|
return None
|
|
pkg_info['version'] = VxVersion(pkg_info['default_branch'], 'branch')
|
|
|
|
# wait user interaction if needed
|
|
if confirm and not 'local' in pkg_info['version'].sources:
|
|
log.user(
|
|
f"Do you want to install '{pkg_info['full_name']}'? (Y/n) ",
|
|
end = ''
|
|
)
|
|
valid = input()
|
|
if valid and not valid in ['Y', 'y', 'yes', 'Yes']:
|
|
return None
|
|
|
|
# "real" clone the package
|
|
return _pkg_clone_core(pkg_info, prefix)
|