]> git.jsancho.org Git - datasette-pytables.git/commitdiff
Inspect pytables files for getting tables info
authorJavier Sancho <jsf@jsancho.org>
Mon, 7 May 2018 10:53:47 +0000 (12:53 +0200)
committerJavier Sancho <jsf@jsancho.org>
Mon, 7 May 2018 10:53:47 +0000 (12:53 +0200)
datasette_pytables/__init__.py

index a3b1844af528e46abbfef28644687b33477ea8af..8516315cd49bbf4bf4507590d3e47e5a4878a1b1 100644 (file)
@@ -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