# 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
    'can_open',
    'delete',
    'gpickle',
    'gunpickle',
    'join_path',
    'locate_by_dir',
    'locate_by_env',
    'locate_file',
    'path_to',
    'strip_extensions',
    'subprocess',
    'syscall',
    'verify',
]


class TempFile(object):

    def __init__(self, dir_=None, disable_delete=False):
        self.disable_delete = disable_delete
        if dir_ is not None and not os.path.exists(dir_):
            raise IOError('Directory "{}" does not exist'.format(dir_))
        self.dir = dir_

    def __enter__(self):
        self._fd, self._wrapped_tmp = tempfile.mkstemp(dir=self.dir)
        return os.path.abspath(self._wrapped_tmp)

    def __exit__(self, type, value, tb):
        # Always close the file, but only delete if disable_delete option allows it

# 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

    'can_open',
    'delete',
    'gpickle',
    'gunpickle',
    'join_path',
    'locate_by_dir',
    'locate_by_env',
    'locate_file',
    'path_to',
    'strip_extensions',
    'subprocess',
    'syscall',
    'verify',
]


class TempFile(object):

    def __init__(self, dir_=None, disable_delete=False):
        self.disable_delete = disable_delete
        if dir_ is not None and not os.path.exists(dir_):
            raise IOError('Directory "{}" does not exist'.format(dir_))
        self.dir = dir_

    def __enter__(self):
        self._fd, self._wrapped_tmp = tempfile.mkstemp(dir=self.dir)
        return os.path.abspath(self._wrapped_tmp)

    def __exit__(self, type, value, tb):
        # Always close the file, but only delete if disable_delete option allows it

        os.close(self._fd)