lol

cups-pdf: misc improvements in package, module, vmtest (#387364)

authored by

Pol Dellaiera and committed by
GitHub
e6999692 6b85d616

+46 -47
+1 -1
nixos/tests/all-tests.nix
··· 368 368 crabfit = handleTest ./crabfit.nix { }; 369 369 cri-o = handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./cri-o.nix { }; 370 370 cryptpad = runTest ./cryptpad.nix; 371 - cups-pdf = handleTest ./cups-pdf.nix { }; 371 + cups-pdf = runTest ./cups-pdf.nix; 372 372 curl-impersonate = handleTest ./curl-impersonate.nix { }; 373 373 custom-ca = handleTest ./custom-ca.nix { }; 374 374 croc = handleTest ./croc.nix { };
+40 -42
nixos/tests/cups-pdf.nix
··· 1 - import ./make-test-python.nix ( 2 - { lib, pkgs, ... }: 3 - { 4 - name = "cups-pdf"; 1 + { hostPkgs, lib, ... }: 2 + { 3 + name = "cups-pdf"; 5 4 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; 24 15 }; 16 + hardware.printers.ensurePrinters = [ 17 + { 18 + name = "noopt"; 19 + model = "CUPS-PDF_noopt.ppd"; 20 + deviceUri = "cups-pdf:/noopt"; 21 + } 22 + ]; 23 + }; 25 24 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 29 28 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 + ''; 44 43 45 - meta.maintainers = [ lib.maintainers.yarny ]; 46 - } 47 - ) 44 + meta.maintainers = [ lib.maintainers.yarny ]; 45 + }
+5 -4
pkgs/by-name/cu/cups-pdf-to-pdf/package.nix
··· 21 21 buildInputs = [ cups ]; 22 22 23 23 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"} ' 25 26 ''; 26 27 27 28 # gcc command line is taken from original cups-pdf's README file ··· 44 45 45 46 passthru.tests.vmtest = nixosTests.cups-pdf; 46 47 47 - meta = with lib; { 48 + meta = { 48 49 description = "CUPS backend that turns print jobs into searchable PDF files"; 49 50 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 ]; 52 53 longDescription = '' 53 54 cups-pdf is a CUPS backend that generates a PDF file for each print job and puts this file 54 55 into a folder on the local machine such that the print job's owner can access the file.