# Path: pybar/utils/utils.py
# def find_file_dir_up(filename, path=None, n=None):
#     '''Finding file in directory upwards.
#     '''
#     if path is None:
#         path = os.getcwd()
#     i = 0
#     while True:
#         current_path = path
#         for _ in range(i):
#             current_path = os.path.split(current_path)[0]
#         if os.path.isfile(os.path.join(current_path, filename)):  # found file and return
#             return os.path.join(current_path, filename)
#         elif os.path.dirname(current_path) == current_path:  # root of filesystem
#             return
#         elif n is not None and i == n:
#             return
#         else:  # file not found
#             i += 1
#             continue


import logging
import datetime
import os
import re
import sys
import functools
import traceback
import signal
import abc
            import thread
            import win32api
from collections import namedtuple
from threading import Lock, Thread, Event, current_thread, _MainThread
from contextlib import contextmanager
from importlib import import_module
from inspect import getmembers, isclass, getargspec
from functools import partial
from ast import literal_eval
from time import time
from functools import wraps
from yaml import safe_load
from pybar.utils.utils import find_file_dir_up
            Configuration for the run(s). Configuration will be passed to all scans.
        '''
        # fixing event handler: http://stackoverflow.com/questions/15457786/ctrl-c-crashes-python-after-importing-scipy-stats
        if os.name == 'nt':

            def handler(signum, hook=thread.interrupt_main):
                hook()
                return True

            win32api.SetConsoleCtrlHandler(handler, 1)

        self._conf = None  # configuration dictionary
        self.current_run = None  # current run number
        self._conf_path = None  # absolute path of the configuation file
        self.init(conf)

    @property
    def conf(self):
        '''Configuration (namedtuple)
        '''
        conf = namedtuple('conf', field_names=self._conf.keys())
        return conf(**self._conf)  # prevent changing dict

    def init(self, conf):
        # current working directory
        if isinstance(conf, basestring) and os.path.isfile(os.path.abspath(conf)):
            conf = os.path.abspath(conf)
            self._conf_path = conf
        # search directory upwards form current working directory
        elif isinstance(conf, basestring) and find_file_dir_up(conf):

# Path: pybar/utils/utils.py
# def find_file_dir_up(filename, path=None, n=None):
#     '''Finding file in directory upwards.
#     '''
#     if path is None:
#         path = os.getcwd()
#     i = 0
#     while True:
#         current_path = path
#         for _ in range(i):
#             current_path = os.path.split(current_path)[0]
#         if os.path.isfile(os.path.join(current_path, filename)):  # found file and return
#             return os.path.join(current_path, filename)
#         elif os.path.dirname(current_path) == current_path:  # root of filesystem
#             return
#         elif n is not None and i == n:
#             return
#         else:  # file not found
#             i += 1
#             continue


# Path: pybar/run_manager.py
import logging
import datetime
import os
import re
import sys
import functools
import traceback
import signal
import abc
            import thread
            import win32api
from collections import namedtuple
from threading import Lock, Thread, Event, current_thread, _MainThread
from contextlib import contextmanager
from importlib import import_module
from inspect import getmembers, isclass, getargspec
from functools import partial
from ast import literal_eval
from time import time
from functools import wraps
from yaml import safe_load
from pybar.utils.utils import find_file_dir_up

            Configuration for the run(s). Configuration will be passed to all scans.
        '''
        # fixing event handler: http://stackoverflow.com/questions/15457786/ctrl-c-crashes-python-after-importing-scipy-stats
        if os.name == 'nt':

            def handler(signum, hook=thread.interrupt_main):
                hook()
                return True

            win32api.SetConsoleCtrlHandler(handler, 1)

        self._conf = None  # configuration dictionary
        self.current_run = None  # current run number
        self._conf_path = None  # absolute path of the configuation file
        self.init(conf)

    @property
    def conf(self):
        '''Configuration (namedtuple)
        '''
        conf = namedtuple('conf', field_names=self._conf.keys())
        return conf(**self._conf)  # prevent changing dict

    def init(self, conf):
        # current working directory
        if isinstance(conf, basestring) and os.path.isfile(os.path.abspath(conf)):
            conf = os.path.abspath(conf)
            self._conf_path = conf
        # search directory upwards form current working directory
        elif isinstance(conf, basestring) and find_file_dir_up(conf):

            conf = find_file_dir_up(conf)