From 463ec8a215dc4f7cdaa2132ba33d68e9ab044105 Mon Sep 17 00:00:00 2001 From: Samuel-Martineau Date: Wed, 29 Nov 2023 11:30:16 -0500 Subject: [PATCH] pastebinit: change upstream to maintained fork and add manpage --- pkgs/tools/misc/pastebinit/default.nix | 52 ++++++++------- .../misc/pastebinit/use-distro-module.patch | 14 ---- pkgs/tools/misc/pastebinit/use-drv-etc.patch | 13 ++++ .../misc/pastebinit/use-urllib-request.patch | 66 ------------------- 4 files changed, 41 insertions(+), 104 deletions(-) delete mode 100644 pkgs/tools/misc/pastebinit/use-distro-module.patch create mode 100644 pkgs/tools/misc/pastebinit/use-drv-etc.patch delete mode 100644 pkgs/tools/misc/pastebinit/use-urllib-request.patch diff --git a/pkgs/tools/misc/pastebinit/default.nix b/pkgs/tools/misc/pastebinit/default.nix index 461e9c9c87fc..ba597934ebbe 100644 --- a/pkgs/tools/misc/pastebinit/default.nix +++ b/pkgs/tools/misc/pastebinit/default.nix @@ -1,51 +1,55 @@ { lib , stdenv -, fetchurl -, fetchpatch +, fetchFromGitHub , python3 +, libxslt +, docbook_xsl +, installShellFiles +, callPackage }: stdenv.mkDerivation rec { - version = "1.5"; + version = "1.6.2"; pname = "pastebinit"; - src = fetchurl { - url = "https://launchpad.net/pastebinit/trunk/${version}/+download/${pname}-${version}.tar.bz2"; - sha256 = "0mw48fgm9lyh9d3pw997fccmglzsjccf2y347gxjas74wx6aira2"; + src = fetchFromGitHub { + owner = pname; + repo = pname; + rev = version; + hash = "sha256-vuAWkHlQM6QTWarThpSbY0qrxzej0GvLU0jT2JOS/qc="; }; + patches = [ + ./use-drv-etc.patch + ]; + + nativeBuildInputs = [ + libxslt + installShellFiles + ]; + buildInputs = [ (python3.withPackages (p: [ p.distro ])) ]; - patchFlags = [ "-p0" ]; - - patches = [ - # Required to allow pastebinit 1.5 to run on Python 3.8 - ./use-distro-module.patch - # Required to remove the deprecation warning of FancyURLopener - ./use-urllib-request.patch - # Required because pastebin.com now redirects http requests to https - (fetchpatch { - name = "pastebin-com-https.patch"; - url = "https://bazaar.launchpad.net/~arnouten/pastebinit/pastebin-com-https/diff/264?context=3"; - sha256 = "0hxhhfcai0mll8qfyhdl3slmbf34ynb759b648x63274m9nd2kji"; - }) - ]; + buildPhase = '' + xsltproc --nonet ${docbook_xsl}/xml/xsl/docbook/manpages/docbook.xsl pastebinit.xml + ''; installPhase = '' mkdir -p $out/bin mkdir -p $out/etc cp -a pastebinit $out/bin + cp -a utils/* $out/bin cp -a pastebin.d $out/etc - substituteInPlace $out/bin/pastebinit --replace "'/etc/pastebin.d" "'$out/etc/pastebin.d" + substituteInPlace $out/bin/pastebinit --subst-var-by "etc" "$out/etc" + installManPage pastebinit.1 ''; meta = with lib; { - homepage = "https://launchpad.net/pastebinit"; + homepage = "https://stgraber.org/category/pastebinit/"; description = "A software that lets you send anything you want directly to a pastebin from the command line"; - maintainers = with maintainers; [ raboof ]; + maintainers = with maintainers; [ raboof samuel-martineau ]; license = licenses.gpl2; platforms = platforms.linux ++ lib.platforms.darwin; - mainProgram = "pastebinit"; }; } diff --git a/pkgs/tools/misc/pastebinit/use-distro-module.patch b/pkgs/tools/misc/pastebinit/use-distro-module.patch deleted file mode 100644 index 0e5dbf7860ae..000000000000 --- a/pkgs/tools/misc/pastebinit/use-distro-module.patch +++ /dev/null @@ -1,14 +0,0 @@ -=== modified file 'pastebinit' ---- pastebinit 2018-07-04 00:46:08 +0000 -+++ pastebinit 2020-11-13 14:21:11 +0000 -@@ -38,8 +38,8 @@ - - # Now try to override it with a distributor pastebin - try: -- import platform -- release = platform.linux_distribution()[0].lower() -+ import distro -+ release = distro.id() - if release == 'debian': - defaultPB = "paste.debian.net" - elif release == 'fedora': diff --git a/pkgs/tools/misc/pastebinit/use-drv-etc.patch b/pkgs/tools/misc/pastebinit/use-drv-etc.patch new file mode 100644 index 000000000000..6ccd7897ddf2 --- /dev/null +++ b/pkgs/tools/misc/pastebinit/use-drv-etc.patch @@ -0,0 +1,13 @@ +diff --git a/pastebinit b/pastebinit +index 4e5f9ce..fe06bd3 100755 +--- a/pastebinit ++++ b/pastebinit +@@ -91,7 +91,7 @@ try: + # Files found later override files found earlier. + pastebind = {} + confdirs = [] +- for confdir in ['/usr/share', '/usr/local/share'] \ ++ for confdir in ['@etc@', '/usr/share', '/usr/local/share'] \ + + list(reversed(os.environ.get('XDG_DATA_DIRS', '').split(':'))) \ + + list(reversed(os.environ.get('XDG_CONFIG_DIRS', '').split(':'))) \ + + ['/etc', '/usr/local/etc', diff --git a/pkgs/tools/misc/pastebinit/use-urllib-request.patch b/pkgs/tools/misc/pastebinit/use-urllib-request.patch deleted file mode 100644 index f379fd0651db..000000000000 --- a/pkgs/tools/misc/pastebinit/use-urllib-request.patch +++ /dev/null @@ -1,66 +0,0 @@ -=== modified file 'pastebinit' ---- pastebinit 2018-07-04 00:46:08 +0000 -+++ pastebinit 2020-11-13 14:21:11 +0000 -@@ -23,15 +23,9 @@ - from __future__ import print_function - - import sys --if sys.version[0] == "2": -- from ConfigParser import NoOptionError -- from ConfigParser import SafeConfigParser as ConfigParser -- from urllib import urlencode -- from urllib import FancyURLopener --else: -- from configparser import ConfigParser, NoOptionError -- from urllib.parse import urlencode -- from urllib.request import FancyURLopener -+from configparser import ConfigParser, NoOptionError -+from urllib.parse import urlencode -+from urllib.request import urlopen, Request - - # Set the default pastebin - defaultPB = "pastebin.com" -@@ -72,13 +66,6 @@ try: - version = "1.5" - configfile = os.path.expanduser("~/.pastebinit.xml") - -- # Custom urlopener to handle 401's -- class pasteURLopener(FancyURLopener): -- version = "Pastebinit v%s" % version -- -- def http_error_401(self, url, fp, errcode, errmsg, headers, data=None): -- return None -- - def preloadPastebins(): - # Check several places for config files: - # - global config in /etc/pastebin.d -@@ -410,12 +397,18 @@ try: - else: - post_format = 'standard' - -- url_opener = pasteURLopener() -+ request = Request( -+ fetch_url, -+ method="POST", -+ headers={ -+ 'User-Agent': "Pastebinit v%s" % version -+ } -+ ) - - if post_format == 'json': - if json: - params = json.dumps(params) -- url_opener.addheader('Content-type', 'text/json') -+ request.add_header('Content-type', 'text/json') - else: - print(_("Could not find any json library."), file=sys.stderr) - sys.exit(1) -@@ -428,7 +421,7 @@ try: - print("POSTing to: %s\nParams: %s" % ( - fetch_url, str(params)), file=sys.stderr) - try: -- page = url_opener.open(fetch_url, params) -+ page = urlopen(request, params.encode("utf-8")) - except Exception as e: - print(_("Failed to contact the server: %s") % e, file=sys.stderr) - sys.exit(1)