# Path: trtools/io/filecache.py
# class FileCache(object):
# class MetaFileCache(FileCache):
# class LeveledFileCache(FileCache):
#     def __init__(self, cache_dir, filename_func=None, *args, **kwargs):
#     def create_dir(dir):
#     def cache_dir_check(self):
#     def get_filename(self, name):
#     def put(self, name, obj):
#     def get(self, name):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __contains__(self, key):
#     def __len__(self):
#     def __repr__(self):
#     def keys(self):
#     def remove(self, name):
#     def __getstate__(self): return self.__dict__
#     def __setstate__(self, d): self.__dict__.update(d)
#     def __init__(self, *args, **kwargs):
#     def get_filename(self, key, leveled=None):
#     def save_keys(self):
#     def add_key(self, key, filename=None):
#     def remove_key(self, key):
#     def keys(self):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __contains__(self, key):
# def leveled_key_dir(key, leveled):
# def leveled_filename(fc, name, length=1):
#     def __init__(self, cache_dir, length=1, *args, **kwargs):
#     def get_filename(self, name):
#     def keys(self):
# def move_to_new_store(new_store, old_store):
#     def move_file(ps):
# 
# Path: trtools/io/hdf5_grouping.py
# class HDFPanel(object):
#     """
#         Kind of like HDFStore but restricts it to a group of 
#         similar DataFrames. Like panel except not sharing index
#     """
#     def __init__(self, filepath, mode='a'):
#         self.handle = None
#         self.filepath = filepath
#         self.mode = mode
#         self.handle = self.open(self.mode)
# 
#     def __getattr__(self, key):
#         if hasattr(self.handle, key):
#             return getattr(self.handle, key)
#         raise AttributeError()
# 
#     def reopen(self):
#         self.handle = self.open(self.mode)
# 
#     def open(self, mode="a", warn=True):
#         self.close()
#         return openFile(self.filepath, mode)
# 
#     def close(self):
#         if self.handle is not None and self.handle.isopen:
#             self.handle.close()
# 
#     def keys(self):
#         return self.groups()
# 
#     def groups(self):
#         handle = self.handle
#         nodes = handle.root._f_listNodes()
#         return [node._v_name for node in nodes]
# 
#     def get_group(self, group, *args, **kwargs):
#         handle = self.handle
#         group = handle.root._f_getChild(group)
# 
#         meta = _meta(group)
#         old_meta = meta.copy()
#         meta.update(kwargs)
# 
#         group_type = meta.setdefault('group_type', 'panel')
# 
#         # update meta if we're overidding here. probably better way to do this
#         if old_meta != meta:
#             _meta(group, meta)
# 
#         klass = HDFPanelGroup
#         if group_type == 'obt':
#             klass = OBTGroup
#         return klass(group, self, **meta)
# 
#     def __getitem__(self, key):
#         return self.get_group(key)
# 
#     def create_group(self, group_name, filters=None):
#         """
#             Create HDFPanelGroup
#         """
#         handle = self.handle    
#         group = handle.createGroup(handle.root, group_name, group_name, filters=filters)
# 
#         meta = {}
#         meta['group_type'] = 'panel'
# 
#         _meta(group, meta)
# 
#         return HDFPanelGroup(group, self, filters=filters)
# 
#     def create_obt(self, group_name, frame_key=None, table_name=None, filters=None,
#                   expectedrows=None):
#         """
#             Create OBTGroup
#         """
#         handle = self.handle    
#         group = handle.createGroup(handle.root, group_name, group_name)
# 
#         frame_key = frame_key or 'frame_key'
#         table_name = table_name or group._v_name
# 
#         meta = {}
#         meta['frame_key'] = frame_key
#         meta['table_name'] = table_name
#         meta['group_type'] = 'obt'
#         meta['expectedrows'] = expectedrows
# 
#         _meta(group, meta)
# 
#         return OBTGroup(group, self, filters=filters, **meta)


import os.path
import glob
from trtools.io.filecache import FileCache, _filename, leveled_filename
from trtools.io.hdf5_grouping import HDFPanel
        return df

class HDF5FileCache(FileCache):
    def __init__(self, cache_dir, filename_func=None, filters=None, *args, **kwargs):
        self.filters = filters
        super(HDF5FileCache, self).__init__(cache_dir, filename_func, *args, **kwargs)

    def get_filename(self, name):
        name = _filename(name) + '.h5'
        filename = os.path.join(self.cache_dir, name)
        return filename

    def put(self, name, obj):
        filename = self.get_filename(name)
        SingleHDF.put(filename, obj, filters=self.filters)

    def get(self, name):
        filename = self.get_filename(name)
        return SingleHDF.get(filename)

    def keys(self):
        keys = list(super(HDF5FileCache, self).keys())
        return [filename[:-3] for filename in keys]

class HDF5LeveledFileCache(HDF5FileCache):
    def __init__(self, cache_dir, length=1, *args, **kwargs):
        self.length = length
        super(HDF5LeveledFileCache, self).__init__(cache_dir, *args, **kwargs) 

    def get_filename(self, name):

# Path: trtools/io/filecache.py
# class FileCache(object):
# class MetaFileCache(FileCache):
# class LeveledFileCache(FileCache):
#     def __init__(self, cache_dir, filename_func=None, *args, **kwargs):
#     def create_dir(dir):
#     def cache_dir_check(self):
#     def get_filename(self, name):
#     def put(self, name, obj):
#     def get(self, name):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __contains__(self, key):
#     def __len__(self):
#     def __repr__(self):
#     def keys(self):
#     def remove(self, name):
#     def __getstate__(self): return self.__dict__
#     def __setstate__(self, d): self.__dict__.update(d)
#     def __init__(self, *args, **kwargs):
#     def get_filename(self, key, leveled=None):
#     def save_keys(self):
#     def add_key(self, key, filename=None):
#     def remove_key(self, key):
#     def keys(self):
#     def __getitem__(self, key):
#     def __setitem__(self, key, value):
#     def __contains__(self, key):
# def leveled_key_dir(key, leveled):
# def leveled_filename(fc, name, length=1):
#     def __init__(self, cache_dir, length=1, *args, **kwargs):
#     def get_filename(self, name):
#     def keys(self):
# def move_to_new_store(new_store, old_store):
#     def move_file(ps):
# 
# Path: trtools/io/hdf5_grouping.py
# class HDFPanel(object):
#     """
#         Kind of like HDFStore but restricts it to a group of 
#         similar DataFrames. Like panel except not sharing index
#     """
#     def __init__(self, filepath, mode='a'):
#         self.handle = None
#         self.filepath = filepath
#         self.mode = mode
#         self.handle = self.open(self.mode)
# 
#     def __getattr__(self, key):
#         if hasattr(self.handle, key):
#             return getattr(self.handle, key)
#         raise AttributeError()
# 
#     def reopen(self):
#         self.handle = self.open(self.mode)
# 
#     def open(self, mode="a", warn=True):
#         self.close()
#         return openFile(self.filepath, mode)
# 
#     def close(self):
#         if self.handle is not None and self.handle.isopen:
#             self.handle.close()
# 
#     def keys(self):
#         return self.groups()
# 
#     def groups(self):
#         handle = self.handle
#         nodes = handle.root._f_listNodes()
#         return [node._v_name for node in nodes]
# 
#     def get_group(self, group, *args, **kwargs):
#         handle = self.handle
#         group = handle.root._f_getChild(group)
# 
#         meta = _meta(group)
#         old_meta = meta.copy()
#         meta.update(kwargs)
# 
#         group_type = meta.setdefault('group_type', 'panel')
# 
#         # update meta if we're overidding here. probably better way to do this
#         if old_meta != meta:
#             _meta(group, meta)
# 
#         klass = HDFPanelGroup
#         if group_type == 'obt':
#             klass = OBTGroup
#         return klass(group, self, **meta)
# 
#     def __getitem__(self, key):
#         return self.get_group(key)
# 
#     def create_group(self, group_name, filters=None):
#         """
#             Create HDFPanelGroup
#         """
#         handle = self.handle    
#         group = handle.createGroup(handle.root, group_name, group_name, filters=filters)
# 
#         meta = {}
#         meta['group_type'] = 'panel'
# 
#         _meta(group, meta)
# 
#         return HDFPanelGroup(group, self, filters=filters)
# 
#     def create_obt(self, group_name, frame_key=None, table_name=None, filters=None,
#                   expectedrows=None):
#         """
#             Create OBTGroup
#         """
#         handle = self.handle    
#         group = handle.createGroup(handle.root, group_name, group_name)
# 
#         frame_key = frame_key or 'frame_key'
#         table_name = table_name or group._v_name
# 
#         meta = {}
#         meta['frame_key'] = frame_key
#         meta['table_name'] = table_name
#         meta['group_type'] = 'obt'
#         meta['expectedrows'] = expectedrows
# 
#         _meta(group, meta)
# 
#         return OBTGroup(group, self, filters=filters, **meta)


# Path: trtools/io/hdf5_filecache.py
import os.path
import glob
from trtools.io.filecache import FileCache, _filename, leveled_filename
from trtools.io.hdf5_grouping import HDFPanel

        return df

class HDF5FileCache(FileCache):
    def __init__(self, cache_dir, filename_func=None, filters=None, *args, **kwargs):
        self.filters = filters
        super(HDF5FileCache, self).__init__(cache_dir, filename_func, *args, **kwargs)

    def get_filename(self, name):
        name = _filename(name) + '.h5'
        filename = os.path.join(self.cache_dir, name)
        return filename

    def put(self, name, obj):
        filename = self.get_filename(name)
        SingleHDF.put(filename, obj, filters=self.filters)

    def get(self, name):
        filename = self.get_filename(name)
        return SingleHDF.get(filename)

    def keys(self):
        keys = list(super(HDF5FileCache, self).keys())
        return [filename[:-3] for filename in keys]

class HDF5LeveledFileCache(HDF5FileCache):
    def __init__(self, cache_dir, length=1, *args, **kwargs):
        self.length = length
        super(HDF5LeveledFileCache, self).__init__(cache_dir, *args, **kwargs) 

    def get_filename(self, name):

        filename = leveled_filename(fc=self, name=name, length=self.length)