author | Radek Brich <radek.brich@devl.cz> |
Fri, 04 Oct 2013 16:38:24 +0200 | |
changeset 90 | 43e5d2cf4ddb |
parent 83 | 515fadd3d286 |
child 93 | b72591087495 |
permissions | -rwxr-xr-x |
2 | 1 |
#!/usr/bin/env python3.2 |
2 |
||
83
515fadd3d286
Add dependency on pycolib. Move common modules to pycolib. Add example table schema for meta DB.
Radek Brich <radek.brich@devl.cz>
parents:
68
diff
changeset
|
3 |
from pgtoolkit import pgbrowser, toolbase |
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 |