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