pastebinit: change upstream to maintained fork and add manpage

This commit is contained in:
Samuel-Martineau 2023-11-29 11:30:16 -05:00
parent 38ca32db53
commit 463ec8a215
No known key found for this signature in database
GPG key ID: B39D48310AD30CE4
4 changed files with 41 additions and 104 deletions

View file

@ -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";
};
}

View file

@ -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':

View file

@ -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',

View file

@ -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)