diff -r cb7e13711a99 -r f768a3529ee7 pgtoolkit/toolbase.py --- a/pgtoolkit/toolbase.py Mon Nov 21 10:43:37 2011 +0100 +++ b/pgtoolkit/toolbase.py Mon Nov 21 10:47:24 2011 +0100 @@ -41,23 +41,32 @@ logger = logging.getLogger('pgmanager') logger.addHandler(handler) - def buildconn(self, name, targetname): + def buildconn(self, name, lookup_name): with self.pgm.cursor('meta') as curs: - curs.execute(self.config.meta_query, [targetname]) + curs.execute(self.config.meta_query, [lookup_name]) row = curs.fetchone_dict() curs.connection.commit() if not row: - raise Exception('Unknown database "%s"' % targetname) + raise Exception('Unknown database "%s"' % lookup_name) self.pgm.create_conn(name=name, **row) - def prepareconns(self, *args): + def prepareconns(self, *pgm_names): + # use meta db if self.config.meta_db: self.pgm.create_conn(name='meta', dsn=self.config.meta_db) - for name in args: - self.buildconn(name, self.args.__dict__[name]) + for name in pgm_names: + lookup_name = self.args.__dict__[name] + self.buildconn(name, lookup_name) self.pgm.close_conn('meta') + + # use config dict 'databases' + if self.config.databases: + for name in pgm_names: + lookup_name = self.args.__dict__[name] + dsn = self.config.databases[lookup_name] + self.pgm.create_conn(name=name, dsn=dsn) class SimpleTool(ToolBase):