# -*- coding: utf-8 -*-

# Copyright (c) 2018 shmilee

'''
'''

import os

from ..glogger import getGLogger

__all__ = ['get_pcksaver']
log = getGLogger('S')
pcksaver_names = ['CachePckSaver', 'NpzPckSaver', 'Hdf5PckSaver']
pcksaver_types = ['.cache', '.npz', '.hdf5']


def get_pcksaver(path):
    '''
    Given a saver path, return a saver instance.
    Raises ValueError if path type not supported.

    Notes
    -----
    *path* types:
    1. '.cache', dict cache name
    2. '.npz', file path
    3. '.hdf5', file path
    '''
    path = str(path)
    ext = os.path.splitext(path)[1]
    if ext not in pcksaver_types:
        log.warn("PckSaver type must be in '%s'! Use default '.npz'."
                 % ', '.join(pcksaver_types))
        ext = '.npz'
        path = path + ext

    if ext == '.cache':
        from .cachepck import CachePckSaver
        saver = CachePckSaver(path)
    elif ext == '.npz':
        from .npzpck import NpzPckSaver
        saver = NpzPckSaver(path)
    elif ext == '.hdf5':
        from .hdf5pck import Hdf5PckSaver
        saver = Hdf5PckSaver(path)
    else:
        raise ValueError('Save ha? Who am I? Why am I here?')
    return saver

@@ -52,16 +52,332 @@
 ee%0A%0A'''%0A
+This is the subpackage %60%60savers%60%60 of gdpy3.%0A%60%60PckSaver%60%60, get by :func:%60get_pcksaver%60, has attributes%0A:attr:%60base.BasePckSaver.path%60%60,%0A:attr:%60base.BasePckSaver.status%60%0Aand methods%0A:meth:%60base.BasePckSaver.iopen%60,%0A:meth:%60base.BasePckSaver.write%60,%0A:meth:%60base.BasePckSaver.close%60,%0A:meth:%60base.BasePckSaver.get_store%60.%0A
 '''%0A%0Aimp

add savers __doc__