# Path: liam2/data.py
# def copy_table(input_table, output_node, output_dtype=None,
#                chunksize=10000, condition=None, stop=None, show_progress=False,
#                default_values=None, **kwargs):
#     complete_kwargs = {'title': input_table._v_title}
# #                       'filters': input_table.filters}
#     output_file = output_node._v_file
#     complete_kwargs.update(kwargs)
#     if output_dtype is None:
#         output_dtype = input_table.dtype
#     output_table = output_file.create_table(output_node, input_table.name,
#                                             output_dtype, **complete_kwargs)
#     return append_table(input_table, output_table, chunksize, condition,
#                         stop=stop, show_progress=show_progress,
#                         default_values=default_values)
# 
# Path: liam2/utils.py
# def timed(func, *args, **kwargs):
#     elapsed, res = gettime(func, *args, **kwargs)
#     if config.show_timings:
#         print("done (%s elapsed)." % time2str(elapsed))
#     else:
#         print("done.")
#     return res


import tables
    import sys
    import platform
from liam2.data import copy_table
from liam2.utils import timed

__version__ = "0.4"


def filter_h5(input_path, output_path, condition, copy_globals=True):
    print("filtering for '%s'" % condition)
    input_file = tables.open_file(input_path)
    output_file = tables.open_file(output_path, mode="w")

    # copy globals
    if copy_globals:
        # noinspection PyProtectedMember
        input_file.root.globals._f_copy(output_file.root, recursive=True)

    output_entities = output_file.create_group("/", "entities", "Entities")
    for table in input_file.iterNodes(input_file.root.entities):
        # noinspection PyProtectedMember
        print(table._v_name, "...")
        copy_table(table, output_entities, condition=condition)

    input_file.close()
    output_file.close()


if __name__ == '__main__':

    print("LIAM HDF5 filter %s using Python %s (%s)\n" %
          (__version__, platform.python_version(), platform.architecture()[0]))

    args = dict(enumerate(sys.argv))
    if len(args) < 4:

# Path: liam2/data.py
# def copy_table(input_table, output_node, output_dtype=None,
#                chunksize=10000, condition=None, stop=None, show_progress=False,
#                default_values=None, **kwargs):
#     complete_kwargs = {'title': input_table._v_title}
# #                       'filters': input_table.filters}
#     output_file = output_node._v_file
#     complete_kwargs.update(kwargs)
#     if output_dtype is None:
#         output_dtype = input_table.dtype
#     output_table = output_file.create_table(output_node, input_table.name,
#                                             output_dtype, **complete_kwargs)
#     return append_table(input_table, output_table, chunksize, condition,
#                         stop=stop, show_progress=show_progress,
#                         default_values=default_values)
# 
# Path: liam2/utils.py
# def timed(func, *args, **kwargs):
#     elapsed, res = gettime(func, *args, **kwargs)
#     if config.show_timings:
#         print("done (%s elapsed)." % time2str(elapsed))
#     else:
#         print("done.")
#     return res


# Path: liam2/filter_h5.py
import tables
    import sys
    import platform
from liam2.data import copy_table
from liam2.utils import timed

__version__ = "0.4"


def filter_h5(input_path, output_path, condition, copy_globals=True):
    print("filtering for '%s'" % condition)
    input_file = tables.open_file(input_path)
    output_file = tables.open_file(output_path, mode="w")

    # copy globals
    if copy_globals:
        # noinspection PyProtectedMember
        input_file.root.globals._f_copy(output_file.root, recursive=True)

    output_entities = output_file.create_group("/", "entities", "Entities")
    for table in input_file.iterNodes(input_file.root.entities):
        # noinspection PyProtectedMember
        print(table._v_name, "...")
        copy_table(table, output_entities, condition=condition)

    input_file.close()
    output_file.close()


if __name__ == '__main__':

    print("LIAM HDF5 filter %s using Python %s (%s)\n" %
          (__version__, platform.python_version(), platform.architecture()[0]))

    args = dict(enumerate(sys.argv))
    if len(args) < 4:

        print("""Usage: {} inputpath outputpath condition [copy_globals]
