toolbase.py
changeset 5 57cf8fdff5ed
parent 2 efee419b7a2d
--- a/toolbase.py	Wed Jul 20 10:51:18 2011 +0200
+++ b/toolbase.py	Wed Jul 20 10:54:07 2011 +0200
@@ -7,7 +7,6 @@
 class ToolBase:
     def __init__(self, name, desc):
         self.parser = argparse.ArgumentParser(description=desc)
-        self.parser.add_argument('target', metavar='target', type=str, help='Target database')
         
         self.config = config.ConfigParser()
         self.config.add_argument('databases', type=dict)
@@ -19,11 +18,6 @@
     def init(self):
         self.config.load('pgtoolkit.conf')
         self.args = self.parser.parse_args()
-        
-        if self.config.meta_db:
-            self.pgm.create_conn(name='meta', dsn=self.config.meta_db)
-            self.buildconn('target', self.args.target)
-            self.pgm.close_conn('meta')
 
     def buildconn(self, name, targetname):
         with self.pgm.cursor('meta') as curs:
@@ -36,3 +30,31 @@
             
             self.pgm.create_conn(name=name, **row)
 
+    def prepareconns(self, *args):        
+        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])
+            self.pgm.close_conn('meta')
+
+
+class SimpleTool(ToolBase):
+    def __init__(self, name, desc):
+        ToolBase.__init__(self, name, desc)        
+        self.parser.add_argument('target', metavar='target', type=str, help='Target database')
+      
+    def init(self):
+        ToolBase.init(self)
+        self.prepareconns('target')
+
+
+class SrcDstTool(ToolBase):
+    def __init__(self, name, desc):
+        ToolBase.__init__(self, name, desc)        
+        self.parser.add_argument('src', metavar='source', type=str, help='Source database')
+        self.parser.add_argument('dst', metavar='destination', type=str, help='Destination database')
+      
+    def init(self):
+        ToolBase.init(self)
+        self.prepareconns('src', 'dst')
+