2021-09-12 06:10:15 +02:00
|
|
|
import click
|
|
|
|
import logging
|
|
|
|
|
2022-11-09 15:22:06 +01:00
|
|
|
from typing import Optional, Sequence, Union
|
2022-08-20 03:44:15 +02:00
|
|
|
|
2022-10-08 04:04:27 +02:00
|
|
|
from config.state import config
|
2022-08-20 03:44:15 +02:00
|
|
|
from constants import Arch
|
2022-02-16 20:44:42 +01:00
|
|
|
from utils import programs_available
|
|
|
|
from .docker import DockerWrapper
|
2022-02-17 16:25:31 +01:00
|
|
|
from .wrapper import Wrapper
|
2021-09-13 15:44:44 +02:00
|
|
|
|
2022-02-17 16:25:31 +01:00
|
|
|
wrapper_impls: dict[str, Wrapper] = {
|
|
|
|
'docker': DockerWrapper(),
|
2022-02-16 20:44:42 +01:00
|
|
|
}
|
2021-08-04 18:36:37 +02:00
|
|
|
|
2021-08-08 18:32:42 +02:00
|
|
|
|
2022-11-09 15:22:06 +01:00
|
|
|
def get_wrapper_type(wrapper_type: Optional[str] = None):
|
2022-08-27 16:48:50 +02:00
|
|
|
return wrapper_type or config.file.wrapper.type
|
2021-08-04 18:36:37 +02:00
|
|
|
|
2021-09-30 03:50:11 +02:00
|
|
|
|
2022-11-09 15:22:06 +01:00
|
|
|
def get_wrapper_impl(wrapper_type: Optional[str] = None) -> Wrapper:
|
2022-02-17 16:25:31 +01:00
|
|
|
return wrapper_impls[get_wrapper_type(wrapper_type)]
|
|
|
|
|
|
|
|
|
2022-11-09 15:22:06 +01:00
|
|
|
def wrap(wrapper_type: Optional[str] = None):
|
2022-02-16 20:44:42 +01:00
|
|
|
wrapper_type = get_wrapper_type(wrapper_type)
|
|
|
|
if wrapper_type != 'none':
|
2022-02-17 16:25:31 +01:00
|
|
|
get_wrapper_impl(wrapper_type).wrap()
|
2021-09-30 03:50:11 +02:00
|
|
|
|
2021-08-17 20:42:17 +02:00
|
|
|
|
2022-11-09 15:22:06 +01:00
|
|
|
def is_wrapped(wrapper_type: Optional[str] = None):
|
2022-09-22 01:40:59 +02:00
|
|
|
wrapper_type = get_wrapper_type(wrapper_type)
|
|
|
|
return wrapper_type != 'none' and get_wrapper_impl(wrapper_type).is_wrapped()
|
2021-09-12 06:10:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
def enforce_wrap(no_wrapper=False):
|
2022-02-16 20:44:42 +01:00
|
|
|
wrapper_type = get_wrapper_type()
|
2022-08-27 16:48:50 +02:00
|
|
|
if wrapper_type != 'none' and not is_wrapped(wrapper_type) and not config.runtime.no_wrap and not no_wrapper:
|
2022-02-16 20:44:42 +01:00
|
|
|
logging.info(f'Wrapping in {wrapper_type}')
|
|
|
|
wrap()
|
2021-09-12 06:10:15 +02:00
|
|
|
|
|
|
|
|
2022-08-20 03:44:15 +02:00
|
|
|
def check_programs_wrap(programs: Union[str, Sequence[str]]):
|
2021-09-29 23:49:46 +02:00
|
|
|
if not programs_available(programs):
|
2022-08-20 03:44:15 +02:00
|
|
|
logging.debug(f"Wrapping because one of {[programs] if isinstance(programs, str) else programs} isn't available.")
|
|
|
|
enforce_wrap()
|
|
|
|
|
|
|
|
|
|
|
|
def wrap_if_foreign_arch(arch: Arch):
|
|
|
|
if arch != config.runtime.arch:
|
2021-09-29 23:49:46 +02:00
|
|
|
enforce_wrap()
|
|
|
|
|
|
|
|
|
2021-09-12 06:10:15 +02:00
|
|
|
nowrapper_option = click.option(
|
2022-08-27 04:59:18 +02:00
|
|
|
'-w/-W',
|
|
|
|
'--force-wrapper/--no-wrapper',
|
|
|
|
'wrapper_override',
|
2021-09-12 06:10:15 +02:00
|
|
|
is_flag=True,
|
2022-08-27 04:59:18 +02:00
|
|
|
default=None,
|
|
|
|
help='Force or disable the docker wrapper. Defaults to autodetection.',
|
2021-09-12 06:10:15 +02:00
|
|
|
)
|