示例#1
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'):
        elevate_pre_args = config_manager.get('elevate_pre_args')
        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
    log = logger.getChild("_process_thread()")
    if isinstance(args, list):
        log.debug("Executing command `{cmd}'".format(cmd=' '.join(args)))
    else:
        log.debug("Executing command `{sh}{cmd}'".format(
            sh="$ " if kwargs.get('shell', False) else "", cmd=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
示例#2
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'):
        elevate_pre_args = config_manager.get('elevate_pre_args')
        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
    log = logger.getChild("_process_thread()")
    if isinstance(args, list):
        log.debug("Executing command `{cmd}'".format(cmd=' '.join(args)))
    else:
        log.debug("Executing command `{sh}{cmd}'".format(
            sh="$ " if kwargs.get('shell', False) else "",
            cmd=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
示例#3
0
def _process_thread(event, args, kwargs):
    """
    This actually runs the process.
    """
    _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(ELEVATE_PRE_ARGS) + args
        else:
            args = 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
示例#4
0
def _process_thread(event, args, kwargs):
    """
    This actually runs the process.
    """
    _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(ELEVATE_PRE_ARGS) + args
        else:
            args = 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
示例#5
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
示例#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)
    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