Jpp  debug
the software that should make you happy
archive-put-wiki-detectors.sh
Go to the documentation of this file.
1 #!/bin/zsh
2 script=${0##*/}
3 
4 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
5 
6 set_variable WORKDIR ${TMPDIR:-/tmp}/
7 set_variable: DEBUG ARCHIVE_DEBUG 2
8 set_variable URL https://wiki.km3net.de/index.php/Calibration/Detectors
9 
10 if do_usage $*; then
11  usage "$script <detector identifier> [<archive> <version>]"\
12  "\nAuxiliary script to download official detectors from wiki."\
13  "\nOptionally, the corresponding JSON files are stored in the archive with given version."
14 fi
15 
16 case $# in
17  3) set_variable VERSION $argv[3];
18  set_variable ARCHIVE $argv[2];&
19  1) set_variable DETID $argv[1];;
20  *) fatal "Wrong number of arguments."
21 esac
22 
23 set_variable WIKI_HTML $WORKDIR/wiki.html
24 set_variable WIKI_TXT $WORKDIR/wiki.txt
25 
26 set_variable DETID `getDetector -D $DETID -O string`
27 typeset -Z 8 DETID
28 
29 # extract html page from wiki
30 
31 if [[ ! -f $WIKI_HTML ]]; then
32 
33  wget \
34  --no-check-certificate \
35  --user=km3net \
36  --ask-password \
37  -q \
38  -O $WIKI_HTML \
39  "$URL"
40 fi
41 
42 # parse html table
43 
44 xmllint --html $WIKI_HTML |\
45  awk 'BEGIN { RS = "</tr>"; FS = "</td>" } \
46  { \
47  if ($1 ~ "https://km3netdbweb.in2p3.fr/detx/") {
48 
49  URL = gensub(".*href *= *\"([^\"]+)\".*", "\\1", "", $1)
50  DETECTOR = gensub(".*(KM3NeT_.*\\.detx|TBD).*", "\\1", "", $1)
51  RUNS = gensub("(<td>|,|<br>|\n)", " ", "g", $2)
52 
53  print gensub("\\&amp;", "\\&", "g", URL), DETECTOR, RUNS
54  }
55  }' > $WIKI_TXT
56 
57 
58 # process data
59 
60 while read __line__; do
61 
62  debug $__line__
63  echo $__line__ | read URL DETECTOR RUNS
64 
65  RUNS=(`echo $RUNS`)
66 
67  notice "Processing $DETECTOR..."
68 
69  if [[ "$DETECTOR" =~ "$DETID" ]]; then
70 
71  if [[ ! -f $DETECTOR ]]; then
72 
73  wget \
74  --no-check-certificate \
75  --load-cookies=$HOME/.km3netdb_cookie \
76  --secure-protocol=TLSv1_2 \
77  -O $DETECTOR \
78  "$URL"
79  fi
80 
81  for RANGE in $RUNS[*]; do
82 
83  RUN1=${RANGE%%-*}
84  RUN2=${RANGE##*-}
85 
86  if [[ "$RUN1" =~ "\.\." ]]; then; RUN1=1; fi
87  if [[ "$RUN2" =~ "\.\." ]]; then; RUN2=99999999; fi
88 
89  debug "$URL"
90  debug "[${RUN1},${RUN2}]"
91 
92  if [[ "$DETECTOR" =~ "\.detx$" || "$DETECTOR" =~ "\.datx$" ]]; then
93 
94  if [[ "$ARCHIVE" != "" ]]; then
95 
96  archive-put-Detector.sh \
97  $ARCHIVE \
98  $VERSION \
99  $DETECTOR \
100  ${RUN1} ${RUN2}
101  else
102 
103  JDestructDetector \
104  -a $DETECTOR \
105  -o $WORKDIR/%.txt
106  fi
107 
108  CHECK_EXIT_CODE
109  fi
110  done
111  fi
112 done < $WIKI_TXT
113 
114 rm -f $WIKI_HTML $WIKI_TXT