comparison cmd2.py @ 228:68b444aeaf8b

now abbrevs and synonyms do not clash
author catherine@Elli.myhome.westell.com
date Mon, 23 Mar 2009 08:32:03 -0400
parents 82b6e0881b78
children caa475678e24
comparison
equal deleted inserted replaced
227:82b6e0881b78 228:68b444aeaf8b
586 self.stdout = tempfile.TemporaryFile() 586 self.stdout = tempfile.TemporaryFile()
587 if statement.parsed.output == '>>': 587 if statement.parsed.output == '>>':
588 self.stdout.write(getPasteBuffer()) 588 self.stdout.write(getPasteBuffer())
589 try: 589 try:
590 # "heart" of the command, replace's cmd's onecmd() 590 # "heart" of the command, replace's cmd's onecmd()
591 self.lastcmd = statement.parsed.expanded 591 self.lastcmd = statement.parsed.expanded
592 if self.abbrev: # accept shortened versions of commands 592 try:
593 funcs = [func for (fname, func) in inspect.getmembers(self, inspect.ismethod) 593 func = getattr(self, 'do_' + statement.parsed.command)
594 if fname.startswith('do_' + statement.parsed.command)] 594 except AttributeError:
595 if len(funcs) == 1: 595 func = None
596 func = funcs[0] 596 if self.abbrev: # accept shortened versions of commands
597 else: 597 funcs = [func for (fname, func) in inspect.getmembers(
598 return self.postparsing_postcmd(self.default(statement)) 598 self, inspect.ismethod)
599 else: 599 if fname.startswith('do_' + statement.parsed.command)]
600 try: 600 if len(funcs) == 1:
601 func = getattr(self, 'do_' + statement.parsed.command) 601 func = funcs[0]
602 except AttributeError: 602 if not func:
603 return self.postparsing_postcmd(self.default(statement)) 603 return self.postparsing_postcmd(self.default(statement))
604 timestart = datetime.datetime.now() 604 timestart = datetime.datetime.now()
605 stop = func(statement) 605 stop = func(statement)
606 if self.timing: 606 if self.timing:
607 print 'Elapsed: %s' % str(datetime.datetime.now() - timestart) 607 print 'Elapsed: %s' % str(datetime.datetime.now() - timestart)