diff options
-rw-r--r-- | ix/PKGBUILD | 19 | ||||
-rw-r--r-- | ix/client | 71 |
2 files changed, 90 insertions, 0 deletions
diff --git a/ix/PKGBUILD b/ix/PKGBUILD new file mode 100644 index 0000000..397e8ca --- /dev/null +++ b/ix/PKGBUILD @@ -0,0 +1,19 @@ +# Contributor: Florian Pritz <f-p@gmx.at> +pkgname=ix +pkgver=0.3 +pkgrel=1 +pkgdesc="client for the ix.io pastebin" +arch=('any') +url="http://ix.io" +license=('NONE') +depends=('python') +source=(http://ix.io/client) + +build() { + cd "$srcdir" + install -D -m755 client $pkgdir/usr/bin/ix +} + +# vim:set ts=2 sw=2 et: +md5sums=('871988a71ced3dd347a39694936f65e4') +sha256sums=('4cac701dd437aba2ec30672e8751c792be1f17a8721018e8e13bdd892c93c60b') diff --git a/ix/client b/ix/client new file mode 100644 index 0000000..1dfd22c --- /dev/null +++ b/ix/client @@ -0,0 +1,71 @@ +#!/usr/bin/env python + +''' [cat |] %prog [-g id | -d id | [-i n1 id1 .. -i nN idN] file1 .. fileN] ''' + +__version__ = '0.3' + +import netrc, os, sys + +def auth(): + ''' netrc: machine ix.io login USERNAME password TOKEN ''' + try: + auth = netrc.netrc().authenticators('ix.io') + except: + return {} + if not auth: + return {} + return {'login' : auth[0], 'token' : auth[2] } + +def mkreq(files, data={}, i=0): + for filename in files: + if filename is sys.stdin: + if os.isatty(sys.stdin.fileno()): + print '^C to exit, ^D to send' + fname, ext = '', '' + try: + contents = sys.stdin.read() + except KeyboardInterrupt: + sys.exit() + if not contents: + sys.exit() + elif os.path.exists(filename): + contents = open(filename).read() + filename, ext = os.path.splitext(filename) + fname = os.path.basename(filename) + else: + continue + i += 1 + data['f:%d' % i] = contents + data['name:%d' % i] = fname + data['ext:%d' % i] = ext + return data + +if __name__ == '__main__': + from optparse import OptionParser + from urllib import urlencode + from urllib2 import urlopen + parser = OptionParser(version=__version__, + usage=__doc__, + description=auth.__doc__) + parser.add_option('-g', '--get', help='get paste identified by ID') + parser.add_option('-d', '--delete', help='delete paste identified by ID') + parser.add_option('-i', '--id', action='append', nargs=2, + help='two params (N, ID) replace paste ID with file N') + opts, args = parser.parse_args() + if opts.get: + print urlopen('http://ix.io/%s' % (opts.get)).read().strip() + else: + if not args: + args = [sys.stdin] + data = auth() + if opts.delete: + data['rm'] = opts.delete + else: + data.update(mkreq(args)) + if opts.id: + for i in opts.id: + try: + data['id:%d' % int(i[0])] = i[1] + except ValueError: + parser.error('invalid file number "%s" in --id option' % i[0]) + print urlopen('http://ix.io', urlencode(data)).read().strip() |