comparison cmd2/cmd2.py @ 109:78c4db4c2045

all done but the proper packaging
author catherine@dellzilla
date Fri, 24 Oct 2008 16:54:45 -0400
parents f7b0152c57f9
children e3b8eaadea56
comparison
equal deleted inserted replaced
108:f7b0152c57f9 109:78c4db4c2045
22 As of 0.3.0, options should be specified as `optparse` options. See README.txt. 22 As of 0.3.0, options should be specified as `optparse` options. See README.txt.
23 flagReader.py options are still supported for backward compatibility 23 flagReader.py options are still supported for backward compatibility
24 """ 24 """
25 import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest, unittest 25 import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest, unittest
26 from optparse import make_option 26 from optparse import make_option
27 __version__ = '0.3.7' 27 __version__ = '0.4'
28 28
29 class OptionParser(optparse.OptionParser): 29 class OptionParser(optparse.OptionParser):
30 def exit(self, status=0, msg=None): 30 def exit(self, status=0, msg=None):
31 self.values._exit = True 31 self.values._exit = True
32 if msg: 32 if msg:
726 def refreshCommandFinder(self): 726 def refreshCommandFinder(self):
727 prompt = pyparsing.Suppress(pyparsing.lineStart + self.cmdapp.prompt) 727 prompt = pyparsing.Suppress(pyparsing.lineStart + self.cmdapp.prompt)
728 continuationPrompt = pyparsing.Suppress(pyparsing.lineStart + self.cmdapp.continuationPrompt) 728 continuationPrompt = pyparsing.Suppress(pyparsing.lineStart + self.cmdapp.continuationPrompt)
729 self.cmdtxtPattern = (prompt + pyparsing.restOfLine + pyparsing.ZeroOrMore( 729 self.cmdtxtPattern = (prompt + pyparsing.restOfLine + pyparsing.ZeroOrMore(
730 pyparsing.lineEnd + continuationPrompt + pyparsing.restOfLine))("command") 730 pyparsing.lineEnd + continuationPrompt + pyparsing.restOfLine))("command")
731
732 pass
733 def inputGenerator(self): 731 def inputGenerator(self):
734 while True: 732 while True:
735 self.refreshCommandFinder() 733 self.refreshCommandFinder()
736 (thiscmd, startpos, endpos) = self.cmdtxtPattern.scanString(self.transcript[self.bookmark:], maxMatches=1).next() 734 (thiscmd, startpos, endpos) = self.cmdtxtPattern.scanString(self.transcript[self.bookmark:], maxMatches=1).next()
737 lineNum = self.transcript.count('\n', 0, self.bookmark+startpos) + 2 735 lineNum = self.transcript.count('\n', 0, self.bookmark+startpos) + 2
747 except StopIteration: 745 except StopIteration:
748 return self.transcript[self.bookmark:] 746 return self.transcript[self.bookmark:]
749 747
750 class Cmd2TestCase(unittest.TestCase): 748 class Cmd2TestCase(unittest.TestCase):
751 '''Subclass this, setting CmdApp and transcriptFileName, to make a unittest.TestCase class 749 '''Subclass this, setting CmdApp and transcriptFileName, to make a unittest.TestCase class
752 that will execute the commands in transcriptFileName and expect the results shown.''' 750 that will execute the commands in transcriptFileName and expect the results shown.
751 See example.py'''
753 # problem: this (raw) case gets called by unittest.main - we don't want it to be. hmm 752 # problem: this (raw) case gets called by unittest.main - we don't want it to be. hmm
754 CmdApp = None 753 CmdApp = None
755 transcriptFileName = '' 754 transcriptFileName = ''
756 def setUp(self): 755 def setUp(self):
757 if self.CmdApp: 756 if self.CmdApp: