pgtoolkit/toolbase.py
changeset 30 a8b7cd92f39f
parent 29 8636719a30f6
child 31 c2e6e24b83d9
equal deleted inserted replaced
29:8636719a30f6 30:a8b7cd92f39f
    20         self.config.add_argument('databases', type=dict)
    20         self.config.add_argument('databases', type=dict)
    21         self.config.add_argument('meta_db')
    21         self.config.add_argument('meta_db')
    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         
    26         
    26     def init(self, *args):
    27     def init(self, *args):
    27         self.config.load('pgtoolkit.conf')
    28         self.config.load('pgtoolkit.conf')
    28         self.args = self.parser.parse_args()
    29         self.args = self.parser.parse_args()
    29         self.init_logging()
    30         self.init_logging()
    57         with self.pgm.cursor('meta') as curs:
    58         with self.pgm.cursor('meta') as curs:
    58             curs.execute(self.config.meta_query, [lookup_name])
    59             curs.execute(self.config.meta_query, [lookup_name])
    59             row = curs.fetchone_dict()
    60             row = curs.fetchone_dict()
    60             curs.connection.commit()
    61             curs.connection.commit()
    61             if row:
    62             if row:
    62                 self.pgm.create_conn(name=name, **row)
    63                 self.pgm.create_conn(name=name,
       
    64                     isolation_level=self.target_isolation_level,
       
    65                     **row)
    63                 return True
    66                 return True
    64 
    67 
    65     def prepare_conn_from_config(self, name, lookup_name):
    68     def prepare_conn_from_config(self, name, lookup_name):
    66         '''Create connection in pgmanager using info in config.databases.'''
    69         '''Create connection in pgmanager using info in config.databases.'''
    67         if self.config.databases:
    70         if self.config.databases:
    68             if lookup_name in self.config.databases:
    71             if lookup_name in self.config.databases:
    69                 dsn = self.config.databases[lookup_name]
    72                 dsn = self.config.databases[lookup_name]
    70                 self.pgm.create_conn(name=name, dsn=dsn)
    73                 self.pgm.create_conn(name=name,
       
    74                     isolation_level=self.target_isolation_level,
       
    75                     dsn=dsn)
    71                 return True
    76                 return True
    72 
    77 
    73     def prepare_conns(self, *pgm_names):
    78     def prepare_conns(self, *pgm_names):
    74         if self.config.meta_db:
    79         if self.config.meta_db:
    75             self.pgm.create_conn(name='meta', dsn=self.config.meta_db)
    80             self.pgm.create_conn(name='meta', dsn=self.config.meta_db)
    76             
    81         
    77         for name in pgm_names:
    82         for name in pgm_names:
    78             lookup_name = self.args.__dict__[name]
    83             lookup_name = self.args.__dict__[name]
    79             found = self.prepare_conn_from_config(name, lookup_name)
    84             found = self.prepare_conn_from_config(name, lookup_name)
    80             if not found and self.config.meta_db:
    85             if not found and self.config.meta_db:
    81                 found = self.prepare_conn_from_metadb(name, lookup_name)
    86                 found = self.prepare_conn_from_metadb(name, lookup_name)