summaryrefslogtreecommitdiffstats
path: root/fb
diff options
context:
space:
mode:
authorFlorian Pritz <f-p@gmx.at>2009-07-13 23:42:32 +0200
committerFlorian Pritz <f-p@gmx.at>2009-07-13 23:42:32 +0200
commitb28fb3f95238b44d6b88979e01cc60588eee6360 (patch)
tree9e11f21ddcac2af0b1672016cca2523fe44454b8 /fb
parent6b6f3664fb58265bc51ddcddc3b9bee1fde5a0ec (diff)
downloadbin-b28fb3f95238b44d6b88979e01cc60588eee6360.tar.gz
bin-b28fb3f95238b44d6b88979e01cc60588eee6360.tar.xz
fb now supports http:// mirroring
Diffstat (limited to 'fb')
-rwxr-xr-xfb56
1 files changed, 40 insertions, 16 deletions
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()