summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Morris2020-10-19 17:06:47 -0700
committerKevin Morris2020-10-19 17:06:47 -0700
commit5d38f63449a4a287241c116a126eac80a5464c52 (patch)
treeb6e228e38cc82244038c662871adbfc60f58e026
parentce84d6beb63faaf12c58d48b25ab5768ab8577dd (diff)
downloadaur-5d38f63449a4a287241c116a126eac80a5464c52.tar.gz
Remove unused copied script.
Signed-off-by: Kevin Morris <kevr@0cost.org>
-rwxr-xr-xsprunge119
1 files changed, 0 insertions, 119 deletions
diff --git a/sprunge b/sprunge
deleted file mode 100755
index 076b7de795e1..000000000000
--- a/sprunge
+++ /dev/null
@@ -1,119 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: UTF-8 -*-
-# Project: sprunge
-# Author: kevr <kevr@0cost.org>
-# 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
-import argparse
-from subprocess import Popen
-
-## 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
-
-def get_paste(id):
- paste_url = f"http://sprunge.us/{id}"
- request = urllib.request.Request(paste_url)
- reply = urllib.request.urlopen(request, timeout=timeout)
-
- if not reply:
- return 3, "error: no response from '{}'".format(paste_url)
-
- response = reply.read().decode()
- reply.close()
-
- return 0, response.rstrip()
-
-def post_paste(text):
- post_data = urllib.parse.urlencode({ "sprunge": text })
-
- # The actual request process
- request = urllib.request.Request(url, post_data.encode())
- reply = urllib.request.urlopen(request, timeout=timeout)
-
- if not reply:
- return 3, "error: no response from '{}'".format(url)
-
- # Read in the reply socket's data and close it cleanly
- response = reply.read().decode()
- reply.close()
-
- return 0, response.rstrip()
-
-## Sorry for the C-style functions, I prefer them
-def main():
- help_description = "Upload text from stdin to http://sprunge.us. If [id] "
- help_description += "is provided, the corresponding paste is fetched and "
- help_description += "displayed."
- parser = argparse.ArgumentParser(description=help_description)
- parser.add_argument("--clip-command", "-cc",
- metavar="clip_command",
- default="xclip -sel primary",
- help="clipboard pipe command (default: 'xclip -sel primary')")
- parser.add_argument("--clipboard", "-c",
- metavar="clipboard",
- action="store_const",
- const=True,
- default=False,
- help="pipe stdout to --clip-command")
- parser.add_argument("id",
- nargs="?",
- help="when provided, fetches and displays a sprunge paste")
- args = parser.parse_args()
-
- # If [id] was provided by the user.
- if args.id is not None:
- if args.id[:4] == "http" and args.id[:18] != "http://sprunge.us/":
- return quit(1, "error: invalid id provided; "
- + "URLs must begin with 'http://sprunge.us/'")
-
- paste_id = args.id.split("/")[-1]
- if not paste_id:
- return quit(1, "error: no id provided")
-
- return_code, response = get_paste(paste_id)
- if return_code != 0:
- return quit(return_code, response)
- print(response)
- else:
- try:
- stdin = sys.stdin.read()
- except UnicodeDecodeError as exc:
- return quit(2, f"error: {str(exc)}")
-
- if not has_data(sys.stdin):
- return quit(1, "error: no data given via stdin")
-
- return_code, response = post_paste(stdin)
- if return_code != 0:
- return quit(return_code, response)
- print(response)
-
- # If --clipboard was given, additionally use --clipboard-command
- # to save the resulting URL to the clipboard.
- if args.clipboard:
- proc = Popen([
- "/bin/sh", "-c",
- f'echo "{response}" | {args.clip_command}'
- ])
- proc.wait()
-
- return 0
-
-# main execution
-if __name__ == "__main__":
- e = main()
- exit(e)
-