Jpp  19.1.0-rc.1
the software that should make you happy
getLs.sh
Go to the documentation of this file.
1 #!/bin/zsh
2 #
3 # \author mdejong
4 #
5 script=${0##*/}
6 
7 source ${0%${script}}ulib.sh
8 
9 set_variable: DEBUG ARCHIVE_DEBUG 2
10 
11 if 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."
15 fi
16 
17 case $# 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."
26 esac
27 
28 if [[ ! -d $DIR ]]; then
29  fatal "Invalid path $DIR"
30 fi
31 
32 if [[ "$OPTION" != "" ]] && [[ "$OPTION" != "short" ]] && [[ "$OPTION" != "long" ]]; then
33  fatal "Invalid option $OPTION"
34 fi
35 
36 typeset -Z8 ID
37 typeset -Z8 MINRUN
38 typeset -Z8 MAXRUN
39 
40 if (( $# == 1 )); then
41 
42  ls -1 $DIR/ | grep -E ${ANY_ID} | sed -n 's/^0*//p'
43 
44 elif (( $# == 2 )); then
45 
46  ls -1 $DIR/$ID/;
47 
48 elif (( $# == 3 )); then
49 
50  ls -1 $DIR/$ID/$TYPE | sed 's/^_//';
51 
52 elif (( $# == 4 )); then
53 
54  ls -1 $DIR/$ID/$TYPE/_$VERSION | sed -n 's/^0*//p'
55 
56 elif (( $# == 5 )); then
57 
58  ls -1 $DIR/$ID/$TYPE/_$VERSION/$MINRUN | sed -n 's/^0*//p'
59 
60 elif (( $# >= 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
77 fi