From d9e3d4c6f66634a32236b238ce04cefff17f79b1 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Mon, 7 May 2018 12:53:47 +0200 Subject: [PATCH] Inspect pytables files for getting tables info --- datasette_pytables/__init__.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/datasette_pytables/__init__.py b/datasette_pytables/__init__.py index a3b1844..8516315 100644 --- a/datasette_pytables/__init__.py +++ b/datasette_pytables/__init__.py @@ -1,3 +1,26 @@ +import tables + def inspect(path): "Open file and return tables info" - return [], [] + h5tables = {} + views = [] + h5file = tables.open_file(path) + + for table in filter(lambda node: not(isinstance(node, tables.group.Group)), h5file): + colnames = [] + if isinstance(table, tables.table.Table): + colnames = table.colnames + + h5tables[table._v_pathname] = { + 'name': table._v_pathname, + 'columns': colnames, + 'primary_keys': [], + 'count': table.nrows, + 'label_column': None, + 'hidden': False, + 'fts_table': None, + 'foreign_keys': {'incoming': [], 'outgoing': []}, + } + + h5file.close() + return h5tables, views -- 2.39.5