Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
getArchive.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 set_variable VERSION "*"
11 
12 if do_usage $*; then
13  usage "$script <path> [<detector identifier> [<run> [<type> [version]]]]"\
14  "\nUtility script to list files in archive."
15 fi
16 
17 case $# in
18  5) set_variable VERSION $argv[5];&
19  4) set_variable TYPE $argv[4];&
20  3) let RUN=" $argv[3]";&
21  2) let ID=" $argv[2]";&
22  1) set_variable DIR $argv[1];;
23  *) fatal "Wrong number of arguments."
24 esac
25 
26 
27 if [[ ! -d $DIR ]]; then
28  fatal "Invalid path $argv[1]"
29 fi
30 
31 
32 setopt extendedglob
33 
34 typeset -Z8 ID
35 
36 
37 #
38 # print file properties
39 #
40 # \param 1 file name
41 #
42 function archive()
43 {
44  typeset -T BUFFER ARRAY /
45 
46  BUFFER=$1
47 
48  set_variable A_ID ${ARRAY[-6]}
49  set_variable A_TYPE ${ARRAY[-5]}
50  set_variable A_VERSION ${ARRAY[-4]#_}
51  let A_MINRUN=" ${ARRAY[-3]}"
52  let A_MAXRUN=" ${ARRAY[-2]}"
53  set_variable A_FILENAME ${ARRAY[-1]}
54 
55  let A_COUNTER="${A_FILENAME:r}"
56 
57  if (( $RUN >= $A_MINRUN && $RUN <= $A_MAXRUN )); then
58 
59  if [[ $(uname) == "Darwin" ]]; then
60  ls -l $BUFFER
61  else
62  ls -l --author $BUFFER
63  fi
64 
65  if (( $DEBUG >= 3 )); then
66  echo "identifier: $(($A_ID))"
67  echo "type: $A_TYPE"
68  echo "version: $A_VERSION"
69  echo "minimal run: $(($A_MINRUN))"
70  echo "maximal run: $(($A_MAXRUN))"
71  echo
72  fi
73  fi
74 
75 }
76 
77 
78 if (( $# == 1 )); then
79  ls -1 $DIR/ | grep -E ${ANY_ID}; return
80 fi
81 
82 
83 if (( $ID == 0 )); then
84  fatal "Invalid detector identifier $argv[2]"
85 fi
86 
87 
88 if (( $# == 2 )); then
89  ls -1 $DIR/$ID/; return
90 fi
91 
92 
93 if (( $RUN == 0 )); then
94  fatal "Invalid run $argv[3]"
95 fi
96 
97 
98 if (( $# == 3 )); then
99 
100  eval ls -1 $DIR/$ID/\*/_\*/\*/\*/\* 2> /dev/null | while read BUFFER; do
101  archive $BUFFER
102  done
103 fi
104 
105 
106 if (( $# >= 4 )); then
107 
108  eval ls -1 $DIR/$ID/$TYPE/_${VERSION}/\*/\*/\* 2> /dev/null | while read BUFFER; do
109  archive $BUFFER
110  done
111 fi