listdepends.py
changeset 31 c2e6e24b83d9
child 83 515fadd3d286
equal deleted inserted replaced
30:a8b7cd92f39f 31:c2e6e24b83d9
       
     1 #!/usr/bin/env python3.2
       
     2 
       
     3 from pgtoolkit import pgbrowser, toolbase, prettysize
       
     4 
       
     5 
       
     6 class ListDependsTool(toolbase.SimpleTool):
       
     7     def __init__(self):
       
     8         toolbase.SimpleTool.__init__(self, name='listdepends', desc='List column dependencies.')
       
     9         self.parser.add_argument('table', metavar='table', type=str, help='Table name.')
       
    10         self.parser.add_argument('column', metavar='column', type=str, help='Column name.')
       
    11         self.parser.add_argument('-s', '--schema', dest='schema', metavar='schema',
       
    12             type=str, default='public', help='Schema name (default=public).')
       
    13         self.init()
       
    14 
       
    15     def main(self):
       
    16         browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
       
    17 
       
    18         objects = browser.list_column_usage(self.args.table, self.args.column, schema=self.args.schema)
       
    19         for obj in sorted(objects, key=lambda x: (x['type'], x['schema'], x['name'])):
       
    20             print(obj['type'], ' ', obj['schema'], '.', obj['name'], sep='')
       
    21 
       
    22 
       
    23 tool = ListDependsTool()
       
    24 tool.main()
       
    25