pgtoolkit/toolbase.py
changeset 31 c2e6e24b83d9
parent 30 a8b7cd92f39f
child 34 98c7809af415
equal deleted inserted replaced
30:a8b7cd92f39f 31:c2e6e24b83d9
    22         self.config.add_argument('meta_query')
    22         self.config.add_argument('meta_query')
    23         
    23         
    24         self.pgm = pgmanager.get_instance()
    24         self.pgm = pgmanager.get_instance()
    25         self.target_isolation_level = None
    25         self.target_isolation_level = None
    26         
    26         
    27     def init(self, *args):
    27     def init(self):
    28         self.config.load('pgtoolkit.conf')
    28         self.config.load('pgtoolkit.conf')
    29         self.args = self.parser.parse_args()
    29         self.args = self.parser.parse_args()
    30         self.init_logging()
    30         self.init_logging()
    31         self.prepare_conns(*args)
       
    32     
    31     
    33     def init_logging(self):
    32     def init_logging(self):
    34         # logging
    33         # logging
    35         handler = logging.StreamHandler()
    34         handler = logging.StreamHandler()
    36         format = ColoredFormatter(highlight(1,7,0)+'%(asctime)s %(levelname)-5s'+highlight(0)+' %(message)s', '%H:%M:%S')
    35         format = ColoredFormatter(highlight(1,7,0)+'%(asctime)s %(levelname)-5s'+highlight(0)+' %(message)s', '%H:%M:%S')
    73                 self.pgm.create_conn(name=name,
    72                 self.pgm.create_conn(name=name,
    74                     isolation_level=self.target_isolation_level,
    73                     isolation_level=self.target_isolation_level,
    75                     dsn=dsn)
    74                     dsn=dsn)
    76                 return True
    75                 return True
    77 
    76 
    78     def prepare_conns(self, *pgm_names):
    77     def prepare_conns_from_cmdline_args(self, *pgm_names):
    79         if self.config.meta_db:
    78         if self.config.meta_db:
    80             self.pgm.create_conn(name='meta', dsn=self.config.meta_db)
    79             self.pgm.create_conn(name='meta', dsn=self.config.meta_db)
    81         
    80         
    82         for name in pgm_names:
    81         for name in pgm_names:
    83             lookup_name = self.args.__dict__[name]
    82             lookup_name = self.args.__dict__[name]
    95     def __init__(self, name, desc):
    94     def __init__(self, name, desc):
    96         ToolBase.__init__(self, name, desc)        
    95         ToolBase.__init__(self, name, desc)        
    97         self.parser.add_argument('target', metavar='target', type=str, help='Target database')
    96         self.parser.add_argument('target', metavar='target', type=str, help='Target database')
    98       
    97       
    99     def init(self):
    98     def init(self):
   100         ToolBase.init(self, 'target')
    99         ToolBase.init(self)
       
   100         self.prepare_conns_from_cmdline_args('target')
   101 
   101 
   102 
   102 
   103 class SrcDstTool(ToolBase):
   103 class SrcDstTool(ToolBase):
   104     def __init__(self, name, desc):
   104     def __init__(self, name, desc):
   105         ToolBase.__init__(self, name, desc)        
   105         ToolBase.__init__(self, name, desc)        
   106         self.parser.add_argument('src', metavar='source', type=str, help='Source database')
   106         self.parser.add_argument('src', metavar='source', type=str, help='Source database')
   107         self.parser.add_argument('dst', metavar='destination', type=str, help='Destination database')
   107         self.parser.add_argument('dst', metavar='destination', type=str, help='Destination database')
   108       
   108       
   109     def init(self):
   109     def init(self):
   110         ToolBase.init(self, 'src', 'dst')
   110         ToolBase.init(self)
       
   111         self.prepare_conns_from_cmdline_args('src', 'dst')
   111 
   112