branch: externals/scanner commit 5fd67b523d18c5cbd2d2b7eb486399b0acea5624 Author: Raffael Stocker <r.stoc...@mnet-mail.de> Commit: Raffael Stocker <r.stoc...@mnet-mail.de>
remove old -args functions The old -args functions are now replaced by scanner--program-args: * scanner.el (scanner--scanimage-args): removed (scanner--tesseract-args): removed --- scanner-test.el | 129 +++++++++++--------------------------------------------- scanner.el | 65 ++++++++++------------------ 2 files changed, 47 insertions(+), 147 deletions(-) diff --git a/scanner-test.el b/scanner-test.el index 46645c99c6..b8b5fd0891 100644 --- a/scanner-test.el +++ b/scanner-test.el @@ -50,135 +50,54 @@ (require 'dash) (require 'ert) -(ert-deftest scanner-test-scanimage-args () - "Test the argument list construction for scanimage." - ;; minimum args list (no device-specific options are available) - (let ((switches nil) - (scanner-device-name "devname") - (scanner-image-size '(200 250)) - (-compare-fn #'string=)) - ;; known values are included with their switches - (should (-is-infix-p '("-d" "devname") (scanner--scanimage-args :image - switches - "jpeg"))) - (should (-contains-p (scanner--scanimage-args :image switches "jpeg") - "--format=jpeg")) - ;; device-specific options are not included in the argument list - (should-not (-contains-p (scanner--scanimage-args :image switches "jpeg") - "--mode")) - (should-not (-contains-p (scanner--scanimage-args :image switches "jpeg") "--resolution")) - (should-not (-contains-p (scanner--scanimage-args :image switches "jpeg") - "-x")) - (should-not (-contains-p (scanner--scanimage-args :image switches "jpeg") - "-y")) - (should-not (-contains-p (scanner--scanimage-args :doc switches "jpeg") - "-x")) - (should-not (-contains-p (scanner--scanimage-args :doc switches "jpeg") - "-y")) - ;; without format and device name, these are not in the args list - (let ((scanner-image-format nil) - (scanner-device-name nil)) - (should-not (-contains-p (scanner--scanimage-args :image switches "jpeg") - "--format=")) - (should-not (-contains-p (scanner--scanimage-args :image switches "jpeg") - "-d")))) - ;; image args list with device-specific args - (let ((switches '("--resolution" "-x" "-y" "--mode")) - (scanner-resolution '(:doc 300 :image 600)) - (scanner-scan-mode '(:image "Color" :doc "Gray")) - (scanner-doc-papersize :a4) - (scanner-paper-sizes '(:a4 (210 297))) - (scanner-image-size '(200 250)) - (scanner-image-format '(:doc "pnm" :image "tiff")) - (-compare-fn #'string=)) - (should (-contains-p (scanner--scanimage-args :image switches "jpeg") - "--format=jpeg")) - (should (-contains-p (scanner--scanimage-args :image switches "jpeg") - "--mode=Color")) - (should (-contains-p (scanner--scanimage-args :image switches "jpeg") - "--resolution=600")) - (should (-is-infix-p '("-x" "210") (scanner--scanimage-args :doc - switches "jpeg"))) - (should (-is-infix-p '("-y" "297") (scanner--scanimage-args :doc - switches "jpeg"))) - (should (-is-infix-p '("-x" "200") (scanner--scanimage-args :image - switches "jpeg"))) - (should (-is-infix-p '("-y" "250") (scanner--scanimage-args :image - switches "jpeg"))) - (should (-contains-p (scanner--scanimage-args :doc switches "jpeg") - "--format=pnm")) - (should (-contains-p (scanner--scanimage-args :doc switches "jpeg") - "--mode=Gray")) - (should (-contains-p (scanner--scanimage-args :doc switches "jpeg") - "--resolution=300")) - (let ((scanner-image-size nil)) - (should-not (-contains-p (scanner--scanimage-args :image - switches "jpeg") - "-x")) - (should-not (-contains-p (scanner--scanimage-args :image - switches "jpeg") - "-y"))) - (let ((scanner-doc-papersize :whatever)) - (should-not (-contains-p (scanner--scanimage-args :doc - switches "jpeg") - "-x")) - (should-not (-contains-p (scanner--scanimage-args :doc - switches "jpeg") - "-y"))))) (ert-deftest scanner-test-make-scanimage-command () "Test the scanimage command construction." (let ((scanner--scanimage-version-o-switch "0")) (should (-is-infix-p '("-o" "outfile") (scanner--make-scanimage-command - (scanner--scanimage-args :doc nil "pnm") + (scanner--program-args + scanner--scanimage-argspec + :scan-type :doc :img-fmt "pnm" + :device-dependent nil) "outfile"))) (should-not (-is-infix-p (list shell-file-name shell-command-switch) (scanner--make-scanimage-command - (scanner--scanimage-args :doc nil "pnm") + (scanner--program-args + scanner--scanimage-argspec + :scan-type :doc :img-fmt "pnm" + :device-dependent nil) "outfile"))) (should-not (string-match " > outfile\\'" (car (last (scanner--make-scanimage-command - (scanner--scanimage-args :doc nil "pnm") + (scanner--program-args + scanner--scanimage-argspec + :scan-type :doc :img-fmt "pnm" + :device-dependent nil) "outfile")))))) (let ((scanner--scanimage-version-o-switch "10")) (should-not (-is-infix-p '("-o" "outfile") (scanner--make-scanimage-command - (scanner--scanimage-args :doc nil "pnm") + (scanner--program-args + scanner--scanimage-argspec + :scan-type :doc :img-fmt "pnm" + :device-dependent nil) "outfile"))) (should (-is-infix-p (list shell-file-name shell-command-switch) (scanner--make-scanimage-command - (scanner--scanimage-args :doc nil "pnm") + (scanner--program-args + scanner--scanimage-argspec + :scan-type :doc :img-fmt "pnm" + :device-dependent nil) "outfile"))) (should (string-match " > outfile\\'" (car (last (scanner--make-scanimage-command - (scanner--scanimage-args :doc nil "pnm") + (scanner--program-args + scanner--scanimage-argspec + :scan-type :doc :img-fmt "pnm" + :device-dependent nil) "outfile"))))))) -(ert-deftest scanner-test-tesseract-args () - "Test the argument list construction for tesseract." - (let ((scanner-resolution '(:image 600 :doc 300)) - (scanner-tesseract-languages '("eng" "deu")) - (scanner-tesseract-switches '("--opt1" "--opt2")) - (scanner-tesseract-outputs '("out1" "out2")) - (scanner-tessdata-dir "/usr/share/tessdata/") - (-compare-fn #'string=)) - (should (-is-infix-p '("-l" "eng+deu") (scanner--tesseract-args "infile" - "outfile"))) - (let ((scanner--tesseract-version-dpi-switch "0")) - (should (-is-infix-p '("--dpi" "300") (scanner--tesseract-args "infile" - "outfile")))) - (let ((scanner--tesseract-version-dpi-switch "1000")) - (should-not (-is-infix-p '("--dpi" "300") (scanner--tesseract-args "infile" - "outfile")))) - (should (-contains-p (scanner--tesseract-args "infile" "outfile") "--opt1")) - (should (-contains-p (scanner--tesseract-args "infile" "outfile") "--opt2")) - (should (-contains-p (scanner--tesseract-args "infile" "outfile") "infile")) - (should (-contains-p (scanner--tesseract-args "infile" "outfile") "outfile")) - (should (-contains-p (scanner--tesseract-args "infile" "outfile") "out1")) - (should (-contains-p (scanner--tesseract-args "infile" "outfile") "out2")) - (should (-is-infix-p '("--tessdata-dir" "/usr/share/tessdata/") - (scanner--tesseract-args "infile" "outfile"))))) ;; Note: interactive commands are only tested for their non-interactive ;; behavior diff --git a/scanner.el b/scanner.el index 5d3e996ad2..92a0aaeaa4 100644 --- a/scanner.el +++ b/scanner.el @@ -419,10 +419,9 @@ configured, return nil." (defvar scanner--scanimage-argspec (list "-d" 'scanner-device-name "--format=" (lambda (args) - (if (eq :doc (plist-get args :scan-type)) - (plist-get scanner-image-format :doc) - (or (plist-get args :img-fmt) - (plist-get scanner-image-format :image)))) + (or (plist-get args :img-fmt) + (plist-get scanner-image-format + (plist-get args :scan-type)))) "--mode=" (lambda (args) (scanner--when-switch "--mode" args (plist-get scanner-scan-mode @@ -477,20 +476,6 @@ translated into the arguments list: (process-argspec (cddr spec)))))) (-flatten (process-argspec argspec)))) -(defun scanner--scanimage-args (scan-type switches img-fmt) - "Construct the argument list for scanimage(1). -SCAN-TYPE is either ‘:image’ or ‘:doc’, SWITCHES is a list of -available device-dependent options and IMG-FMT is the output -image format. - -When scanning documents (scan-type :doc), scanner uses the IMG-FMT -argument for the intermediate representation before conversion to -the document format. If any of the required options from -‘scanner--device-specific-switches’ are unavailable, they are -simply dropped." - (scanner--program-args scanner--scanimage-argspec :img-fmt img-fmt - :scan-type scan-type :device-dependent switches)) - (defun scanner--program-version (program version-switch) "Determine the version of PROGRAM using VERSION-SWITCH." (condition-case err @@ -510,11 +495,12 @@ simply dropped." ;; once everyone has caught up. (defun scanner--make-scanimage-command (args outfile) "Make the scanimage command using ARGS and OUTFILE. -The arguments list ARGS should be supplied by ‘scanner--scanimage-args’ and -the output file name is given by OUTFILE. -This function checks the installed version of scanimage(1) and -returns a command directly callable by ‘make-process’. For old versions of -scanimage this will construct a shell command." +The arguments list ARGS should be supplied by +‘scanner--program-args’ and the output file name is given by +OUTFILE. This function checks the installed version of +scanimage(1) and returns a command directly callable by +‘make-process’. For old versions of scanimage this will +construct a shell command." (if (version< (scanner--program-version scanner-scanimage-program "-V") scanner--scanimage-version-o-switch) (list shell-file-name @@ -545,14 +531,6 @@ scanimage this will construct a shell command." 'outputs 'scanner-tesseract-outputs) "The arguments list specification for tesseract.") -(defun scanner--tesseract-args (input output-base) - "Construct the argument list for ‘tesseract(1)’. -INPUT is the input file name, OUTPUT-BASE is the basename for the -output files. Note that tesseract automatically adds file name -extensions depending on the selected output options, see -‘scanner-tesseract-outputs’." - (scanner--program-args scanner--tesseract-argspec :input input - :output output-base)) (defun scanner--ensure-init () "Ensure that scanning device is initialized. @@ -744,9 +722,11 @@ performing OCR." (number-to-string (cl-incf page-num)) "." fmt)) - (scanimage-args (scanner--scanimage-args :doc - switches - fmt)) + (scanimage-args (scanner--program-args + scanner--scanimage-argspec + :scan-type :doc + :img-type fmt + :device-dependent switches)) (scanimage-command (scanner--make-scanimage-command scanimage-args img-file))) (push img-file file-list) @@ -794,8 +774,9 @@ performing OCR." (mapconcat #'identity file-list "\n"))) - (let ((tesseract-args (scanner--tesseract-args fl-file - doc-file))) + (let ((tesseract-args (scanner--program-args + scanner--tesseract-argspec + :input fl-file :output doc-file))) (scanner--log (format "tesseract arguments: %s" tesseract-args)) (make-process :name "Scanner (tesseract)" @@ -852,9 +833,7 @@ available, ask for a selection interactively." (page-count 1)) (cl-labels ((scanimage (multi-scan) - (let* ((img-fmt (or derived-fmt - (plist-get scanner-image-format :image))) - (img-ext (if derived-fmt + (let* ((img-ext (if derived-fmt (file-name-extension filename t) (concat "." (plist-get scanner-image-format @@ -869,9 +848,11 @@ available, ask for a selection interactively." img-ext) (cl-incf page-count)) (concat img-base img-ext))) - (scanimage-args (scanner--scanimage-args :image - switches - img-fmt)) + (scanimage-args (scanner--program-args + scanner--scanimage-argspec + :img-fmt derived-fmt + :scan-type :image + :device-dependent switches)) (scanimage-command (scanner--make-scanimage-command scanimage-args img-file))) (when (scanner--confirm-filenames img-file)