pdf-sign: use makeBinPath instead of patching

This commit is contained in:
TomaSajt 2023-08-20 18:09:25 +02:00
parent 7267429af3
commit 8bd00717e8
No known key found for this signature in database
GPG key ID: F011163C050122A1
2 changed files with 13 additions and 109 deletions

View file

@ -1,17 +1,17 @@
{ lib
, stdenv
, fetchFromGitHub
, substituteAll
, python3
, ghostscript
, coreutils
, pdftk
, poppler_utils
, makeBinaryWrapper
}:
let
python-env = python3.withPackages (ps: with ps; [ tkinter ]);
binPath = lib.makeBinPath [ ghostscript pdftk poppler_utils ];
in
stdenv.mkDerivation {
pname = "pdf-sign";
@ -24,24 +24,20 @@ stdenv.mkDerivation {
hash = "sha256-5GRk0T1iLqmvWI8zvZE3OWEHPS0/zN/Ie9brjZiFpqc=";
};
patches = [
(substituteAll {
src = ./use-nix-paths.patch;
gs = "${ghostscript}/bin/gs";
mv = "${coreutils}/bin/mv";
pdftk = "${pdftk}/bin/pdftk";
pdfinfo = "${poppler_utils}/bin/pdfinfo";
})
];
buildInputs = [ python-env ];
nativeBuildInputs = [ makeBinaryWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp pdf-sign pdf-create-empty $out/bin
patchShebangs $out/bin
mkdir -p $out
cp pdf-sign pdf-create-empty $out
makeWrapper ${python-env}/bin/python $out/bin/pdf-sign \
--add-flags $out/pdf-sign \
--prefix PATH : ${binPath}
makeWrapper ${python-env}/bin/python $out/bin/pdf-create-empty \
--add-flags $out/pdf-create-empty \
--prefix PATH : ${binPath}
runHook postInstall
'';
@ -50,6 +46,7 @@ stdenv.mkDerivation {
description = "A tool to visually sign PDF files";
homepage = "https://github.com/svenssonaxel/pdf-sign";
license = lib.licenses.mit;
mainProgram = "pdf-sign";
maintainers = with lib.maintainers; [ tomasajt ];
platforms = lib.platforms.unix;
};

View file

@ -1,93 +0,0 @@
diff --git a/pdf-create-empty b/pdf-create-empty
index e4768af..5caf34c 100755
--- a/pdf-create-empty
+++ b/pdf-create-empty
@@ -20,7 +20,7 @@ def main(args):
except:
die('Invalid dimensions')
subprocess.run([
- 'gs', '-dBATCH', '-dNOPAUSE', '-dSAFER', '-dQUIET',
+ '@gs@', '-dBATCH', '-dNOPAUSE', '-dSAFER', '-dQUIET',
f'-sOutputFile={o}',
'-sDEVICE=pdfwrite',
f'-dDEVICEWIDTHPOINTS={w}', f'-dDEVICEHEIGHTPOINTS={h}',
diff --git a/pdf-sign b/pdf-sign
index 64be231..37d508d 100755
--- a/pdf-sign
+++ b/pdf-sign
@@ -17,7 +17,7 @@ def main(args):
if args.flatten:
outFile=intmp('input.pdf')
subprocess.run([
- 'pdftk', filePath,
+ '@pdftk@', filePath,
'output', outFile,
'flatten'
], check=True)
@@ -28,7 +28,7 @@ def main(args):
if args.page < -pageCount or args.page==0 or pageCount < args.page:
die('Page number out of range')
pageNumber=Cell(args.page if 0 < args.page else pageCount+args.page+1)
- pagePDF=Cell(lambda: subprocess.run(['pdftk', inputPDF(), 'cat', str(pageNumber()), 'output', intmp('page.pdf')], check=True) and intmp('page.pdf'))
+ pagePDF=Cell(lambda: subprocess.run(['@pdftk@', inputPDF(), 'cat', str(pageNumber()), 'output', intmp('page.pdf')], check=True) and intmp('page.pdf'))
pageSize=Cell(lambda: pdfGetSize(pagePDF()))
# The chosen signature
if not args.signature and args.batch:
@@ -52,7 +52,7 @@ def main(args):
dy=h*(1-signaturePositionY())/resize - sh/2
outFile=intmp('signature-positioned.pdf')
subprocess.run([
- 'gs', '-dBATCH', '-dNOPAUSE', '-dSAFER', '-dQUIET',
+ '@gs@', '-dBATCH', '-dNOPAUSE', '-dSAFER', '-dQUIET',
f'-sOutputFile={outFile}',
'-sDEVICE=pdfwrite',
f'-dDEVICEWIDTHPOINTS={w}', f'-dDEVICEHEIGHTPOINTS={h}', '-dFIXEDMEDIA',
@@ -62,7 +62,7 @@ def main(args):
return outFile
# The signed page
signedPagePDF=Cell(lambda: subprocess.run([
- 'pdftk',
+ '@pdftk@',
pagePDF(),
'stamp', signaturePositionedPDF(),
'output', intmp('signed-page.pdf'),
@@ -80,7 +80,7 @@ def main(args):
(w, h)=displaySize()
outFile=intmp('display.png')
subprocess.run([
- 'gs', '-dBATCH', '-dNOPAUSE', '-dSAFER', '-dQUIET',
+ '@gs@', '-dBATCH', '-dNOPAUSE', '-dSAFER', '-dQUIET',
f'-sOutputFile={outFile}',
'-sDEVICE=pngalpha',
'-dMaxBitmap=2147483647',
@@ -258,7 +258,7 @@ def main(args):
if args.existing=='backup':
backupFilePath=f'{signedFilePath}.backup{time.strftime("%Y%m%d_%H%M%S")}'
subprocess.run([
- 'mv',
+ '@mv@',
signedFilePath,
backupFilePath,
], check=True)
@@ -269,7 +269,7 @@ def main(args):
assert args.existing=='overwrite'
pnr=pageNumber()
subprocess.run([
- 'pdftk',
+ '@pdftk@',
f'A={inputPDF()}',
f'B={signedPagePDF()}',
'cat',
@@ -352,10 +352,10 @@ def tkthrottle(frequency, root):
return decorator
def pdfCountPages(filePath):
- return int(fromCmdOutput(["pdfinfo", filePath], "^.*\nPages: +([0-9]+)\n.*$")[1])
+ return int(fromCmdOutput(["@pdfinfo@", filePath], "^.*\nPages: +([0-9]+)\n.*$")[1])
def pdfGetSize(filePath):
- [ignored, w, h, *ignored2]=fromCmdOutput(['pdfinfo', filePath], '^.*\nPage size: +([0-9.]+) x ([0-9.]+) pts( \([A-Za-z0-9]+\))?\n.*$')
+ [ignored, w, h, *ignored2]=fromCmdOutput(['@pdfinfo@', filePath], '^.*\nPage size: +([0-9.]+) x ([0-9.]+) pts( \([A-Za-z0-9]+\))?\n.*$')
return (float(w), float(h))
def m(pattern, string):