braille: Checking for tool presence
PATCH 1/1 braille: Checking for tool presence
Hello,
The attached patch makes the braille support check for tool presence, so that cups nicely tells the user what is missing, allowing distributions to relax package dependencies.
Samuel
=== modified file 'filter/braille/filters/cups-braille.sh.in'
braille/filters/cups-braille.sh.in +15 -1
@@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2016 Samuel Thibault <[email protected]> +# Copyright (c) 2015-2016 Samuel Thibault <[email protected]> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal
@@ -228,3 +228,17 @@ echo "DEBUG: Table4 $LIBLOUIS4" >&2 [ "$LIBLOUIS2" != None ] && LIBLOUIS_TABLES="${LIBLOUIS_TABLES:+$LIBLOUIS_TABLES,}$LIBLOUIS2" [ "$LIBLOUIS3" != None ] && LIBLOUIS_TABLES="${LIBLOUIS_TABLES:+$LIBLOUIS_TABLES,}$LIBLOUIS3" [ "$LIBLOUIS4" != None ] && LIBLOUIS_TABLES="${LIBLOUIS_TABLES:+$LIBLOUIS_TABLES,}$LIBLOUIS4" + +# +# Checking for presence of tools +# +checkTool() { + TOOL=$1 + PACKAGE=$2 + USE=$3 + if ! type $TOOL + then + printf "ERROR: The $PACKAGE package is required for $USE\n" >&2 + exit 1 + fi +}
=== modified file 'filter/braille/filters/imagetobrf.in'
braille/filters/imagetobrf.in +3 -1
@@ -1,7 +1,7 @@ #!/bin/bash # -# Copyright (c) 2015-2016 Samuel Thibault <[email protected]> +# Copyright (c) 2015-2016 Samuel Thibault <[email protected]> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal
@@ -42,6 +42,8 @@ esac . @CUPS_DATADIR@/braille/cups-braille.sh +checkTool convert imagemagick "embossing images" + NEGATE=$(getOption Negate) case "$NEGATE" in True) NEGATE=-negate ;;
=== modified file 'filter/braille/filters/texttobrf.in'
braille/filters/texttobrf.in +12 -1
@@ -1,7 +1,7 @@ #!/bin/bash # -# Copyright (c) 2015-2016 Samuel Thibault <[email protected]> +# Copyright (c) 2015-2016 Samuel Thibault <[email protected]> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal
@@ -57,6 +57,8 @@ echo "DEBUG: Input content type: $CONTEN # Selected braille table if [ -n "$LIBLOUIS_TABLES" ] then + checkTool file2brl liblouis "translating braille" + # Tool to be used for the conversion # FIXME CONTENT_TYPE contains original document, not document passed as parameter ?!! case $CONTENT_TYPE in
@@ -75,18 +77,22 @@ then application/msword) LIBLOUIS_TOOL="file2brl" CONVERT="antiword -x db /dev/stdin" + checkTool antiword antiword "translating MS-Word doc files" ;; application/vnd.openxmlformats-officedocument.wordprocessingml.document) LIBLOUIS_TOOL="file2brl" CONVERT="docx2txt" + checkTool docx2txt docx2txt "translating MS-Word docx files" ;; text/rtf|application/rtf) LIBLOUIS_TOOL="file2brl" CONVERT="rtf2xml /dev/stdin" + checkTool rtf2xml rtf2xml "translating RTF files" ;; application/pdf) LIBLOUIS_TOOL="file2brl -p" CONVERT="pdftotext -raw /dev/stdin /dev/stdout" + checkTool pdftotext poppler "translating PDF files" ;; *) echo "ERROR: unsupported content type $CONTENT_TYPE" >&2
@@ -107,18 +113,23 @@ else text/html) CONVERT="" RENDER_CALL="lynx -width=$TEXTWIDTH -dump -stdin" + checkTool lynx lynx "translating html files" ;; application/msword) CONVERT="antiword /dev/stdin" + checkTool antiword antiword "translating MS-Word doc files" ;; application/vnd.openxmlformats-officedocument.wordprocessingml.document) CONVERT="docx2txt" + checkTool docx2txt docx2txt "translating MS-Word docx files" ;; text/rtf|application/rtf) CONVERT="rtf2txt /dev/stdin" + checkTool rtf2txt rtf2txt "translating RTF files" ;; application/pdf) CONVERT="pdftotext -raw /dev/stdin /dev/stdout" + checkTool pdftotext poppler "translating PDF files" ;; *) echo "ERROR: unsupported content type $CONTENT_TYPE" >&2
Quoted 7 lines · Samuel Thibault
Hello,
The attached patch makes the braille support check for tool presence, so that cups nicely tells the user what is missing, allowing distributions to relax package dependencies.
Samuel
Thank you for the patch. I have applied it to the BZR repository now.
Till
The attached patch makes cups-filter able to use lou_translate from liblouis-bin (and warn about that) when file2brl from liblouisutdml-bin is not available.
Samuel
=== modified file 'filter/braille/filters/texttobrf.in'
braille/filters/texttobrf.in +67 -48
@@ -54,58 +54,13 @@ fi echo "DEBUG: Input content type: $CONTENT_TYPE" >&2 -# Selected braille table -if [ -n "$LIBLOUIS_TABLES" ] -then - checkTool file2brl liblouis "translating braille" +# FIXME CONTENT_TYPE contains original document, not document passed as parameter ?!! - # Tool to be used for the conversion - # FIXME CONTENT_TYPE contains original document, not document passed as parameter ?!! - case $CONTENT_TYPE in - text/plain) - LIBLOUIS_TOOL="file2brl" - CONVERT="" - ;; - text/html) - LIBLOUIS_TOOL="file2brl -t" - CONVERT="" - ;; - text/xml|application/xml|application/xhtml+xml) - LIBLOUIS_TOOL="file2brl" - CONVERT="" - ;; - application/msword) - LIBLOUIS_TOOL="file2brl" - CONVERT="antiword -x db /dev/stdin" - checkTool antiword antiword "translating MS-Word doc files" - ;; - application/vnd.openxmlformats-officedocument.wordprocessingml.document) - LIBLOUIS_TOOL="file2brl" - CONVERT="docx2txt" - checkTool docx2txt docx2txt "translating MS-Word docx files" - ;; - text/rtf|application/rtf) - LIBLOUIS_TOOL="file2brl" - CONVERT="rtf2xml /dev/stdin" - checkTool rtf2xml rtf2xml "translating RTF files" - ;; - application/pdf) - LIBLOUIS_TOOL="file2brl -p" - CONVERT="pdftotext -raw /dev/stdin /dev/stdout" - checkTool pdftotext poppler "translating PDF files" - ;; - *) - echo "ERROR: unsupported content type $CONTENT_TYPE" >&2 - exit 1 - ;; - esac - RENDER_CALL="$LIBLOUIS_TOOL -CliteraryTextTable=$LIBLOUIS_TABLES,braille-patterns.cti $LIBLOUIS_CONFIG" -else +setupTextRendering() { # Default rendering without translation: just reformat paragraphs RENDER_CALL="fmt -$TEXTWIDTH" # Tool to be used for the conversion - # FIXME CONTENT_TYPE contains original document, not document passed as parameter ?!! case $CONTENT_TYPE in text/plain) CONVERT=""
@@ -136,6 +91,66 @@ else exit 1 ;; esac +} + +# Selected braille table +if [ -n "$LIBLOUIS_TABLES" ] +then + if type file2brl + then + # Good, we can use liblouisutdml + case $CONTENT_TYPE in + text/plain) + LIBLOUIS_TOOL="file2brl" + CONVERT="" + ;; + text/html) + LIBLOUIS_TOOL="file2brl -t" + CONVERT="" + ;; + text/xml|application/xml|application/xhtml+xml) + LIBLOUIS_TOOL="file2brl" + CONVERT="" + ;; + application/msword) + LIBLOUIS_TOOL="file2brl" + CONVERT="antiword -x db /dev/stdin" + checkTool antiword antiword "translating MS-Word doc files" + ;; + application/vnd.openxmlformats-officedocument.wordprocessingml.document) + LIBLOUIS_TOOL="file2brl" + CONVERT="docx2txt" + checkTool docx2txt docx2txt "translating MS-Word docx files" + ;; + text/rtf|application/rtf) + LIBLOUIS_TOOL="file2brl" + CONVERT="rtf2xml /dev/stdin" + checkTool rtf2xml rtf2xml "translating RTF files" + ;; + application/pdf) + LIBLOUIS_TOOL="file2brl -p" + CONVERT="pdftotext -raw /dev/stdin /dev/stdout" + checkTool pdftotext poppler "translating PDF files" + ;; + *) + echo "ERROR: unsupported content type $CONTENT_TYPE" >&2 + exit 1 + ;; + esac + RENDER_CALL="$LIBLOUIS_TOOL -CliteraryTextTable=$LIBLOUIS_TABLES,braille-patterns.cti $LIBLOUIS_CONFIG" + elif type lou_translate + then + # Only liblouis, but better than nothing + setupTextRendering + printf "WARN: The liblouisutdml package is required for translating braille better\n" >&2 + TRANSLATE="lou_translate $LIBLOUIS_TABLES,braille-patterns.cti" + else + printf "ERROR: The liblouisutdml package is required for translating braille\n" >&2 + exit 1 + fi +else + # No translation, only text rendering + setupTextRendering fi # Now proceeed
@@ -147,9 +162,13 @@ if [ -z "$CONVERT" ] then printf "DEBUG: Calling $RENDER_CALL on '%s'\n" "$FILE" >&2 < "$FILE" $RENDER_CALL -else +elif [ -z "$TRANSLATE" ] +then printf "DEBUG: Calling $CONVERT | $RENDER_CALL on '%s'\n" "$FILE" >&2 < "$FILE" $CONVERT | $RENDER_CALL +else + printf "DEBUG: Calling $CONVERT | $RENDER_CALL | $TRANSLATE on '%s'\n" "$FILE" >&2 + < "$FILE" $CONVERT | $RENDER_CALL | $TRANSLATE fi echo "INFO: Ready" >&2
Quoted 6 lines · Samuel Thibault
The attached patch makes cups-filter able to use
lou_translatefrom liblouis-bin (and warn about that) when file2brl from liblouisutdml-bin is not available.Samuel
Thank you very much. I have committed it now to the upstream BZR repository and so it will be part of cups-filters 1.8.0.
Till