tools/toolbase.py
changeset 9 2fcc8ef0b97d
parent 8 2911935c524d
child 10 f3a1b9792cc9
--- a/tools/toolbase.py	Tue Aug 16 15:12:53 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-import argparse
-
-from tools import pgmanager
-from common import config
-
-
-class ToolBase:
-    def __init__(self, name, desc):
-        self.parser = argparse.ArgumentParser(description=desc)
-        
-        self.config = config.ConfigParser()
-        self.config.add_argument('databases', type=dict)
-        self.config.add_argument('meta_db')
-        self.config.add_argument('meta_query')
-        
-        self.pgm = pgmanager.get_instance()
-        
-    def init(self):
-        self.config.load('pgtoolkit.conf')
-        self.args = self.parser.parse_args()
-
-    def buildconn(self, name, targetname):
-        with self.pgm.cursor('meta') as curs:
-            curs.execute(self.config.meta_query, [targetname])
-            row = curs.fetchone_dict()
-            curs.connection.commit()
-            
-            if not row:
-                raise Exception('Unknown database "%s"' % targetname)
-            
-            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')
-