diff lemuriformes/count.py @ 10:ad1bf59eedb0

[SQL] add count CLI front-end
author Jeff Hammel <k0scist@gmail.com>
date Sun, 10 Dec 2017 13:57:33 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lemuriformes/count.py	Sun Dec 10 13:57:33 2017 -0800
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+"""
+list SQL table counts
+"""
+
+import sys
+from .cli import ConfigurationParser
+from .url2sql import url2sql
+
+
+def main(args=sys.argv[1:]):
+    """CLI"""
+
+    # parse command line
+    parser = ConfigurationParser(description=__doc__)
+    parser.add_argument('connection',
+                        type=url2sql,
+                        help="URL of SQL connection")
+    options = parser.parse_args(args)
+
+    # display table counts
+    connection = options.connection
+    tables = connection.tables()
+    for table in tables:
+        count = connection.count(table)
+        print ("{},{}".format(table, count))
+
+
+if __name__ == '__main__':
+    main()