comparison sqlpyPlus.py @ 88:d3da34473a8e

fixed spool
author catherine@localhost
date Tue, 20 May 2008 12:04:00 -0400
parents 2de82dd6eba2
children f9a8852a9552
comparison
equal deleted inserted replaced
87:2de82dd6eba2 88:d3da34473a8e
639 def do_resolve(self, arg): 639 def do_resolve(self, arg):
640 self.stdout.write(self.resolve(arg)+'\n') 640 self.stdout.write(self.resolve(arg)+'\n')
641 641
642 def spoolstop(self): 642 def spoolstop(self):
643 if self.spoolFile: 643 if self.spoolFile:
644 sys.stdout = self.stdoutBeforeSpool 644 self.stdout = self.stdoutBeforeSpool
645 print 'Finished spooling to ', self.spoolFile.name 645 print 'Finished spooling to ', self.spoolFile.name
646 self.spoolFile.close() 646 self.spoolFile.close()
647 self.spoolFile = None 647 self.spoolFile = None
648 648
649 def do_spool(self, arg): 649 def do_spool(self, arg):
655 if arg.lower() != 'off': 655 if arg.lower() != 'off':
656 if '.' not in arg: 656 if '.' not in arg:
657 arg = '%s.lst' % arg 657 arg = '%s.lst' % arg
658 print 'Sending output to %s (until SPOOL OFF received)' % (arg) 658 print 'Sending output to %s (until SPOOL OFF received)' % (arg)
659 self.spoolFile = open(arg, 'w') 659 self.spoolFile = open(arg, 'w')
660 sys.stdout = self.spoolFile 660 self.stdout = self.spoolFile
661
662 def write(self, arg, fname):
663 originalOut = sys.stdout
664 f = open(fname, 'w')
665 sys.stdout = f
666 self.onecmd_plus_hooks(arg)
667 f.close()
668 sys.stdout = originalOut
669 661
670 def do_write(self, args): 662 def do_write(self, args):
671 'write [filename.extension] query - writes result to a file' 663 print 'Use (query) > outfilename instead.'
672 words = args.split(None, 1) 664 return
673 if len(words) > 1 and '.' in words[0]:
674 fname, command = words
675 else:
676 fname, command = 'output.txt', args
677 self.write(command, fname)
678 print 'Results written to %s' % os.path.join(os.getcwd(), fname)
679 665
680 def do_compare(self, args): 666 def do_compare(self, args):
681 """COMPARE query1 TO query2 - uses external tool to display differences. 667 """COMPARE query1 TO query2 - uses external tool to display differences.
682 668
683 Sorting is recommended to avoid false hits. 669 Sorting is recommended to avoid false hits.
684 Will attempt to use a graphical diff/merge tool like kdiff3, meld, or Araxis Merge, 670 Will attempt to use a graphical diff/merge tool like kdiff3, meld, or Araxis Merge,
685 if they are installed.""" 671 if they are installed."""
686 fnames = [] 672 fnames = []
687 args2 = args.split(' to ') 673 args2 = args.split(' to ')
674 if len(args2) < 2:
675 print self.do_compare.__doc__
676 return
688 for n in range(len(args2)): 677 for n in range(len(args2)):
689 query = args2[n] 678 query = args2[n]
690 fnames.append('compare%s.txt' % n) 679 fnames.append('compare%s.txt' % n)
691 if query.rstrip()[-1] != self.terminator: 680 if query.rstrip()[-1] != self.terminator:
692 query = '%s%s' % (query, self.terminator) 681 query = '%s%s' % (query, self.terminator)
693 self.write(query, fnames[n]) 682 self.onecmd_plus_hooks('%s > %s' % (query, fnames[n]))
694 diffMergeSearcher.invoke(fnames[0], fnames[1]) 683 diffMergeSearcher.invoke(fnames[0], fnames[1])
695 684
696 bufferPosPattern = re.compile('\d+') 685 bufferPosPattern = re.compile('\d+')
697 rangeIndicators = ('-',':') 686 rangeIndicators = ('-',':')
698 687