Guest

Untitled

By: a guest on Oct 15th, 2011  |  syntax: Python  |  size: 1.06 KB  |  hits: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. servername = 'unix.torvalds.net'
  2. username = 'stevejobs'
  3.  
  4. remotedir = 'bla/' # don't forget the trailing slash
  5. remoteurl = 'http://www.foo.com/screenshots/' # don't forget the trailing slash
  6.  
  7. playsound = true # do you want a sound if upload is done and url in your pastebuffer?
  8.  
  9. ## there should be no reason to edit below this line
  10.  
  11. import os, sys, random, string, subprocess
  12. for file in sys.stdin:
  13.         file = file.strip()
  14.         fileroot, fileext = os.path.splitext(file)
  15.         if os.path.isfile(file) and fileext.lower()=='.png':
  16.                 print file, " is a png file"
  17.                 remotefilename = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(8)) + '.png'
  18.                 # returnvalue = subprocess.check_call(['rsync', ....])
  19.                 returnvalue = subprocess.check_call(['rsync', file, username + '@' + servername + ':' + remotedir + remotefilename ])
  20.                 p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE)
  21.                 p.stdin.write(remoteurl + remotefilename)
  22.                 p.stdin.close()
  23.                 p.wait()
  24.                 if (playsound):
  25.                         p2 = subprocess.check_call(['afplay', '/System/Library/Sounds/Purr.aiff'])
  26.