Skip to content

Commit e699969

Browse files
authored
cups-pdf: misc improvements in package, module, vmtest (#387364)
2 parents 6b85d61 + ce5e427 commit e699969

File tree

3 files changed

+46
-47
lines changed

3 files changed

+46
-47
lines changed

nixos/tests/all-tests.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ in
368368
crabfit = handleTest ./crabfit.nix { };
369369
cri-o = handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./cri-o.nix { };
370370
cryptpad = runTest ./cryptpad.nix;
371-
cups-pdf = handleTest ./cups-pdf.nix { };
371+
cups-pdf = runTest ./cups-pdf.nix;
372372
curl-impersonate = handleTest ./curl-impersonate.nix { };
373373
custom-ca = handleTest ./custom-ca.nix { };
374374
croc = handleTest ./croc.nix { };

nixos/tests/cups-pdf.nix

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
1-
import ./make-test-python.nix (
2-
{ lib, pkgs, ... }:
3-
{
4-
name = "cups-pdf";
1+
{ hostPkgs, lib, ... }:
2+
{
3+
name = "cups-pdf";
54

6-
nodes.machine =
7-
{ pkgs, ... }:
8-
{
9-
imports = [ ./common/user-account.nix ];
10-
environment.systemPackages = [ pkgs.poppler-utils ];
11-
fonts.packages = [ pkgs.dejavu_fonts ]; # yields more OCR-able pdf
12-
services.printing.cups-pdf.enable = true;
13-
services.printing.cups-pdf.instances = {
14-
opt = { };
15-
noopt.installPrinter = false;
16-
};
17-
hardware.printers.ensurePrinters = [
18-
{
19-
name = "noopt";
20-
model = "CUPS-PDF_noopt.ppd";
21-
deviceUri = "cups-pdf:/noopt";
22-
}
23-
];
5+
nodes.machine =
6+
{ pkgs, ... }:
7+
{
8+
imports = [ ./common/user-account.nix ];
9+
environment.systemPackages = [ pkgs.poppler-utils ];
10+
fonts.packages = [ pkgs.dejavu_fonts ]; # yields more OCR-able pdf
11+
services.printing.cups-pdf.enable = true;
12+
services.printing.cups-pdf.instances = {
13+
opt = { };
14+
noopt.installPrinter = false;
2415
};
16+
hardware.printers.ensurePrinters = [
17+
{
18+
name = "noopt";
19+
model = "CUPS-PDF_noopt.ppd";
20+
deviceUri = "cups-pdf:/noopt";
21+
}
22+
];
23+
};
2524

26-
# we cannot check the files with pdftotext, due to
27-
# https://github.com/alexivkin/CUPS-PDF-to-PDF/issues/7
28-
# we need `imagemagickBig` as it has ghostscript support
25+
# we cannot check the files with pdftotext, due to
26+
# https://github.com/alexivkin/CUPS-PDF-to-PDF/issues/7
27+
# we need `imagemagickBig` as it has ghostscript support
2928

30-
testScript = ''
31-
from subprocess import run
32-
machine.wait_for_unit("multi-user.target")
33-
for name in ("opt", "noopt"):
34-
text = f"test text {name}".upper()
35-
machine.wait_until_succeeds(f"lpstat -v {name}")
36-
machine.succeed(f"su - alice -c 'echo -e \"\n {text}\" | lp -d {name}'")
37-
# wait until the pdf files are completely produced and readable by alice
38-
machine.wait_until_succeeds(f"su - alice -c 'pdfinfo /var/spool/cups-pdf-{name}/users/alice/*.pdf'")
39-
machine.succeed(f"cp /var/spool/cups-pdf-{name}/users/alice/*.pdf /tmp/{name}.pdf")
40-
machine.copy_from_vm(f"/tmp/{name}.pdf", "")
41-
run(f"${pkgs.imagemagickBig}/bin/convert -density 300 $out/{name}.pdf $out/{name}.jpeg", shell=True, check=True)
42-
assert text.encode() in run(f"${lib.getExe pkgs.tesseract} $out/{name}.jpeg stdout", shell=True, check=True, capture_output=True).stdout
43-
'';
29+
testScript = ''
30+
from subprocess import run
31+
machine.wait_for_unit("multi-user.target")
32+
for name in ("opt", "noopt"):
33+
text = f"test text {name}".upper()
34+
machine.wait_until_succeeds(f"lpstat -v {name}")
35+
machine.succeed(f"su - alice -c 'echo -e \"\n {text}\" | lp -d {name}'")
36+
# wait until the pdf files are completely produced and readable by alice
37+
machine.wait_until_succeeds(f"su - alice -c 'pdfinfo /var/spool/cups-pdf-{name}/users/alice/*.pdf'")
38+
machine.succeed(f"cp /var/spool/cups-pdf-{name}/users/alice/*.pdf /tmp/{name}.pdf")
39+
machine.copy_from_vm(f"/tmp/{name}.pdf", "")
40+
run(f"${lib.getExe hostPkgs.imagemagickBig} -density 300 $out/{name}.pdf $out/{name}.jpeg", shell=True, check=True)
41+
assert text.encode() in run(f"${lib.getExe hostPkgs.tesseract} $out/{name}.jpeg stdout", shell=True, check=True, capture_output=True).stdout
42+
'';
4443

45-
meta.maintainers = [ lib.maintainers.yarny ];
46-
}
47-
)
44+
meta.maintainers = [ lib.maintainers.yarny ];
45+
}

pkgs/by-name/cu/cups-pdf-to-pdf/package.nix

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ stdenv.mkDerivation {
2121
buildInputs = [ cups ];
2222

2323
postPatch = ''
24-
sed -r 's|(gscall, size, ")cp |\1${coreutils}/bin/cp |' cups-pdf.c -i
24+
substituteInPlace cups-pdf.c \
25+
--replace-fail '"cp ' '"${lib.getExe' coreutils "cp"} '
2526
'';
2627

2728
# gcc command line is taken from original cups-pdf's README file
@@ -44,11 +45,11 @@ stdenv.mkDerivation {
4445

4546
passthru.tests.vmtest = nixosTests.cups-pdf;
4647

47-
meta = with lib; {
48+
meta = {
4849
description = "CUPS backend that turns print jobs into searchable PDF files";
4950
homepage = "https://github.com/alexivkin/CUPS-PDF-to-PDF";
50-
license = licenses.gpl2Only;
51-
maintainers = [ maintainers.yarny ];
51+
license = lib.licenses.gpl2Only;
52+
maintainers = [ lib.maintainers.yarny ];
5253
longDescription = ''
5354
cups-pdf is a CUPS backend that generates a PDF file for each print job and puts this file
5455
into a folder on the local machine such that the print job's owner can access the file.

0 commit comments

Comments
 (0)