Mercurial > python-cmd2
changeset 192:c0d4c7ba14a9
added settable timings param
author | catherine@Elli.myhome.westell.com |
---|---|
date | Sun, 15 Feb 2009 11:03:38 -0500 |
parents | 9d9e9ea88daf |
children | e96877b59371 |
files | cmd2.py |
diffstat | 1 files changed, 12 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd2.py Thu Feb 12 04:29:43 2009 -0500 +++ b/cmd2.py Sun Feb 15 11:03:38 2009 -0500 @@ -24,7 +24,8 @@ As of 0.3.0, options should be specified as `optparse` options. See README.txt. flagReader.py options are still supported for backward compatibility """ -import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest, unittest, string +import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest +import unittest, string, datetime from optparse import make_option __version__ = '0.4.5' @@ -161,13 +162,14 @@ echo = False caseInsensitive = True continuationPrompt = '> ' + timing = False legalChars = '!#$%.:?@_' + pyparsing.alphanums + pyparsing.alphas8bit # make sure your terminators are not in here! shortcuts = {'?': 'help', '!': 'shell', '@': 'load' } excludeFromHistory = '''run r list l history hi ed edit li eof'''.split() noSpecialParse = 'set ed edit exit'.split() defaultExtension = 'txt' defaultFileName = 'command.txt' - settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive', 'echo'] + settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive', 'echo', 'timing'] editor = os.environ.get('EDITOR') _STOP_AND_EXIT = 2 @@ -447,11 +449,13 @@ return self.emptyline() if not pyparsing.Or(self.commentGrammars).setParseAction(lambda x: '').transformString(line): return 0 # command was empty except for comments + import profile try: statement = self.parsed(line) while statement.parsed.multilineCommand and (statement.parsed.terminator == ''): - statement = self.parsed('%s\n%s' % (statement.parsed.raw, - self.pseudo_raw_input(self.continuationPrompt))) + statement = '%s\n%s' % (statement.parsed.raw, + self.pseudo_raw_input(self.continuationPrompt)) + statement = self.parsed(statement) except Exception, e: print e return 0 @@ -489,7 +493,10 @@ func = getattr(self, 'do_' + statement.parsed.command) except AttributeError: return self.default(statement) - stop = func(statement) + timestart = datetime.datetime.now() + stop = func(statement) + if self.timing: + print 'Elapsed: %s' % str(datetime.datetime.now() - timestart) except Exception, e: print e try: