Mercurial > python-cmd2
comparison cmd2.py @ 28:28b3fb301d3d
almost working, but problem with check_call
author | catherine@cordelia |
---|---|
date | Sun, 18 May 2008 13:34:38 -0400 |
parents | a76798cde34c |
children | c4bd5f1a6968 |
comparison
equal
deleted
inserted
replaced
27:a76798cde34c | 28:28b3fb301d3d |
---|---|
69 Download from http://sourceforge.net/projects/pywin32/""" | 69 Download from http://sourceforge.net/projects/pywin32/""" |
70 else: | 70 else: |
71 errmsg = """Redirecting to or from paste buffer requires xclip | 71 errmsg = """Redirecting to or from paste buffer requires xclip |
72 to be installed on operating system. | 72 to be installed on operating system. |
73 On Debian/Ubuntu, 'sudo apt-get install xclip' will install it.""" | 73 On Debian/Ubuntu, 'sudo apt-get install xclip' will install it.""" |
74 def __init__(self, msg): | 74 def __init__(self): |
75 Exception.__init__(self, self.errmsg) | 75 Exception.__init__(self, self.errmsg) |
76 | 76 |
77 if sys.platform[:3] == 'win': | 77 if sys.platform[:3] == 'win': |
78 def getPasteBuffer(): | 78 def getPasteBuffer(): |
79 if not win32clipboard: | 79 try: |
80 win32clipboard.OpenClipboard(0) | |
81 except NameError: | |
80 raise PasteBufferError | 82 raise PasteBufferError |
81 win32clipboard.OpenClipboard(0) | |
82 try: | 83 try: |
83 result = win32clipboard.GetClipboardData() | 84 result = win32clipboard.GetClipboardData() |
84 except TypeError: | 85 except TypeError: |
85 result = '' #non-text | 86 result = '' #non-text |
86 win32clipboard.CloseClipboard() | 87 win32clipboard.CloseClipboard() |
87 return result | 88 return result |
88 def writeToPasteBuffer(txt): | 89 def writeToPasteBuffer(txt): |
89 if not win32clipboard: | 90 try: |
91 win32clipboard.OpenClipboard(0) | |
92 except NameError: | |
90 raise PasteBufferError | 93 raise PasteBufferError |
91 win32clipboard.OpenClipboard(0) | |
92 win32clipboard.EmptyClipboard() | 94 win32clipboard.EmptyClipboard() |
93 win32clipboard.SetClipboardText(txt) | 95 win32clipboard.SetClipboardText(txt) |
94 win32clipboard.CloseClipboard() | 96 win32clipboard.CloseClipboard() |
95 else: | 97 else: |
96 def getPasteBuffer(): | 98 def getPasteBuffer(): |
97 try: | 99 try: |
98 xclipproc = subprocess.check_call('xc1ip -o -sel clip', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) | 100 xclipproc = subprocess.check_call('xclip -o -sel clip', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) |
99 except subprocess.CalledProcessError: | 101 except subprocess.CalledProcessError: |
100 raise PasteBufferError | 102 raise PasteBufferError |
101 return xclipproc.stdout.read() | 103 return xclipproc.stdout.read() |
102 def writeToPasteBuffer(txt): | 104 def writeToPasteBuffer(txt): |
103 try: | 105 try: |
217 self.stdout = tempfile.TemporaryFile() | 219 self.stdout = tempfile.TemporaryFile() |
218 if mode == 'a': | 220 if mode == 'a': |
219 self.stdout.write(clipcontents) | 221 self.stdout.write(clipcontents) |
220 else: | 222 else: |
221 statement = '%s %s' % (statement, clipcontents) | 223 statement = '%s %s' % (statement, clipcontents) |
222 except PasteBufferError: | 224 except PasteBufferError, e: |
225 print e | |
223 return 0 | 226 return 0 |
224 elif redirect: | 227 elif redirect: |
225 if mode in ('w','a'): | 228 if mode in ('w','a'): |
226 statekeeper = Statekeeper(self, ('stdout',)) | 229 statekeeper = Statekeeper(self, ('stdout',)) |
227 self.stdout = open(redirect, mode) | 230 self.stdout = open(redirect, mode) |