summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorkevr <kevr@nixcode.us>2015-06-08 05:45:20 -0700
committerkevr <kevr@nixcode.us>2015-06-08 05:45:20 -0700
commit18986c2233bb9e1a474d8c8da64d16711e148ed8 (patch)
tree69d29435fca605581ec82a7c2d776873218124f8
downloadaur-18986c2233bb9e1a474d8c8da64d16711e148ed8.tar.gz
Initial import
-rw-r--r--.SRCINFO15
-rw-r--r--PKGBUILD19
-rwxr-xr-xsprunge57
3 files changed, 91 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 0000000..55bdfe8
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,15 @@
+pkgbase = sprunge
+ pkgdesc = Upload data to sprunge.us via stdin
+ pkgver = 0.1.2
+ pkgrel = 1
+ url = https://github.com/kevr/sprunge
+ arch = i686
+ arch = x86_64
+ arch = armv6h
+ license = GPL2
+ depends = python
+ source = sprunge
+ sha256sums = 7c65273804d26a24c1dcda83a559315b9f501013d3d77d7d140f882f05eb2b33
+
+pkgname = sprunge
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 0000000..f5ca67b
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,19 @@
+pkgname='sprunge'
+pkgver='0.1.2'
+pkgrel=1
+pkgdesc='Upload data to sprunge.us via stdin'
+license=('GPL2')
+url='https://github.com/kevr/sprunge'
+
+arch=('i686' 'x86_64' 'armv6h')
+depends=('python')
+source=('sprunge')
+sha256sums=(
+ '7c65273804d26a24c1dcda83a559315b9f501013d3d77d7d140f882f05eb2b33'
+)
+
+package()
+{
+ install -Dm755 "${srcdir}/${pkgname}" "${pkgdir}/usr/bin/${pkgname}"
+}
+
diff --git a/sprunge b/sprunge
new file mode 100755
index 0000000..c0c09df
--- /dev/null
+++ b/sprunge
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+# -*- coding: UTF-8 -*-
+# Project: sprunge
+# Author: kevr <kevr@nixcode.us>
+# Description: A tool which uploads data from stdin to sprunge.us
+# Copyright (C) 2014 Kevin Morris
+import sys
+import urllib.parse
+import urllib.request
+from select import select
+
+## Voila hardcoded settings~
+url = "http://sprunge.us"
+timeout = 5 # Change this to any http request timeout you desire
+
+## Immediately timed out select poll
+def has_data(fd):
+ return select([fd], [], [], 0.0) == ([fd], [], [])
+
+def quit(code, msg):
+ print(msg)
+ return code
+
+## Sorry for the C-style functions, I prefer them
+def main():
+ if not has_data(sys.stdin):
+ return quit(1, "sprunge: no data given via stdin")
+
+ try:
+ stdin = sys.stdin.read()
+ except UnicodeDecodeError:
+ return quit(2, "sprunge: an error occured reading stdin")
+
+ post_data = { "sprunge": stdin }
+ post_data = urllib.parse.urlencode(post_data)
+
+ # The actual request process
+ request = urllib.request.Request(url, post_data.encode("UTF-8"))
+ reply = urllib.request.urlopen(request, timeout=timeout)
+
+ if not reply:
+ return quit(3, "sprunge: no response from '{}'".format(url))
+
+ # Read in the reply socket's data and close it cleanly
+ response = reply.read().decode("UTF-8")
+ reply.close()
+
+ # End the program by printing out sprunge's response
+ print(response.rstrip())
+
+ return 0
+
+# main execution
+if __name__ == "__main__":
+ e = main()
+ exit(e)
+