Merge lp:~blackfrog/pastebinit/clipboard into lp:pastebinit

Proposed by BlackFrog
Status: Work in progress
Proposed branch: lp:~blackfrog/pastebinit/clipboard
Merge into: lp:pastebinit
Diff against target: 80 lines (+55/-3)
1 file modified
pastebinit (+55/-3)
To merge this branch: bzr merge lp:~blackfrog/pastebinit/clipboard
Reviewer Review Type Date Requested Status
Stéphane Graber Needs Fixing
Review via email: mp+51404@code.launchpad.net

Description of the change

This branch added a feature that will copy the url of the paste to the system clipboard. The feature has beed tested on Mac OS X system. I have included code for a Linux & Windows system. But I cannot test/debug those system.

To post a comment you must log in.
Revision history for this message
Stéphane Graber (stgraber) wrote :

Not merging it for this release, I'd need to have testers on the various supported platform and would like this feature to be optional.

I for one don't like apps messing with my clipboard and I don't think showing an error message on most system is the way to go.

review: Needs Fixing

Unmerged revisions

115. By BlackFrog

Added code to copy the url to the system clipboard

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'pastebinit'
--- pastebinit 2011-01-30 15:20:00 +0000
+++ pastebinit 2011-02-26 05:46:14 +0000
@@ -160,6 +160,52 @@
160 def getFirstNodeText(nodes, title):160 def getFirstNodeText(nodes, title):
161 return getText(getFirstNode(nodes, title).childNodes)161 return getText(getFirstNode(nodes, title).childNodes)
162162
163 def copyToClipboard(url):
164 try:
165 import platform, subprocess
166 if platform.system() == 'Darwin':
167 # echo `url` | pbcopy
168 subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE).communicate(url)
169
170 elif platform.system() == "Windows":
171 # I don't have windows to test the following code
172 # I found at http://stackoverflow.com/questions/3827511/copying-and-pasting-from-to-clipboard-with-python-win32
173 from win32clipboard import win32clipboard
174 import win32gui, win32con
175 OpenClipboard()
176 EmptyClipboard()
177 SetClipboard(win32con.CF_TEXT, url) #set clipboard data
178 # if the above code doesn't work at all
179 # try this method: http://mail.python.org/pipermail/python-win32/2005-April/003186.html
180
181 elif platform.system() == "Linux":
182 # TODO: need to make sure xclip is install before using
183 # because I don't know how to test if xclip is available on the system
184 # I am going to wrap Popen call in try block
185 try:
186 subprocess.Popen(['xclip'], stdin=subprocess.PIPE).communicate(url)
187 copySuccess = True
188 except:
189 copySuccess = False
190 # Check if xclip was success, if not try gtk
191 if copySuccess == False:
192 # Found this code for using gtk on Ubuntu
193 # http://ubuntuforums.org/showthread.php?t=1295070
194 try:
195 import pygtk
196 pygtk.require('2.0')
197 import gtk
198 clipboard = gtk.clipboard_get()
199 clipboard.set_text("%s" % (url))
200 clipboard.store()
201 except ImportError, e:
202 pass # module doesn't exist
203 except: #catch *all* exceptions
204 # for debugging un-comment the lines below to see what the exception errors
205 # e = sys.exc_info()[1]
206 # print e
207 print "Couldn't copy URL to clipboard, you will have to copy manually."
208
163 # Display usage instructions209 # Display usage instructions
164 def Usage():210 def Usage():
165 print "pastebinit v" + version211 print "pastebinit v" + version
@@ -331,14 +377,20 @@
331 page = url_opener.open(website, params) #Send the informations and be redirected to the final page377 page = url_opener.open(website, params) #Send the informations and be redirected to the final page
332378
333 try:379 try:
380 pasteURL = "" # the url of where we can file the paste
334 if reLink: #Check if we have to apply a regexp381 if reLink: #Check if we have to apply a regexp
335 website = website.replace(tmp_page, "")382 website = website.replace(tmp_page, "")
336 if reLink == '(.*)':383 if reLink == '(.*)':
337 print page.read().strip()384 pasteURL = page.read().strip()
338 else:385 else:
339 print website + re.split(reLink, page.read())[1] #Print the result of the Regexp386 pasteURL = website + re.split(reLink, page.read())[1] #Print the result of the Regexp
340 else:387 else:
341 print page.url #Get the final page and show the ur388 pasteURL = page.url #Get the final page and show the url
389
390 # copy the url to the clipboard
391 copyToClipboard(pasteURL)
392 print pasteURL # output paste url to stdout
393
342 except KeyboardInterrupt:394 except KeyboardInterrupt:
343 sys.exit(_("KeyboardInterrupt caught."))395 sys.exit(_("KeyboardInterrupt caught."))
344 except:396 except:

Subscribers

People subscribed via source and target branches

to all changes: