Mercurial > python-cmd2
diff cmd2.py @ 58:f20dcfa69341
uber-trap exceptions maybe working?
author | catherine@localhost |
---|---|
date | Tue, 10 Jun 2008 15:22:16 -0400 |
parents | a791d615545c |
children |
line wrap: on
line diff
--- a/cmd2.py Mon Jun 09 12:09:10 2008 -0400 +++ b/cmd2.py Tue Jun 10 15:22:16 2008 -0400 @@ -237,42 +237,45 @@ commands by the interpreter should stop. """ - command, args = self.extractCommand(line) - statement = originalStatement = ' '.join([command, args]) - if (not assumeComplete) and (command in self.multilineCommands): - statement = self.finishStatement(statement) statekeeper = None - stop = 0 - statement, redirect, mode = self.parseRedirectors(statement) - if isinstance(redirect, subprocess.Popen): - statekeeper = Statekeeper(self, ('stdout',)) - self.stdout = redirect.stdin - elif redirect == self._TO_PASTE_BUFFER: - try: - clipcontents = getPasteBuffer() - if mode in ('w', 'a'): + stop = 0 + try: + command, args = self.extractCommand(line) + statement = originalStatement = ' '.join([command, args]) + if (not assumeComplete) and (command in self.multilineCommands): + statement = self.finishStatement(statement) + statement, redirect, mode = self.parseRedirectors(statement) + if isinstance(redirect, subprocess.Popen): + statekeeper = Statekeeper(self, ('stdout',)) + self.stdout = redirect.stdin + elif redirect == self._TO_PASTE_BUFFER: + try: + clipcontents = getPasteBuffer() + if mode in ('w', 'a'): + statekeeper = Statekeeper(self, ('stdout',)) + self.stdout = tempfile.TemporaryFile() + if mode == 'a': + self.stdout.write(clipcontents) + else: + statement = '%s %s' % (statement, clipcontents) + except OSError, e: + print e + return 0 + elif redirect: + if mode in ('w','a'): statekeeper = Statekeeper(self, ('stdout',)) - self.stdout = tempfile.TemporaryFile() - if mode == 'a': - self.stdout.write(clipcontents) + self.stdout = open(redirect, mode) else: - statement = '%s %s' % (statement, clipcontents) - except OSError, e: - print e - return 0 - elif redirect: - if mode in ('w','a'): - statekeeper = Statekeeper(self, ('stdout',)) - self.stdout = open(redirect, mode) + statement = '%s %s' % (statement, self.fileimport(statement=statement, source=redirect)) + if isinstance(redirect, subprocess.Popen): + stop = self.onecmd(statement) else: - statement = '%s %s' % (statement, self.fileimport(statement=statement, source=redirect)) - if isinstance(redirect, subprocess.Popen): - stop = self.onecmd(statement) - else: - stop = cmd.Cmd.onecmd(self, statement) - try: + stop = cmd.Cmd.onecmd(self, statement) + if command not in self.excludeFromHistory: self.history.append(originalStatement) + except Exception, e: + print e finally: if statekeeper: if redirect == self._TO_PASTE_BUFFER: @@ -282,8 +285,7 @@ for result in redirect.communicate(): statekeeper.stdout.write(result or '') self.stdout.close() - statekeeper.restore() - + statekeeper.restore() return stop statementEndPattern = re.compile(r'[%s]\s*$' % terminators)