# Path: pybombs/pb_logging.py
# BOLD = str('\033[1m')
# TRACE = 1
# class ColoredConsoleHandler(logging.StreamHandler):
# class PBLogger(logging.getLoggerClass()):
#     def emit(self, record):
#     def __init__(self, *args, **kwargs):
#     def trace(self, *args, **kwargs):


import os
import re
import signal
import subprocess
import threading
    from Queue import Queue, Empty
    from queue import Queue, Empty  # Py3k
from pybombs.pb_logging import logger
from pybombs.pb_exception import PBException
    from pybombs.config_manager import config_manager
    from pybombs.utils import output_proc
            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

# args is not *args!
def monitor_process(args, **kwargs):
    """
    Run a process and monitor it. If it is cancelled, perform cleanup.

    Params:
    - args: Must be a list (e.g. ['ls', '-l'])
    - shell: If True, run in shell environment
    - throw: Throw a PBException if the process returns a non-zero return value
    - throw_ex: If True, propagate subprocess exceptions. If False, return -1
                on exceptions.
    - env: A dictionary with environment variables.
           Note: If None is provided, it will actually load the environment
           from the config manager.
    - o_proc: An output processor
    - cleanup: A callback to clean up artifacts if the process is killed
    - elevate: Run with elevated privileges (e.g., 'sudo <command>')

    Returns the process's return value.
    """

# Path: pybombs/pb_logging.py
# BOLD = str('\033[1m')
# TRACE = 1
# class ColoredConsoleHandler(logging.StreamHandler):
# class PBLogger(logging.getLoggerClass()):
#     def emit(self, record):
#     def __init__(self, *args, **kwargs):
#     def trace(self, *args, **kwargs):


# Path: pybombs/utils/subproc.py
import os
import re
import signal
import subprocess
import threading
    from Queue import Queue, Empty
    from queue import Queue, Empty  # Py3k
from pybombs.pb_logging import logger
from pybombs.pb_exception import PBException
    from pybombs.config_manager import config_manager
    from pybombs.utils import output_proc

            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

# args is not *args!
def monitor_process(args, **kwargs):
    """
    Run a process and monitor it. If it is cancelled, perform cleanup.

    Params:
    - args: Must be a list (e.g. ['ls', '-l'])
    - shell: If True, run in shell environment
    - throw: Throw a PBException if the process returns a non-zero return value
    - throw_ex: If True, propagate subprocess exceptions. If False, return -1
                on exceptions.
    - env: A dictionary with environment variables.
           Note: If None is provided, it will actually load the environment
           from the config manager.
    - o_proc: An output processor
    - cleanup: A callback to clean up artifacts if the process is killed
    - elevate: Run with elevated privileges (e.g., 'sudo <command>')

    Returns the process's return value.
    """

    log = logger.getChild("monitor_process()")