Esempio n. 1
0
def require_hostsys_dependencies(deps):
    """
    Require a dependency 'dep' to be installed. Try to install if not.
    Fail if not possible.
    """
    if not deps:
        return
    global REQUIRER_CHECKED_CACHE
    deps_to_check = [d for d in deps if d not in REQUIRER_CHECKED_CACHE]
    if not deps_to_check:
        return
    from pybombs import install_manager
    from pybombs.config_manager import config_manager
    s_order = config_manager.get('satisfy_order')
    # These are host system dependencies, so disallow source package manager
    config_manager.set('satisfy_order', 'native')
    REQUIRER_CHECKED_CACHE += deps_to_check
    install_manager.InstallManager().install(
            deps_to_check,
            'install', # install / update
            fail_if_not_exists=False,
            update_if_exists=False,
            quiet=True,
            print_tree=False,
    )
    # Restore previous settings
    config_manager.set('satisfy_order', s_order)
Esempio n. 2
0
def require_hostsys_dependencies(deps):
    """
    Require a dependency 'dep' to be installed. Try to install if not.
    Fail if not possible.
    """
    if not deps:
        return
    global REQUIRER_CHECKED_CACHE
    deps_to_check = [d for d in deps if d not in REQUIRER_CHECKED_CACHE]
    if not deps_to_check:
        return
    from pybombs.commands import Install
    from pybombs.config_manager import config_manager
    s_order = config_manager.get('satisfy_order')
    # These are host system dependencies, so disallow source package manager
    config_manager.set('satisfy_order', 'native')
    args = argparse.Namespace(
        packages=[deps_to_check],
        update=False,
        static=False,
        no_deps=False,
        print_tree=False,
        quiet_install=True,
        deps_only=False,
        verify=False,
    )
    REQUIRER_CHECKED_CACHE += deps_to_check
    Install('install', args).run()
    # Restore previous settings
    config_manager.set('satisfy_order', s_order)
Esempio n. 3
0
def _process_thread(event, args, kwargs):
    """
    This actually runs the process.
    """
    from pybombs.config_manager import config_manager
    from pybombs.utils import output_proc
    _process_thread.result = 0
    extra_popen_args = {}
    use_oproc = False
    o_proc = kwargs.get('o_proc')
    if isinstance(o_proc, output_proc.OutputProcessor):
        use_oproc = True
        extra_popen_args = o_proc.extra_popen_args
    if kwargs.get('shell', False) and isinstance(args, list):
        args = ' '.join(args)
    if kwargs.get('elevate'):
        if kwargs.get('shell', False) and isinstance(args, str):
            args = ' '.join(config_manager.get('elevate_pre_args')) + args
        else:
            args = config_manager.get('elevate_pre_args') + args
    log = logger.getChild("_process_thread()")
    log.debug("Executing command `{cmd}'".format(cmd=str(args).strip()))
    proc = subprocess.Popen(args,
                            shell=kwargs.get('shell', False),
                            env=kwargs.get(
                                'env',
                                config_manager.get_active_prefix().env),
                            **extra_popen_args)
    if use_oproc:
        ret_code = run_with_output_processing(proc, o_proc, event,
                                              kwargs.get('cleanup'))
    else:
        # Wait until the process is done, or monitor_process() sends us the quit event
        ret_code = None
        while ret_code is None and not event.is_set():
            ret_code = proc.poll()
            event.wait(1)
            if event.is_set():
                kill_process_tree(proc)
                if kwargs.get('cleanup') is not None:
                    kwargs.get('cleanup')()
                break
    _process_thread.result = ret_code
    event.set()
    return ret_code
Esempio n. 4
0
def _process_thread(event, args, kwargs):
    """
    This actually runs the process.
    """
    from pybombs.config_manager import config_manager
    from pybombs.utils import output_proc
    _process_thread.result = 0
    extra_popen_args = {}
    use_oproc = False
    o_proc = kwargs.get('o_proc')
    if isinstance(o_proc, output_proc.OutputProcessor):
        use_oproc = True
        extra_popen_args = o_proc.extra_popen_args
    if kwargs.get('shell', False) and isinstance(args, list):
        args = ' '.join(args)
    if kwargs.get('elevate'):
        if kwargs.get('shell', False) and isinstance(args, str):
            args = ' '.join(config_manager.get('elevate_pre_args')) + args
        else:
            args = config_manager.get('elevate_pre_args') + args
    log = logger.getChild("_process_thread()")
    log.debug("Executing command `{cmd}'".format(cmd=str(args).strip()))
    proc = subprocess.Popen(
        args,
        shell=kwargs.get('shell', False),
        env=kwargs.get('env', config_manager.get_active_prefix().env),
        **extra_popen_args
    )
    if use_oproc:
        ret_code = run_with_output_processing(proc, o_proc, event, kwargs.get('cleanup'))
    else:
        # Wait until the process is done, or monitor_process() sends us the quit event
        ret_code = None
        while ret_code is None and not event.is_set():
            ret_code = proc.poll()
            event.wait(1)
            if event.is_set():
                kill_process_tree(proc)
                if kwargs.get('cleanup') is not None:
                    kwargs.get('cleanup')()
                break
    _process_thread.result = ret_code
    event.set()
    return ret_code
Esempio n. 5
0
def require_hostsys_dependencies(deps):
    """
    Require a dependency 'dep' to be installed. Try to install if not.
    Fail if not possible.
    """
    if not deps:
        return
    from pybombs.commands import Install
    from pybombs.config_manager import config_manager
    s_order = config_manager.get('satisfy_order')
    # These are host system dependencies, so disallow source package manager
    config_manager.set('satisfy_order', 'native')
    args = argparse.Namespace(
        packages=[deps],
        update=False,
        static=False,
        no_deps=False,
        print_tree=False,
        quiet_install=True,
    )
    Install('install', args).run()
    # Restore previous settings
    config_manager.set('satisfy_order', s_order)
Esempio n. 6
0
def _process_thread(event, args, kwargs):
    """
    This actually runs the process.
    """
    def elevate_command(args, elevate_pre_args):
        " Modify the command to run with elevated privileges. "
        if isinstance(elevate_pre_args, str):
            elevate_pre_args = [elevate_pre_args,]
        if len(elevate_pre_args[0].strip()) == 0:
            elevate_pre_args = []
        if kwargs.get('shell', False) and isinstance(args, str):
            args = ' '.join(elevate_pre_args) + args
        else:
            args = elevate_pre_args + args
        return args
    def pretty_print_cmd(args):
        " Return pretty-printed version of the command. "
        if isinstance(args, list):
            return ' '.join(args)
        else:
            return "{sh}{cmd}".format(
                sh="$ " if kwargs.get('shell', False) else "",
                cmd=args.strip()
            )
    from pybombs.config_manager import config_manager
    from pybombs.utils import output_proc
    _process_thread.result = 0
    extra_popen_args = {}
    use_oproc = False
    o_proc = kwargs.get('o_proc')
    if isinstance(o_proc, output_proc.OutputProcessor):
        use_oproc = True
        extra_popen_args = o_proc.extra_popen_args
    if kwargs.get('shell', False) and isinstance(args, list):
        args = ' '.join(args)
    if kwargs.get('elevate'):
        args = elevate_command(args, config_manager.get('elevate_pre_args'))
    log = logger.getChild("_process_thread()")
    cmd_pp = pretty_print_cmd(args)
    log.debug("Executing command `{cmd}'".format(cmd=cmd_pp))
    try:
        proc = subprocess.Popen(
            args,
            shell=kwargs.get('shell', False),
            env=kwargs.get('env', config_manager.get_active_prefix().env),
            **extra_popen_args
        )
    except OSError:
        log.error("Failure executing command `{cmd}'!".format(cmd=cmd_pp))
        if kwargs.get('elevate'):
            log.debug("Make sure command can be elevated using `{epa}' " \
                           "on this platform!".format(
                               epa=config_manager.get('elevate_pre_args')))
        return -1
    if use_oproc:
        ret_code = run_with_output_processing(
            proc, o_proc,
            event, kwargs.get('cleanup')
        )
    else:
        # Wait until the process is done, or monitor_process() sends us the
        # quit event
        ret_code = None
        while ret_code is None and not event.is_set():
            ret_code = proc.poll()
            event.wait(1)
            if event.is_set():
                kill_process_tree(proc)
                if kwargs.get('cleanup') is not None:
                    kwargs.get('cleanup')()
                break
    _process_thread.result = ret_code
    event.set()
    return ret_code
Esempio n. 7
0
def _process_thread(event, args, kwargs):
    """
    This actually runs the process.
    """
    def elevate_command(args, elevate_pre_args):
        " Modify the command to run with elevated privileges. "
        if isinstance(elevate_pre_args, str):
            elevate_pre_args = [
                elevate_pre_args,
            ]
        if len(elevate_pre_args[0].strip()) == 0:
            elevate_pre_args = []
        if kwargs.get('shell', False) and isinstance(args, str):
            args = ' '.join(elevate_pre_args) + args
        else:
            args = elevate_pre_args + args
        return args

    def pretty_print_cmd(args):
        " Return pretty-printed version of the command. "
        if isinstance(args, list):
            return ' '.join(args)
        else:
            return "{sh}{cmd}".format(
                sh="$ " if kwargs.get('shell', False) else "",
                cmd=args.strip())

    from pybombs.config_manager import config_manager
    from pybombs.utils import output_proc
    _process_thread.result = 0
    extra_popen_args = {}
    use_oproc = False
    o_proc = kwargs.get('o_proc')
    if isinstance(o_proc, output_proc.OutputProcessor):
        use_oproc = True
        extra_popen_args = o_proc.extra_popen_args
    if kwargs.get('shell', False) and isinstance(args, list):
        args = ' '.join(args)
    if kwargs.get('elevate'):
        args = elevate_command(args, config_manager.get('elevate_pre_args'))
    log = logger.getChild("_process_thread()")
    cmd_pp = pretty_print_cmd(args)
    if kwargs.get('elevate'):
        log.info("Executing command with elevated privileges: `{cmd}'".format(
            cmd=cmd_pp))
    else:
        log.debug("Executing command `{cmd}'".format(cmd=cmd_pp))
    try:
        proc = subprocess.Popen(args,
                                shell=kwargs.get('shell', False),
                                env=kwargs.get(
                                    'env',
                                    config_manager.get_active_prefix().env),
                                **extra_popen_args)
    except OSError:
        log.error("Failure executing command `{cmd}'!".format(cmd=cmd_pp))
        if kwargs.get('elevate'):
            log.debug("Make sure command can be elevated using `{epa}' " \
                           "on this platform!".format(
                               epa=config_manager.get('elevate_pre_args')))
        return -1
    if use_oproc:
        ret_code = run_with_output_processing(proc, o_proc, event,
                                              kwargs.get('cleanup'))
    else:
        # Wait until the process is done, or monitor_process() sends us the
        # quit event
        ret_code = None
        while ret_code is None and not event.is_set():
            ret_code = proc.poll()
            event.wait(1)
            if event.is_set():
                kill_process_tree(proc)
                if kwargs.get('cleanup') is not None:
                    kwargs.get('cleanup')()
                break
    _process_thread.result = ret_code
    event.set()
    return ret_code