diff options
author | Tim Starling <tstarling@wikimedia.org> | 2023-12-04 11:09:12 +1100 |
---|---|---|
committer | Tim Starling <tstarling@wikimedia.org> | 2023-12-04 20:20:32 +1100 |
commit | 497efa4ed6b8630e414c4c917ed95f66ee6235fd (patch) | |
tree | a7655661bf60fca376e57ef908b05345b69a9f8f /includes/media/scripts | |
parent | a007f6e09a9ed65a77e51dfe0435f85e9841d23c (diff) | |
download | mediawikicore-497efa4ed6b8630e414c4c917ed95f66ee6235fd.tar.gz mediawikicore-497efa4ed6b8630e414c4c917ed95f66ee6235fd.zip |
Clean up DjVuImage::retrieveMetaData including shellbox support
Following up Id9539a28f0f143539334002c3:
* Don't run the script twice.
* Wrap the decoded dump in an array with key "data".
* The default assignment for DJVU_DUMP and DJVU_TXT had the effect of
running the scripts anyway if the configuration variables are null.
Don't do that.
* If both $wgDjvuDump and $wgDjvuTxt are null, don't run the shellbox
script.
* Centralise shell location configuration.
* Factor out call to convertDumpToJSON().
* Instead of txt_exit_code, just use existence of the file to
communicate success. This avoids a deprecation warning if
txt_exit_code was not received, due to passing null to trim.
* Check for the existence of the result files instead of just trying to
use them.
* Check the exit status of the overall script.
* Confirm that the BoxedCommand branch is functional and works in CLI
mode by using it in DjvuTest.
* Change the service name from "media" to "djvu". Existing examples are
"pagedtiffhandler" and "pdfhandler", i.e. named after the extension,
there is no other core caller. I think it should be more fine-grained
than "media". The name was possibly a conflation with the
ProductionServices array key.
Also:
* Check the exit status of djvudump and don't use the output file if it
is non-zero.
* Check the return value of convertDumpToJSON().
* Don't use isset() unless error suppression is intended.
Bug: T352515
Change-Id: If41a2baada2e4e2462518c1f437af458feb29632
Diffstat (limited to 'includes/media/scripts')
-rw-r--r-- | includes/media/scripts/retrieveDjvuMetaData.sh | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/includes/media/scripts/retrieveDjvuMetaData.sh b/includes/media/scripts/retrieveDjvuMetaData.sh index 601b20a97d4c..5ca0fb6a33aa 100644 --- a/includes/media/scripts/retrieveDjvuMetaData.sh +++ b/includes/media/scripts/retrieveDjvuMetaData.sh @@ -1,23 +1,32 @@ #!/bin/sh -# Get parameters from environment -export DJVU_DUMP="${DJVU_DUMP:-djvudump}" -export DJVU_TXT="${DJVU_TXT:-djvutxt}" + runDump() { + local ret # djvudump is faster than djvutoxml (now abandoned) as of version 3.5 # https://sourceforge.net/p/djvu/bugs/71/ "$DJVU_DUMP" file.djvu > dump + ret="$?" + if [ "$ret" -ne 0 ]; then + echo "djvudump failed with exit code $ret" 1>&2 + rm -f dump + fi } runTxt() { + local ret # Text layer - "$DJVU_TXT" \ - --detail=page \ - file.djvu > txt - # Store exit code so we can use it later - echo $? > txt_exit_code + if ! "$DJVU_TXT" --detail=page file.djvu > txt; then + rm -f txt + fi + ret="$?" + if [ "$ret" -ne 0 ]; then + echo "djvutxt failed with exit code $ret" 1>&2 + rm -f txt + fi } -if [ -x "$DJVU_DUMP" ]; then +if [ -n "$DJVU_DUMP" ]; then runDump fi -if [ -x "$DJVU_TXT" ]; then +if [ -n "$DJVU_TXT" ]; then runTxt fi +exit 0 |