author | Radek Brich <radek.brich@devl.cz> |
Mon, 04 Mar 2013 15:39:34 +0100 | |
changeset 70 | 77e65040711c |
parent 68 | b0d972be2631 |
child 83 | 515fadd3d286 |
permissions | -rwxr-xr-x |
2 | 1 |
#!/usr/bin/env python3.2 |
2 |
||
9
2fcc8ef0b97d
Reorganize again :-) Add setup.py.
Radek Brich <radek.brich@devl.cz>
parents:
7
diff
changeset
|
3 |
from pgtoolkit import pgbrowser, toolbase, prettysize |
2 | 4 |
|
5 |
||
68 | 6 |
class ListTablesTool(toolbase.SimpleTool): |
2 | 7 |
def __init__(self): |
68 | 8 |
toolbase.SimpleTool.__init__(self, name='listtables', desc='List tables in database.') |
9 |
self.parser.add_argument('-o', dest='options', type=str, nargs='*', help='Filter by options (eg. -o autovacuum_enabled=false).') |
|
2 | 10 |
self.init() |
11 |
||
12 |
def main(self): |
|
13 |
browser = pgbrowser.PgBrowser(self.pgm.get_conn('target')) |
|
14 |
||
38
d3593869d624
Update bigtables tool: scan all schemas.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
15 |
# scan all tables from all shemas, remember names and sizes |
68 | 16 |
tables = [] |
17 |
for schema in browser.schemas.values(): |
|
18 |
for table in schema.tables.values(): |
|
19 |
for option in self.args.options: |
|
20 |
if option in table.options: |
|
21 |
tables.append(table) |
|
22 |
||
23 |
# print result |
|
24 |
if len(tables): |
|
25 |
print('Found %d tables:' % len(tables)) |
|
26 |
else: |
|
27 |
print('No table meets the conditions.') |
|
28 |
for table in tables: |
|
29 |
table_name = '%s.%s' % (table.schema.name, table.name) |
|
30 |
print(' ', table_name) |
|
2 | 31 |
|
32 |
||
68 | 33 |
tool = ListTablesTool() |
2 | 34 |
tool.main() |
35 |