Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
getLs.sh
Go to the documentation of this file.
1#!/usr/bin/env zsh
2#
3# \author mdejong
4#
5script=${0##*/}
6
7source ${0%${script}}ulib.sh
8
9set_variable: DEBUG ARCHIVE_DEBUG 2
10
11if do_usage $*; then
12 usage "$script <path> [<detector identifier> [<type> [version [<min run> [<max run> [option]]]]]]"\
13 "\nUtility script to list files in archive."\
14 "\nPossible options short or long."
15fi
16
17case $# in
18 7) set_variable OPTION ${argv[7]};&
19 6) let MAXRUN=" ${argv[6]}";&
20 5) let MINRUN=" ${argv[5]}";&
21 4) set_variable VERSION ${argv[4]};&
22 3) set_variable TYPE ${argv[3]};&
23 2) let ID=" ${argv[2]}";&
24 1) set_variable DIR ${argv[1]:a};;
25 *) fatal "Wrong number of arguments."
26esac
27
28if [[ ! -d $DIR ]]; then
29 fatal "Invalid path $DIR"
30fi
31
32if [[ "$OPTION" != "" ]] && [[ "$OPTION" != "short" ]] && [[ "$OPTION" != "long" ]]; then
33 fatal "Invalid option $OPTION"
34fi
35
36typeset -Z8 ID
37typeset -Z8 MINRUN
38typeset -Z8 MAXRUN
39
40if (( $# == 1 )); then
41
42 ls -1 $DIR/ | grep -E ${ANY_ID} | sed -n 's/^0*//p'
43
44elif (( $# == 2 )); then
45
46 ls -1 $DIR/$ID/;
47
48elif (( $# == 3 )); then
49
50 ls -1 $DIR/$ID/$TYPE | sed 's/^_//';
51
52elif (( $# == 4 )); then
53
54 ls -1 $DIR/$ID/$TYPE/_$VERSION | sed -n 's/^0*//p'
55
56elif (( $# == 5 )); then
57
58 ls -1 $DIR/$ID/$TYPE/_$VERSION/$MINRUN | sed -n 's/^0*//p'
59
60elif (( $# >= 6 )); then
61
62 FILENAME=""
63
64 for BUFFER in $(ls -1 $DIR/$ID/$TYPE/_$VERSION/$MINRUN/$MAXRUN); do
65 if [[ "$FILENAME" == "" ]] || (( ${BUFFER:r} > ${FILENAME:r} )); then
66 FILENAME=$BUFFER
67 fi
68 done
69
70 if [[ -n $FILENAME ]]; then
71 case "_$OPTION" in
72 _) echo "$FILENAME";;
73 _short) echo "$FILENAME";;
74 _long) echo "$DIR/$ID/$TYPE/_$VERSION/$MINRUN/$MAXRUN/$FILENAME";;
75 esac
76 fi
77fi