1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
# -*-Shell-script-*-
#
# Copyright (C) 2015-2020 SUSE Software Solutions Germany GmbH
#
# Author:
# Frank Sundermeyer <fsundermeyer at opensuse dot org>
#
###########################################################################
#
# GETIMAGES
#
# Gets a list of images from the file specified with -f or --file or
# the document specified by rootid and outputs them as:
# * default: long list (one file per line)
# * --compact: compact list (single line)
# * --viewer=VIEWER: shows images in VIEWER and prints long list to STDOUT
#
# the additional option (--modified) will also print the image file's
# mtime in long lists (this option is ignored with --compact)
#
###########################################################################
function getimages {
local SHORT_OPTS LONG_OPTS SUB_CMD
local COMPACT FILE SHOW IVIEWER
local -a IMGLIST
SUB_CMD=$1
shift
# any kind of verbosity is unwanted in this case
WRITE_LOG=0
DEBUG=0
VERBOSITY=0
SHORT_OPTS="h"
LONG_OPTS="compact,file:,help,modified,rootid:,show,viewer:"
parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"
#------ Computing the values returned from the parser -----
if [[ 1 -eq $P_HELP ]]; then
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}"
help_compact
help_file
help_modified
help_rootid
help_show_images
help_viewer
echo -e " NOTES: * Options --file (-f) and --rootid exclude one another.\n * If neither file nor rootid is specified, the rootid\n from the DC-file is used\n * $SUB_CMD follows xi:includes\n"
exit 0
fi
# set ROOTID - either directly or via $FILE
if [[ -z "$P_ROOTID" && -z "$P_FILE" ]]; then
if [[ 0 -ne $VERBOSITY ]]; then
ccecho "info" "Neither file nor rootid specified, using rootid from DC-file"
fi
elif [[ -n "$P_ROOTID" && -n "$P_FILE" ]]; then
exit_on_error "Options --file (-f) and --rootid exclude one another.\nPlease specify only one of these options"
fi
if [[ -n $P_FILE ]]; then
ROOTID=$($XSLTPROC --stylesheet "$DAPSROOT/daps-xslt/common/get-rootelement-id.xsl" --file "$P_FILE" "$XSLTPROCESSOR" 2>/dev/null) || exit_on_error "Cannot get a rootid from file $FILE"
export ROOTID
fi
# IMG_VIEWER may also be set via config file:
if [[ 1 -eq $SHOW ]]; then
if [[ -z "$IMG_VIEWER" ]]; then
exit_on_error "Please specify an image viewer via command-line (--viewer) or via config file"
else
IVIEWER=$(which "$IMG_VIEWER" 2>/dev/null)
if [[ 0 -ne $? ]]; then # which command failed
# Viewer not installed
exit_on_error "Cannot find VIEWER command ($IMG_VIEWER). Is it installed?"
fi
fi
fi
# get the image list
# we can use projectgraphics, since it returns images for a given rootid
IMGLIST=( $(call_make list-srcfiles silent LIST_NODC=1 LIST_NOENT=1 LIST_NOXML=1) )
if [[ 0 -ne $? ]]; then
exit_on_error "Failed to get list of images"
fi
if [[ 0 -lt ${#IMGLIST[@]} ]]; then
if [[ $COMPACT ]]; then
echo -e "${IMGLIST[*]}\n"
else
for IMAGE in "${IMGLIST[@]}"; do
if [[ 1 -eq $MOD ]]; then
MODIFIED=$(stat -c %y "$IMAGE" | cut -d '.' -f1 2>/dev/null)
echo "${IMAGE} (${MODIFIED})"
else
echo "${IMAGE}"
fi
done | column -t
if [[ 1 -eq $SHOW ]]; then
$IMG_VIEWER "${IMGLIST[@]}" &
fi
fi
fi
exit
}
|