TableDiffTool: add arguments to set different destination schema and table. PgDataDiff: fixes.
authorRadek Brich <radek.brich@devl.cz>
Thu, 20 Oct 2011 13:54:35 +0200
changeset 14 a900bc629ecc
parent 13 16dc5dec9c36
child 15 93450b43e627
TableDiffTool: add arguments to set different destination schema and table. PgDataDiff: fixes.
pgtoolkit/pgdatadiff.py
pgtoolkit/toolbase.py
tablediff.py
--- a/pgtoolkit/pgdatadiff.py	Fri Sep 09 11:56:37 2011 +0200
+++ b/pgtoolkit/pgdatadiff.py	Thu Oct 20 13:54:35 2011 +0200
@@ -186,7 +186,7 @@
         
         '''
         for ln in self.iter_diff():
-            print(ln.format_patch(self.fulltable2))
+            print(ln.format_patch(self.fulltable1))
 
     def _select(self):
         browser = pgbrowser.PgBrowser(self.conn1)
@@ -221,7 +221,8 @@
     def _compare_row(self, row1, row2):
         if row2 is None:
             cols1 = OrderedDict(zip(self.colnames, row1))
-            return DiffData('-', cols1, None)
+            id = (self.colnames[0], row1[0])
+            return DiffData('-', cols1, None, id=id)
         if row1 is None:
             cols2 = OrderedDict(zip(self.colnames, row2))
             return DiffData('+', None, cols2)
--- a/pgtoolkit/toolbase.py	Fri Sep 09 11:56:37 2011 +0200
+++ b/pgtoolkit/toolbase.py	Thu Oct 20 13:54:35 2011 +0200
@@ -22,10 +22,20 @@
     def init(self):
         self.config.load('pgtoolkit.conf')
         self.args = self.parser.parse_args()
+        self.init_logging()
+        
+    def init_logging(self):
+        # logging
+        handler = logging.StreamHandler()
+        format = ColoredFormatter(highlight(1,7,0)+'%(asctime)s %(levelname)-5s'+highlight(0)+' %(message)s', '%H:%M:%S')
+        handler.setFormatter(format)
+        handler.setLevel(logging.DEBUG)
+        self.log = logging.getLogger('main')
+        self.log.addHandler(handler)
+        self.log.setLevel(logging.DEBUG)
+        
         if self.args.debug:
             handler = logging.StreamHandler()
-            format = ColoredFormatter(
-                highlight(1,7,0)+'%(asctime)s %(levelname)-5s'+highlight(0)+' %(message)s', '%H:%M:%S')
             handler.setFormatter(format)
             handler.setLevel(logging.DEBUG)
             logger = logging.getLogger('pgmanager')
--- a/tablediff.py	Fri Sep 09 11:56:37 2011 +0200
+++ b/tablediff.py	Thu Oct 20 13:54:35 2011 +0200
@@ -15,19 +15,28 @@
     def __init__(self):
         toolbase.SrcDstTool.__init__(self, name='tablediff', desc='Table diff.')
         
-        self.parser.add_argument('table', metavar='table', type=str, help='Table name')
-        self.parser.add_argument('-s', dest='schema', metavar='schema', type=str, default='public', help='Schema name.')
+        self.parser.add_argument('srctable', metavar='srctable',
+            type=str, help='Source table name.')
+        self.parser.add_argument('--dst-table', dest='dsttable', metavar='dsttable',
+            type=str, default=None, help='Destination table (default=srctable).')
+        self.parser.add_argument('-s', '--src-schema', dest='srcschema', metavar='srcschema',
+            type=str, default='public', help='Schema name (default=public).')
+        self.parser.add_argument('--dst-schema', dest='dstschema', metavar='dstschema',
+            type=str, default=None, help='Destination schema name (default=srcschema).')
         self.parser.add_argument('--sql', action='store_true', help='Output is SQL script.')
         
         self.init()
 
     def main(self):
-        table = self.args.table
-        schema = self.args.schema
-
+        srcschema = self.args.srcschema
+        dstschema = self.args.dstschema if self.args.dstschema else self.args.srcschema
+        
+        srctable = self.args.srctable
+        dsttable = self.args.dsttable if self.args.dsttable else self.args.srctable
+        
         dd = pgdatadiff.PgDataDiff(self.pgm.get_conn('src'), self.pgm.get_conn('dst'))
-        dd.settable1(table, schema)
-        dd.settable2(table, schema)
+        dd.settable1(srctable, srcschema)
+        dd.settable2(dsttable, dstschema)
         
         if self.args.sql:
             dd.print_patch()