diff options
author | Florian Pritz <f-p@gmx.at> | 2009-07-15 01:45:16 +0200 |
---|---|---|
committer | Florian Pritz <f-p@gmx.at> | 2009-07-15 01:45:16 +0200 |
commit | e896c96d42375002c362e345690dfb46291dde80 (patch) | |
tree | 9c176b889a998d5389e4ecbbcb84ccc7226f498c /fb | |
parent | b28fb3f95238b44d6b88979e01cc60588eee6360 (diff) | |
download | bin-e896c96d42375002c362e345690dfb46291dde80.tar.gz bin-e896c96d42375002c362e345690dfb46291dde80.tar.xz |
update fb
Diffstat (limited to 'fb')
-rwxr-xr-x | fb | 53 |
1 files changed, 48 insertions, 5 deletions
@@ -8,7 +8,7 @@ #---------------------------------------------------- '''[cat |] %prog [file1 file2 ...]''' -__version__ = '0.3.1' +__version__ = '0.4.0' __desc__ = ''' Upload file to paste.xinu.at and copy URL to clipboard or nopaste stdin @@ -18,14 +18,50 @@ from optparse import OptionParser from subprocess import Popen, PIPE import os import sys +import netrc + +def password(): + ''' netrc: machine paste.xinu.at password PASSWORD''' + try: + auth = netrc.netrc().authenticators('paste.xinu.at') + except: + return None + if not auth: + return None + return auth[2] def do_upload(file): - url = Popen(['curl', '-#', '-L', '-F', 'userfile=@'+file, - 'http://paste.xinu.at/file/do_upload' - ], stdout=PIPE).communicate()[0] + pw = password() + curl_args = [] + if pw: + curl_args.append('-F') + curl_args.append('password='+pw) + url = Popen(merge([['curl', '-#', '-L', '-F', 'userfile=@'+file, + ], curl_args, ['http://paste.xinu.at/file/do_upload']]), + stdout=PIPE).communicate()[0] print url Popen('echo -n "%s" | nohup &>/dev/null xclip' % url, shell=True) +def delete(id): + pw = password() + curl_args = [] + if not pw: + print 'Please set up .netrc correctly' + sys.exit(1) + else: + curl_args.append('-F') + curl_args.append('password='+pw) + Popen(merge([['curl', '-#', '-L'], curl_args, + ['http://paste.xinu.at/file/delete/'+id]] + ),).communicate()[0] + +def merge(seq): + merged = [] + for s in seq: + for x in s: + merged.append(x) + return merged + def read_stdin(): if os.isatty(sys.stdin.fileno()): print '^C to exit, ^D to send' @@ -44,9 +80,16 @@ def read_stdin(): def main(): p = OptionParser(version=__version__, usage=__doc__, - description=__desc__) + description=__desc__+password.__doc__) + p.add_option('-d', '--delete', action='append', dest='delete', + help='delete file by ID', metavar='<ID>', default=None) options, args = p.parse_args() + if options.delete: + for id in options.delete: + delete(id) + sys.exit() + tmpfiles = [] if args: for arg in args: |