From b28fb3f95238b44d6b88979e01cc60588eee6360 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 13 Jul 2009 23:42:32 +0200 Subject: fb now supports http:// mirroring --- fb | 56 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 16 deletions(-) (limited to 'fb') diff --git a/fb b/fb index 6d4a897..c3d6641 100755 --- a/fb +++ b/fb @@ -8,7 +8,7 @@ #---------------------------------------------------- '''[cat |] %prog [file1 file2 ...]''' -__version__ = '0.3' +__version__ = '0.3.1' __desc__ = ''' Upload file to paste.xinu.at and copy URL to clipboard or nopaste stdin @@ -16,7 +16,7 @@ or nopaste stdin from optparse import OptionParser from subprocess import Popen, PIPE -from os import isatty +import os import sys def do_upload(file): @@ -26,6 +26,20 @@ def do_upload(file): print url Popen('echo -n "%s" | nohup &>/dev/null xclip' % url, shell=True) +def read_stdin(): + if os.isatty(sys.stdin.fileno()): + print '^C to exit, ^D to send' + try: + content = sys.stdin.read() + except KeyboardInterrupt: + sys.exit() + if not content: + sys.exit() + tmpfile = Popen('mktemp', stdout=PIPE).communicate()[0] + f = open(tmpfile, 'w') + f.write(content) + f.close() + return tmpfile def main(): p = OptionParser(version=__version__, @@ -33,23 +47,33 @@ def main(): description=__desc__) options, args = p.parse_args() + tmpfiles = [] if args: - for file in args: - do_upload(file) + for arg in args: + if arg.find('http://') != -1: + tmpdir = Popen(['mktemp', '-d'], stdout=PIPE).communicate()[0] + tmpdir = tmpdir.replace('\n', '') + os.chdir(tmpdir) + tmpfiles.append(tmpdir) + Popen(['wget', '-q', arg]).communicate()[0] + for file in os.listdir(tmpdir): + do_upload(file) + else: + do_upload(arg) else: - if isatty(sys.stdin.fileno()): - print '^C to exit, ^D to send' - try: - content = sys.stdin.read() - except KeyboardInterrupt: - sys.exit() - if not content: - sys.exit() - tmpfile = Popen('mktemp', stdout=PIPE).communicate()[0] - f = open(tmpfile, 'w') - f.write(content) - f.close() + tmpfile = read_stdin() + tmpfiles.append(tmpfile) do_upload(tmpfile) + os.chdir('/tmp') + for path in tmpfiles: + if os.path.isfile(path): + os.remove(path) + else: + for file in os.listdir(path): + os.remove(path+'/'+file) + # FIXME: causes getcwd error + os.rmdir(path) + if __name__ == '__main__': main() -- cgit v1.2.3-24-g4f1b