# HG changeset patch # User catherine@cordelia # Date 1211023395 14400 # Node ID 82dde2f60e46ca3f8ae7e15411a18eeeb3459be5 # Parent c8efa4369189af815ec8b96de8d9a64d07b0dc24# Parent 6948d1f9e4b48908c712e3ea66c4f91f0d5ec3de catching no-xclip errors finally fixed diff -r 6948d1f9e4b4 -r 82dde2f60e46 cmd2.py --- a/cmd2.py Fri May 16 18:09:34 2008 -0400 +++ b/cmd2.py Sat May 17 07:23:15 2008 -0400 @@ -45,8 +45,10 @@ optionParser.set_usage("%s [options] arg" % func.__name__.strip('do_')) def newFunc(instance, arg): try: - opts, arg = optionParser.parse_args(arg.split()) - except optparse.OptionValueError, e: + opts, arg = optionParser.parse_args(arg.split()) + except (optparse.OptionValueError, optparse.BadOptionError, + optparse.OptionError, optparse.AmbiguousOptionError, + optparse.OptionConflictError), e: print e optionParser.print_help() return @@ -141,26 +143,15 @@ if redirect: return newStatement, redirect, 'r' return statement, '', '' - + def pasteBufferProcess(self, mode='read'): if mode == 'read': command = 'xc1ip -o -sel clip' else: command = 'xclip -sel clip' - 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 + result = subprocess.check_call(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) return result - + def onecmd(self, line): """Interpret the argument as though it had been typed in response to the prompt. @@ -189,7 +180,10 @@ self.stdout.write(clipcontents) else: statement = '%s %s' % (statement, clipcontents) - except EnvironmentError, e: + except subprocess.CalledProcessError: + print """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.""" return 0 elif redirect: if mode in ('w','a'):