author | Radek Brich <brich.radek@ifortuna.cz> |
Wed, 07 May 2014 18:33:50 +0200 | |
changeset 102 | fda45bdfd68d |
parent 101 | 2a2d0d5df03b |
child 104 | d8ff52a0390f |
permissions | -rwxr-xr-x |
93
b72591087495
Change python3.2 to python3 in scripts.
Radek Brich <brich.radek@ifortuna.cz>
parents:
83
diff
changeset
|
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 |
|
11 |
def main(self): |
|
12 |
browser = pgbrowser.PgBrowser(self.pgm.get_conn('target')) |
|
13 |
||
38
d3593869d624
Update bigtables tool: scan all schemas.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
14 |
# scan all tables from all shemas, remember names and sizes |
68 | 15 |
tables = [] |
16 |
for schema in browser.schemas.values(): |
|
17 |
for table in schema.tables.values(): |
|
18 |
for option in self.args.options: |
|
19 |
if option in table.options: |
|
20 |
tables.append(table) |
|
21 |
||
22 |
# print result |
|
23 |
if len(tables): |
|
24 |
print('Found %d tables:' % len(tables)) |
|
25 |
else: |
|
26 |
print('No table meets the conditions.') |
|
27 |
for table in tables: |
|
28 |
table_name = '%s.%s' % (table.schema.name, table.name) |
|
29 |
print(' ', table_name) |
|
2 | 30 |
|
31 |
||
68 | 32 |
tool = ListTablesTool() |
101
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
Radek Brich <brich.radek@ifortuna.cz>
parents:
93
diff
changeset
|
33 |
tool.setup() |
2 | 34 |
tool.main() |
35 |