Mercurial > python-cmd2
comparison cmd2.py @ 275:f62e9fbb3f90
restoring python 2.4 compatibility
author | catherine@cordelia |
---|---|
date | Thu, 28 May 2009 17:33:19 -0400 |
parents | 540315f06a17 |
children | 9bcfa4f81825 |
comparison
equal
deleted
inserted
replaced
274:540315f06a17 | 275:f62e9fbb3f90 |
---|---|
24 """ | 24 """ |
25 import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest | 25 import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest |
26 import unittest, string, datetime, urllib, glob | 26 import unittest, string, datetime, urllib, glob |
27 from code import InteractiveConsole, InteractiveInterpreter, softspace | 27 from code import InteractiveConsole, InteractiveInterpreter, softspace |
28 from optparse import make_option | 28 from optparse import make_option |
29 __version__ = '0.5.3' | 29 __version__ = '0.5.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: |
647 statekeeper = Statekeeper(self, ('stdout',)) | 647 statekeeper = Statekeeper(self, ('stdout',)) |
648 self.stdout = tempfile.TemporaryFile() | 648 self.stdout = tempfile.TemporaryFile() |
649 if statement.parsed.output == '>>': | 649 if statement.parsed.output == '>>': |
650 self.stdout.write(getPasteBuffer()) | 650 self.stdout.write(getPasteBuffer()) |
651 try: | 651 try: |
652 # "heart" of the command, replace's cmd's onecmd() | |
653 self.lastcmd = statement.parsed.expanded | |
654 funcname = self.func_named(statement.parsed.command) | |
655 if not funcname: | |
656 return self.postparsing_postcmd(self.default(statement)) | |
657 try: | 652 try: |
658 func = getattr(self, funcname) | 653 # "heart" of the command, replace's cmd's onecmd() |
659 except AttributeError: | 654 self.lastcmd = statement.parsed.expanded |
660 return self.postparsing_postcmd(self.default(statement)) | 655 funcname = self.func_named(statement.parsed.command) |
661 timestart = datetime.datetime.now() | 656 if not funcname: |
662 stop = func(statement) | 657 return self.postparsing_postcmd(self.default(statement)) |
663 if self.timing: | 658 try: |
664 self.pfeedback('Elapsed: %s' % str(datetime.datetime.now() - timestart)) | 659 func = getattr(self, funcname) |
665 except Exception, e: | 660 except AttributeError: |
666 self.perror(e) | 661 return self.postparsing_postcmd(self.default(statement)) |
662 timestart = datetime.datetime.now() | |
663 stop = func(statement) | |
664 if self.timing: | |
665 self.pfeedback('Elapsed: %s' % str(datetime.datetime.now() - timestart)) | |
666 except Exception, e: | |
667 self.perror(e) | |
667 finally: | 668 finally: |
668 if statekeeper: | 669 if statekeeper: |
669 if statement.parsed.output and not statement.parsed.outputTo: | 670 if statement.parsed.output and not statement.parsed.outputTo: |
670 self.stdout.seek(0) | 671 self.stdout.seek(0) |
671 try: | 672 try: |