# Path: bipy/utils.py
# def which(program):
#     """ returns the path to an executable"""
# 
#     def is_exe(fpath):
#         return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
# 
#     fpath, fname = os.path.split(program)
#     if fpath:
#         if is_exe(program):
#             return program
#     else:
#         for path in os.environ["PATH"].split(os.pathsep):
#             exe_file = os.path.join(path, program)
#             if is_exe(exe_file):
#                 return exe_file
# 
#     return None


import unittest
import yaml
import logging
import os
from bcbio.utils import file_exists
from bipy.utils import which
        program_ok = self.check_program(config)
        return program_ok

    def check_exists(self, field, config):
        filename = config.get(field, None)
        if not filename:
            self._field_missing_warning(field)
            return True
        elif file_exists(filename):
            logger.info("%s location: %s" % (field, filename))
            return True
        else:
            logger.error("%s: %s was not found." % (field, filename))
            return False

    def check_program(self, config):
        need_dirs = ["picard"]
        programs = config.get("program", None)
        if not programs:
            self._field_missing_warning("program")
            return True

        for program, loc in programs.items():
            if program in need_dirs:
                if os.path.isdir(loc):
                    logger.info("%s lives in %s." % (program, loc))
                else:
                    self._directory_missing_error(program, loc)
                    return False
            else:

# Path: bipy/utils.py
# def which(program):
#     """ returns the path to an executable"""
# 
#     def is_exe(fpath):
#         return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
# 
#     fpath, fname = os.path.split(program)
#     if fpath:
#         if is_exe(program):
#             return program
#     else:
#         for path in os.environ["PATH"].split(os.pathsep):
#             exe_file = os.path.join(path, program)
#             if is_exe(exe_file):
#                 return exe_file
# 
#     return None


# Path: test/config/test_config.py
import unittest
import yaml
import logging
import os
from bcbio.utils import file_exists
from bipy.utils import which

        program_ok = self.check_program(config)
        return program_ok

    def check_exists(self, field, config):
        filename = config.get(field, None)
        if not filename:
            self._field_missing_warning(field)
            return True
        elif file_exists(filename):
            logger.info("%s location: %s" % (field, filename))
            return True
        else:
            logger.error("%s: %s was not found." % (field, filename))
            return False

    def check_program(self, config):
        need_dirs = ["picard"]
        programs = config.get("program", None)
        if not programs:
            self._field_missing_warning("program")
            return True

        for program, loc in programs.items():
            if program in need_dirs:
                if os.path.isdir(loc):
                    logger.info("%s lives in %s." % (program, loc))
                else:
                    self._directory_missing_error(program, loc)
                    return False
            else:

                if which(loc):