Debian Codegraph @

lib/getimages

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