# Path: treeCl/errors.py
# def filecheck(filename):
#     if not os.path.isfile(filename):
#         raise FileError(filename)
#     return filename
# 
# def directorycheck(directory):
#     if not os.path.isdir(directory):
#         raise DirectoryError(directory)
#     return directory


import bz2
import pickle
import glob
import gzip
import io
import os
import shutil
import tempfile
from subprocess import Popen, PIPE
from ..errors import filecheck, directorycheck
    def __exit__(self, type, value, tb):
        os.chdir(self._cdir)


def basename(filename):
    return os.path.basename(filename)


def can_locate(filename):
    return os.path.isfile(filename) if filename else False


def can_open(directory):
    return os.path.isdir(directory) if directory else False


def delete(filename):
    return os.remove(filecheck(filename))


def delete_if_exists(filename):
    if os.path.isfile(filename):
        os.remove(filename)
        return True
    return False


def freader(filename, gz=False, bz=False):
    """ Returns a filereader object that can handle gzipped input """


# Path: treeCl/errors.py
# def filecheck(filename):
#     if not os.path.isfile(filename):
#         raise FileError(filename)
#     return filename
# 
# def directorycheck(directory):
#     if not os.path.isdir(directory):
#         raise DirectoryError(directory)
#     return directory


# Path: treeCl/utils/fileIO.py
import bz2
import pickle
import glob
import gzip
import io
import os
import shutil
import tempfile
from subprocess import Popen, PIPE
from ..errors import filecheck, directorycheck

    def __exit__(self, type, value, tb):
        os.chdir(self._cdir)


def basename(filename):
    return os.path.basename(filename)


def can_locate(filename):
    return os.path.isfile(filename) if filename else False


def can_open(directory):
    return os.path.isdir(directory) if directory else False


def delete(filename):
    return os.remove(filecheck(filename))


def delete_if_exists(filename):
    if os.path.isfile(filename):
        os.remove(filename)
        return True
    return False


def freader(filename, gz=False, bz=False):
    """ Returns a filereader object that can handle gzipped input """


    filecheck(filename)