annotate lemuriformes/count.py @ 12:82cd4e0b66cf

csv2sql
author Jeff Hammel <k0scist@gmail.com>
date Sun, 10 Dec 2017 15:18:00 -0800
parents ad1bf59eedb0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 list SQL table counts
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 """
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 import sys
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 from .cli import ConfigurationParser
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 from .url2sql import url2sql
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 def main(args=sys.argv[1:]):
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 """CLI"""
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 # parse command line
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 parser = ConfigurationParser(description=__doc__)
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 parser.add_argument('connection',
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 type=url2sql,
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 help="URL of SQL connection")
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 options = parser.parse_args(args)
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 # display table counts
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 connection = options.connection
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 tables = connection.tables()
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 for table in tables:
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 count = connection.count(table)
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 print ("{},{}".format(table, count))
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 if __name__ == '__main__':
ad1bf59eedb0 [SQL] add count CLI front-end
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 main()