comparison cmd2.py @ 435:bfbe4241bd6b

custom double-redirector fixed
author catherine.devlin@gmail.com
date Thu, 25 Aug 2011 15:24:56 -0400
parents 742fd308f0c9
children c4c35f002aef
comparison
equal deleted inserted replaced
434:742fd308f0c9 435:bfbe4241bd6b
377 feedback_to_output = False # Do include nonessentials in >, | output 377 feedback_to_output = False # Do include nonessentials in >, | output
378 quiet = False # Do not suppress nonessential output 378 quiet = False # Do not suppress nonessential output
379 debug = False 379 debug = False
380 locals_in_py = True 380 locals_in_py = True
381 kept_state = None 381 kept_state = None
382 redirector = '>' # for sending output to file
382 settable = stubbornDict(''' 383 settable = stubbornDict('''
383 prompt 384 prompt
384 colors Colorized output (*nix only) 385 colors Colorized output (*nix only)
385 continuation_prompt On 2nd+ line of input 386 continuation_prompt On 2nd+ line of input
386 debug Show full error stack on error 387 debug Show full error stack on error
663 - command: what 664 - command: what
664 - statement: ['what', 'if "quoted strings /* seem to " start comments?'] 665 - statement: ['what', 'if "quoted strings /* seem to " start comments?']
665 - args: if "quoted strings /* seem to " start comments? 666 - args: if "quoted strings /* seem to " start comments?
666 - command: what 667 - command: what
667 ''' 668 '''
668 outputParser = (pyparsing.Literal('>>') | (pyparsing.WordStart() + '>') | pyparsing.Regex('[^=]>'))('output') 669 #outputParser = (pyparsing.Literal('>>') | (pyparsing.WordStart() + '>') | pyparsing.Regex('[^=]>'))('output')
670 outputParser = (pyparsing.Literal(self.redirector *2) | \
671 (pyparsing.WordStart() + self.redirector) | \
672 pyparsing.Regex('[^=]' + self.redirector))('output')
669 673
670 terminatorParser = pyparsing.Or([(hasattr(t, 'parseString') and t) or pyparsing.Literal(t) for t in self.terminators])('terminator') 674 terminatorParser = pyparsing.Or([(hasattr(t, 'parseString') and t) or pyparsing.Literal(t) for t in self.terminators])('terminator')
671 stringEnd = pyparsing.stringEnd ^ '\nEOF' 675 stringEnd = pyparsing.stringEnd ^ '\nEOF'
672 self.multilineCommand = pyparsing.Or([pyparsing.Keyword(c, caseless=self.case_insensitive) for c in self.multilineCommands])('multilineCommand') 676 self.multilineCommand = pyparsing.Or([pyparsing.Keyword(c, caseless=self.case_insensitive) for c in self.multilineCommands])('multilineCommand')
673 oneLineCommand = (~self.multilineCommand + pyparsing.Word(self.legalChars))('command') 677 oneLineCommand = (~self.multilineCommand + pyparsing.Word(self.legalChars))('command')
813 raise EnvironmentError('Cannot redirect to paste buffer; install ``xclip`` and re-run to enable') 817 raise EnvironmentError('Cannot redirect to paste buffer; install ``xclip`` and re-run to enable')
814 self.kept_state = Statekeeper(self, ('stdout',)) 818 self.kept_state = Statekeeper(self, ('stdout',))
815 self.kept_sys = Statekeeper(sys, ('stdout',)) 819 self.kept_sys = Statekeeper(sys, ('stdout',))
816 if statement.parsed.outputTo: 820 if statement.parsed.outputTo:
817 mode = 'w' 821 mode = 'w'
818 if statement.parsed.output == '>>': 822 if statement.parsed.output == 2 * self.redirector:
819 mode = 'a' 823 mode = 'a'
820 sys.stdout = self.stdout = open(os.path.expanduser(statement.parsed.outputTo), mode) 824 sys.stdout = self.stdout = open(os.path.expanduser(statement.parsed.outputTo), mode)
821 else: 825 else:
822 sys.stdout = self.stdout = tempfile.TemporaryFile(mode="w+") 826 sys.stdout = self.stdout = tempfile.TemporaryFile(mode="w+")
823 if statement.parsed.output == '>>': 827 if statement.parsed.output == '>>':