# HG changeset patch # User catherine@localhost # Date 1210975774 14400 # Node ID 6948d1f9e4b48908c712e3ea66c4f91f0d5ec3de # Parent f9196cf5ef5104d013c20ddfcbb4ae2b8129b8a5 missing xclip half-working diff -r f9196cf5ef51 -r 6948d1f9e4b4 cmd2.py --- a/cmd2.py Fri May 16 17:36:28 2008 -0400 +++ b/cmd2.py Fri May 16 18:09:34 2008 -0400 @@ -141,14 +141,24 @@ if redirect: return newStatement, redirect, 'r' return statement, '', '' - + def pasteBufferProcess(self, mode='read'): if mode == 'read': - command = 'xclip -o -sel clip' + command = 'xc1ip -o -sel clip' else: command = 'xclip -sel clip' - result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) - #TODO: need a better response to user who lacks xclip + errf = tempfile.TemporaryFile() + result = subprocess.Popen(command, shell=True, stderr=errf, stdout=subprocess.PIPE, stdin=subprocess.PIPE) + errf.seek(0) + if 'not found' in errf.read(): + msg = """Redirecting to or from paste buffer requires xclip to be installed on operating system. + On Debian/Ubuntu, 'sudo apt-get install xclip' will install it.""" + print msg + print '---' + errf.seek(0) + print errf.read() + print '---' + raise EnvironmentError, msg return result def onecmd(self, line): @@ -166,17 +176,21 @@ if command in self.multilineCommands: statement = self.finishStatement(statement) statekeeper = None + stop = 0 statement, redirect, mode = self.parseRedirectors(statement) if redirect == self._TO_PASTE_BUFFER: - if mode in ('a', 'r'): - clipcontents = self.pasteBufferProcess('read').stdout.read() - if mode in ('w', 'a'): - statekeeper = Statekeeper(self, ('stdout',)) - self.stdout = self.pasteBufferProcess('write').stdin - if mode == 'a': - self.stdout.write(clipcontents) - else: - statement = '%s %s' % (statement, clipcontents) + try: + if mode in ('a', 'r'): + clipcontents = self.pasteBufferProcess('read').stdout.read() + if mode in ('w', 'a'): + statekeeper = Statekeeper(self, ('stdout',)) + self.stdout = self.pasteBufferProcess('write').stdin + if mode == 'a': + self.stdout.write(clipcontents) + else: + statement = '%s %s' % (statement, clipcontents) + except EnvironmentError, e: + return 0 elif redirect: if mode in ('w','a'): statekeeper = Statekeeper(self, ('stdout',))