pgtoolkit/toolbase.py
changeset 17 f768a3529ee7
parent 14 a900bc629ecc
child 20 73f0d53fef6b
--- 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):