comparison cmd2.py @ 140:e49ded85ba4c

keeping comments in history now
author catherine@Elli.myhome.westell.com
date Thu, 13 Nov 2008 15:40:59 -0500
parents 4b428849783d
children fc31b73cb04d
comparison
equal deleted inserted replaced
139:e2d06e53d09c 140:e49ded85ba4c
24 As of 0.3.0, options should be specified as `optparse` options. See README.txt. 24 As of 0.3.0, options should be specified as `optparse` options. See README.txt.
25 flagReader.py options are still supported for backward compatibility 25 flagReader.py options are still supported for backward compatibility
26 """ 26 """
27 import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest, unittest 27 import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest, unittest
28 from optparse import make_option 28 from optparse import make_option
29 __version__ = '0.4.2' 29 __version__ = '0.4.4'
30 30
31 class OptionParser(optparse.OptionParser): 31 class OptionParser(optparse.OptionParser):
32 def exit(self, status=0, msg=None): 32 def exit(self, status=0, msg=None):
33 self.values._exit = True 33 self.values._exit = True
34 if msg: 34 if msg:
242 >>> r.statement, r.input, r.inputFrom 242 >>> r.statement, r.input, r.inputFrom
243 ('got from ', '<', 'thisfile.txt') 243 ('got from ', '<', 'thisfile.txt')
244 ''' 244 '''
245 if isinstance(s, pyparsing.ParseResults): 245 if isinstance(s, pyparsing.ParseResults):
246 return s 246 return s
247 s = self.commentGrammars.transformString(s)
248 result = (pyparsing.SkipTo(pyparsing.StringEnd()))("fullStatement").parseString(s) 247 result = (pyparsing.SkipTo(pyparsing.StringEnd()))("fullStatement").parseString(s)
248 s = self.commentGrammars.transformString(s)
249 command = s.split()[0] 249 command = s.split()[0]
250 if self.caseInsensitive: 250 if self.caseInsensitive:
251 command = command.lower() 251 command = command.lower()
252 result['command'] = command 252 result['command'] = command
253 if command in self.noSpecialParse: 253 if command in self.noSpecialParse:
254 result['statement'] = result.fullStatement 254 result['statement'] = s
255 return result 255 return result
256 256
257 if s[0] in self.shortcuts: 257 if s[0] in self.shortcuts:
258 s = self.shortcuts[s[0]] + ' ' + s[1:] 258 s = self.shortcuts[s[0]] + ' ' + s[1:]
259 result['statement'] = s 259 result['statement'] = s
264 if result.terminator: 264 if result.terminator:
265 result['statement'] = result.upToIncluding 265 result['statement'] = result.upToIncluding
266 result['unterminated'] = result.before 266 result['unterminated'] = result.before
267 result['parseable'] = result.after 267 result['parseable'] = result.after
268 else: 268 else:
269 result['statement'] = result['unterminated'] = result.before
269 if command in self.multilineCommands: 270 if command in self.multilineCommands:
270 return result # don't bother with the rest, we're still collecting input 271 return result # don't bother with the rest, we're still collecting input
271 result += parseSearchResults(self.punctuationPattern, s) 272 result += parseSearchResults(self.punctuationPattern, s)
272 result['statement'] = result['unterminated'] = result.before
273 result += parseSearchResults(self.pipePattern, result.parseable) 273 result += parseSearchResults(self.pipePattern, result.parseable)
274 result += parseSearchResults(self.redirectInPattern, result.parseable) 274 result += parseSearchResults(self.redirectInPattern, result.parseable)
275 result += parseSearchResults(self.redirectOutPattern, result.parseable) 275 result += parseSearchResults(self.redirectOutPattern, result.parseable)
276 result += parseSearchResults(self.argSeparatorPattern, result.statement) 276 result += parseSearchResults(self.argSeparatorPattern, result.statement)
277 if self.caseInsensitive: 277 if self.caseInsensitive: