]> git.jsancho.org Git - datasette-pytables.git/blob - datasette_pytables/__init__.py
8516315cd49bbf4bf4507590d3e47e5a4878a1b1
[datasette-pytables.git] / datasette_pytables / __init__.py
1 import tables
2
3 def inspect(path):
4     "Open file and return tables info"
5     h5tables = {}
6     views = []
7     h5file = tables.open_file(path)
8
9     for table in filter(lambda node: not(isinstance(node, tables.group.Group)), h5file):
10         colnames = []
11         if isinstance(table, tables.table.Table):
12             colnames = table.colnames
13
14         h5tables[table._v_pathname] = {
15             'name': table._v_pathname,
16             'columns': colnames,
17             'primary_keys': [],
18             'count': table.nrows,
19             'label_column': None,
20             'hidden': False,
21             'fts_table': None,
22             'foreign_keys': {'incoming': [], 'outgoing': []},
23         }
24
25     h5file.close()
26     return h5tables, views