-
Notifications
You must be signed in to change notification settings - Fork 125
/
opatrack.sh
executable file
·1688 lines (1516 loc) · 48.3 KB
/
opatrack.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
export ROOT=`pwd`
# The name of the application
opatrack='opatrack'
# The location of cgi script for building evolution scripts
CGI_LOCATION='http://kahan/cgi-bin/hudson'
# Conventions over name of files and directories.
# <!> Keep it synchronized with module PassTrack.
passes_list='passes.list'
printers_list='printers.list'
trackers_list='trackers.list'
printers_dir='printers'
trackers_dir='trackers'
internal_dir='internal'
check_dir='check'
time_dir='time'
all_time='all.time'
size_file='size'
# Global variables
dir2_mode=0
entityident='entity'
html_trace="$entityident.html"
raw_trace="$entityident.opatrack"
set_entity_ident() {
local entity="$1"
entityident="$entity"
html_trace="$entityident.html"
raw_trace="$entityident.opatrack"
}
# Command line options.
# <!> Keep alphabetic order for maintenance.
COLOR=1
DEBUG=0
DIR=''
DIR2=''
LOGFILE=/dev/stdout
REPORT_MODE=0
TOOL=meld
TOOL_FLAGS=''
VIEWER=less
VIEWER_FLAGS=''
SUM=0
SUMTARGET=''
menuitem() {
key="$1"
shift
msg="$*"
if [ "$COLOR" -eq 1 ]; then
printf "\t[34m%2s[0m : %s\n" "$key" "$msg"
else
printf "\t%2s : %s\n" "$key" "$msg"
fi
}
title() {
if [ "$COLOR" -eq 1 ]; then
echo "[32m$*[0m"
else
echo "$*"
fi
}
warn() {
if [ "$COLOR" -eq 1 ]; then
echo "[33m[1m$*[0m"
else
echo "$*"
fi
}
# Help messsage
help() {
cat <<EOF
$opatrack: the MLstate pass track analyser
Usage: $opatrack [options] ?directory ?directory2
Options:
-h|--help : displays this help
--no-color : disables colors
-t|--tool : set diff tool. (def is $TOOL)
--tflag <opt> : add to tool options <opt>
-v|--viewer : set diff viewer. (def is $VIEWER)
--vflag <opt> : add to viewer options <opt>
--report : do not start main, but report mode
--entity-ident _ : set the entity ident (def is $entityident)
--html _ : set the name of the html trace (def is entityident.html)
--sum _ <dirs> : set the directory target for suming everyother _tracks directory
--debug : debug mode (more output for reporting, or summing)
--log _ : precise a log for outputing modes (default is /dev/stdout)
See the documentation of module PassTracker for more information.
EOF
}
# Arg.parse
while [ $# -gt 0 ]; do
case $1 in
-h|--help|-help|help)
help
exit 0
;;
--no-color)
COLOR=0
;;
-t|--tool)
if [ -z "$2" ]; then warn "Error: option $1 requires an argument"; exit 1; fi
shift
TOOL="$1"
;;
--tflag)
if [ -z "$2" ]; then warn "Error: option $1 requires an argument"; exit 1; fi
shift
TOOL_FLAGS="$TOOL_FLAGS $1"
;;
-v|--viewer)
if [ -z "$2" ]; then warn "Error: option $1 requires an argument"; exit 1; fi
shift
VIEWER="$1"
;;
--vflag)
if [ -z "$2" ]; then warn "Error: option $1 requires an argument"; exit 1; fi
shift
VIEWER_FLAGS="$VIEWER_FLAGS $1"
;;
--report)
REPORT_MODE=1
;;
--entity-ident)
if [ -z "$2" ]; then warn "Error: option $1 requires an argument"; exit 1; fi
shift
set_entity_ident "$1"
;;
--html)
if [ -z "$2" ]; then warn "Error: option $1 requires an argument"; exit 1; fi
shift
html_trace="$1"
;;
--sum)
if [ -z "$2" ]; then warn "Error: option $1 requires an argument"; exit 1; fi
shift
SUM=1
SUMTARGET="$1"
shift
DIR="$@"
break
;;
--debug)
DEBUG=1
;;
--log)
if [ -z "$2" ]; then warn "Error: option $1 requires an argument"; exit 1; fi
shift
LOGFILE=$1
;;
*)
if [ -z "$DIR" ] ; then
DIR="$1"
else
if [ -z "$DIR2" ] ; then
DIR2="$1"
dir2_mode=1
else
warn "$opatrack: unrecognized option '$1'"
warn "Try '$opatrack --help' for more information."
exit 1
fi
fi
;;
esac
shift
done
sum_size() {
local A=$1
local B=$2
local T=$3
local line
rm -f $T
while read number field ; do
line=$(cat $B | grep $field)
number2=$(echo $line | cut -d' ' -f1)
number=$(echo "$number + $number2" | bc)
if [ -n "$number" ] ; then
echo "$number $field" >> $T
fi
done < $A
}
get_line() {
local file=$1
local line=$2
line=$(head -n $line $file | tail -n 1)
echo $line
}
merge_files() {
local private_FILE_I=$1
local private_FILE_J=$2
local private_I=1
local private_J=1
local private_FILE_I_LEN=$(cat $private_FILE_I | wc -l)
local private_FILE_J_LEN=$(cat $private_FILE_J | wc -l)
local LINES=''
local line_I=''
local line_J=''
local rest_I=0
local rest_J=0
local succ_I=0
local succ_J=0
while [ 1 ] ; do
if (($private_I > $private_FILE_I_LEN)) && (($private_J > $private_FILE_J_LEN)) ; then
break;
fi
if (($private_I > $private_FILE_I_LEN)) ; then
local rest_J=$(($private_FILE_J_LEN - $private_J + 1))
tail -n $rest_J $private_FILE_J
break;
fi
if (($private_J > $private_FILE_J_LEN)) ; then
local rest_I=$(($private_FILE_I_LEN - $private_I + 1))
tail -n $rest_I $private_FILE_I
break;
fi
line_I=$(get_line $private_FILE_I $private_I)
line_J=$(get_line $private_FILE_J $private_J)
if [ "$line_I" = "$line_J" ] ; then
echo "$line_I"
let "private_I=$private_I+1"
let "private_J=$private_J+1"
else
# depending of a simple heuristic, priority to left or to right
local succ_I=$(get_line $private_FILE_I $(($private_I+1)))
local succ_J=$(get_line $private_FILE_J $(($private_J+1)))
if [ "$line_I" = "$succ_J" ] ; then
echo "$line_J"
let "private_J=$private_J+1"
elif [ "$line_J" = "$succ_I" ] ; then
echo "$line_I"
let "private_I=$private_I+1"
else
# warning, will probably skip some lines
echo "$line_I"
let "private_I=$private_I+1"
fi
fi
done
echo $LINES
}
sum2() {
local A=$1
local B=$2
local T=$3
local pass ta tb tc
local PASSES=$(merge_files $A/$passes_list $B/$passes_list)
mkdir -p $T/$time_dir
cp $A/*.list $T/
rm -f $T/$passes_list
if [ -f $A/$time_dir/$all_time ] && [ -f $B/$time_dir/$all_time ] ; then
echo "$(cat $A/$time_dir/$all_time) + $(cat $B/$time_dir/$all_time)" | bc > $T/$time_dir/$all_time
fi
for pass in $PASSES ; do
if [ -f $A/$time_dir/$pass.time ] && [ -f $B/$time_dir/$pass.time ] ; then
echo "$(cat $A/$time_dir/$pass.time) + $(cat $B/$time_dir/$pass.time)" | bc > $T/$time_dir/$pass.time
echo $pass >> $T/$passes_list
else
if [ -f $A/$time_dir/$pass.time ] ; then
# echo "only A for $pass"
cat $A/$time_dir/$pass.time > $T/$time_dir/$pass.time
echo $pass >> $T/$passes_list
elif [ -f $B/$time_dir/$pass.time ] ; then
# echo "only B for $pass"
cat $B/$time_dir/$pass.time > $T/$time_dir/$pass.time
echo $pass >> $T/$passes_list
fi
fi
if [ -f $A/$pass/$printers_dir/size ] && [ -f $B/$pass/$printers_dir/size ] ; then
mkdir -p $T/$pass/$printers_dir
sum_size $A/$pass/$printers_dir/size $B/$pass/$printers_dir/size $T/$pass/$printers_dir/size
fi
if [ -f $A/$pass/$printers_dir/size_client ] && [ -f $B/$pass/$printers_dir/size_client ] ; then
mkdir -p $T/$pass/$printers_dir
sum_size $A/$pass/$printers_dir/size_client $B/$pass/$printers_dir/size_client $T/$pass/$printers_dir/size_client
fi
done
}
sumN() {
local T=$1
shift
local N=$@
local first acc target
local x=$(echo $N | wc -w)
first=$(echo $N | cut -d' ' -f1)
acc=$(mktemp)
rm -rf $acc
mkdir -p $acc
cp -r $first/* $acc/
N=$(echo $N | cut -d' ' -f2-$x)
for d in $N; do
tmp1=$(mktemp)
rm -rf $tmp1
sum2 $acc $d $tmp1
rm -rf $acc
acc=$tmp1
done
mv $tmp1 $T
}
if [ "$SUM" = 1 ] ; then
sumN $SUMTARGET $DIR
exit 0
fi
# Utils
quit() {
warn "Thank you for using $opatrack !"
exit 0
}
if [ "$COLOR" -eq 1 ]; then
TRACKPATH="[31m$opatrackm:[31m[0m\$ "
else
TRACKPATH="$opatrack:\$ "
fi
set_track_path() {
if [ "$COLOR" -eq 1 ]; then
TRACKPATH="[31m$opatrack[0m:[33m/$1[31m[0m\$ "
else
TRACKPATH="$opatrack:/$1\$ "
fi
}
concat_path() {
local p1="$1"
local p2="$2"
if [ -z "$p1" ] ; then
echo "$p2"
else
echo "$p1/$p2"
fi
}
check_dir() {
if [ ! -d "$1" ] ; then
warn "[!] $opatrack: cannot find directory $1"
exit 1
fi
}
check_file() {
if [ ! -f "$1" ] ; then
warn "[!] $opatrack: cannot find file $1"
exit 1
fi
}
length_of_file() {
wc -l $1 | sed -e 's/ *\(.*\)/\1/g' | cut -d' ' -f1
}
assert_eq() {
if [ ! "$1" = "$2" ] ; then
warn "$opatrack: internal error. assertion failure ($1 != $2)"
exit 5
fi
}
eof_check() {
if [ "$1" = 1 ] && [ -z "$REPLY" ] ; then echo ; quit ; fi
if [ "$REPLY" = "q" ] ; then echo ; quit ; fi
}
get_size() {
# %d declarations
# %d nodes
local file="$1"
if [ -e "$file" ] ; then
local declarations=$(cat $file | grep 'declarations' | cut -d' ' -f1)
local nodes=$(cat $file | grep 'nodes' | cut -d' ' -f1)
echo $declarations $nodes
else
echo 0 0
fi
}
# Evolution ratio between a last value, and a current value.
# the value is expressed like this :
# +3.4 means 1 * 3.4
# -2.5 means 1 / 2.5
# @param $1 last
# @param $2 current
evolution_ratio() {
last=$1
this=$2
if [ ! -n "$last" ] || [ ! -n "$this" ] || [ "$last" = 0 ] || [ "$this" = 0 ] ; then
echo 'nan'
return
fi
ratio=$(echo "scale=4; $this / $last" | bc)
if [ $(echo "$ratio < 1" | bc) = 1 ] ; then
ratio=$(echo "scale=4; 1 / $ratio" | bc)
echo "-$ratio"
else
echo "+$ratio"
fi
}
private_fresh=0
fresh_index() {
private_fresh=$(echo "$private_fresh + 1" | bc)
}
evolution_item() {
local CGI_CALL="$1"
shift
local label="$1"
shift
local data="$*"
fresh_index
local this_fresh=$private_fresh
local this_cgi_call=$CGI_CALL"&label=$label"
cat <<EOF
<b>$label</b> : $data
[
<a href='#' onclick='javascript:document.getElementById("evolution_$this_fresh").innerHTML=document.getElementById("evolution_$this_fresh").innerHTML != "" ? "" : "<object width=700px height=500px data=$this_cgi_call></object>"; return false;'>evolution</a>
]
<div id="evolution_$this_fresh"></div>
EOF
}
# avoid to print .54 instead of 0.54
float_escaped() {
local float="$1"
if [ $(echo "$float < 1" | bc) = "1" ] ; then
float="0"$float
fi
echo "$float"
}
# grep_indexed_auto_selection will select between args
# writting in the tempfile, and returning 0 if ok, 1 if KO
auto_selected_file=$(mktemp /tmp/fileXXXXXX)
grep_indexed_auto_selection() {
echo '' > $auto_selected_file
local ALL="$@"
declare -a tab
local loop=1
local FILES="$ALL"
if [ -z "$ALL" ] ; then
return 1
fi
local IS_FILTER=0
while [ "$loop" = 1 ] ; do
loop=0
i=0
tab[1]=''
count=$(echo $FILES | wc -w | sed -e 's/ *\(.*\)/\1/g')
if [ "$count" -gt 150 ] ; then
echo "There are $count elts, please give a <regexp> !"
read -p "$TRACKPATH"
eof_check "$?"
rep="$REPLY"
if [ "$rep" = "!" ] ; then break ; fi
IS_FILTER=1
FILES=$(for file in $FILES; do echo $file ; done | grep $rep)
loop=1
continue
fi
title "Selection:"
for file in $FILES ; do
let "i=$i+1"
menuitem $i "$file"
tab[$i]=$file
done
if [ "$i" = 0 ] ; then
loop=1
FILES="$ALL"
IS_FILTER=0
continue
fi
if [ "$i" = 1 ] ; then
echo "${tab[1]}" > $auto_selected_file
return 0
fi
if [ "$i" -lt 10 ] ; then
echo "Choose an index, (or '!')"
read -p "$TRACKPATH" -en1
eof_check "$?"
else
echo "Choose an index, or '<regexp>' for filtering or '!' for review all"
read -p "$TRACKPATH"
eof_check "$?"
fi
rep=$REPLY
if [ -z "$rep" ] ; then
loop=1
continue
fi
if [ ! "$rep" = "!" ] && [[ "$rep" != [0-9]* ]]; then
IS_FILTER=1
FILES=$(for file in $FILES; do echo $file ; done | grep $rep)
loop=1
continue
else
if [ "$rep" = "!" ] ; then
if [ "$IS_FILTER" = 1 ] ; then
loop=1
FILES="$ALL"
IS_FILTER=0
continue
else
return 1
fi
else
if [[ "$rep" != [0-9]* ]]; then
warn "integer expected : $rep"
loop=1
continue
else
choice="${tab[$rep]}"
if [ -n "$choice" ] ; then
echo "$choice" > $auto_selected_file
return 0
else
warn "[!] $rep : no such index."
loop=1
fi
fi
fi
fi
done
}
# 1 Retrieve informations
# 1.1 Find directory
# Get to the directory if specified
# If the directory ends with .opx, then go $DIR/_tracks instead
# Can be absolute or relative. Try both
case "$DIR" in
*.opx) DIR="$DIR/_tracks";;
esac
if [ ! -d "$ROOT/$DIR" ] ; then
check_dir "$DIR"
else
if [ -n "$DIR" ] ; then
DIR="$ROOT/$DIR"
else
DIR="$ROOT"
fi
fi
if [ "$dir2_mode" = 1 ] ; then
case "$DIR2" in
*.opx) DIR2="$DIR2/_tracks";;
esac
if [ ! -d "$ROOT/$DIR2" ] ; then
check_dir "$DIR2"
else
if [ -n "$DIR2" ] ; then
DIR2="$ROOT/$DIR2"
else
DIR2="$ROOT"
fi
fi
fi
# 1.2 Check for .list conf
passes_list="$DIR/$passes_list"
printers_list="$DIR/$printers_list"
trackers_list="$DIR/$trackers_list"
check_file "$passes_list"
check_file "$printers_list"
check_file "$trackers_list"
passes_len=$(length_of_file $passes_list)
printers_len=$(length_of_file $printers_list)
trackers_len=$(length_of_file $trackers_list)
# 1.3 Build tables for indexed access
declare -a passes_table
declare -a printers_table
declare -a trackers_table
declare -a trackers_tracked_table
declare -a trackers_length_table
ALL_PASSES=''
ALL_PRINTERS=''
ALL_TRACKERS=''
i=0
while read passname ; do
let "i=$i+1"
passes_table[$i]=$passname
done < $passes_list
ALL_PASSES=$(cat $passes_list)
assert_eq "$i" "$passes_len"
i=0
while read printer_id ; do
let "i=$i+1"
printers_table[$i]=$printer_id
done < $printers_list
ALL_PRINTERS=$(cat $printers_list)
assert_eq "$i" "$printers_len"
i=0
while read tracker_id ; do
let "i=$i+1"
trackers_table[$i]=$tracker_id
done < $trackers_list
ALL_TRACKERS=$(cat $trackers_list)
assert_eq "$i" "$trackers_len"
# collect all tracked values for a given tracker_id
for (( i=1; i<=$trackers_len; i++ )); do
tracker_id="${trackers_table[$i]}"
tracked_file="$DIR/$trackers_dir/$tracker_id.list"
length=$(length_of_file $tracked_file)
trackers_length_table[$i]="$length"
trackers_tracked_table[$i]=$(cat $tracked_file)
done
print_tree() {
title "Passes:"
for (( i=1; i<=$passes_len; i++ )); do
menuitem $i "${passes_table[$i]}"
done
title "Printers:"
if [ "$printers_len" -gt 5 ] ; then
echo -e "\t$printers_len printers"
else
for (( i=1; i<=$printers_len; i++ )); do
menuitem $i "${printers_table[$i]}"
done
fi
title "Trackers:"
if [ "$trackers_len" -gt 5 ] ; then
echo -e "\t$trackers_len trackers"
else
for (( i=1; i<=$trackers_len; i++ )); do
menuitem $i "${trackers_table[$i]} (${trackers_length_table[$i]} elts)"
done
fi
}
index_pass() {
local passname="$1"
for (( i=1; i<=$passes_len; i++ )); do
if [ "${passes_table[$i]}" = "$passname" ] ; then
echo $i
return 0
fi
done
return 1
}
index_printer() {
local printer_id="$1"
for (( i=1; i<=$printers_len; i++ )); do
if [ "${printers_table[$i]}" = "$printer_id" ] ; then
echo $i
return 0
fi
done
return 1
}
index_tracker() {
local tracker_id="$1"
for (( i=1; i<=$trackers_len; i++ )); do
if [ "${trackers_table[$i]}" = "$tracker_id" ] ; then
echo $i
return 0
fi
done
return 1
}
# 2 Pre computation is done. Start the main loop
# 2.1 Some common help manual
general_help() {
cat <<EOF
Welcome to opatrack.
This script is meant to speed-up the diffing between expressions
along passes. You can choose between several modes.
Whenever you get request for an answer :
'?' : get some help about the specific local menu
'!' : get back to the backward menu
'q' : quit opatrack.
Have a nice bug tracking with opatrack !
EOF
}
# Add new modes there if you need.
# GUIDELINES ABOUT MODES :
# + should start a loop, and print $opatrack/$mode ~:$ before inviting read
# + they can starts sub-mode, and should not exit when finished (get back to the parent mode) (except if 'q' is read)
# + they should be documented, and provide an introduction, and a short helpfull help messages resuming command
# + they should return and get back to the parent if '!' is pressed.
# + if you add sub modes, the function should be prefixed with the name of the mode
# + read function should prefix request with TRACKPATH value
# + menus should be cool (hahaha)
# tool (meld)
launch_meld() {
local file1="$1"
local file2="$2"
local file3="$3"
local command=''
if [ -n "$file3" ] ; then
command="$TOOL $TOOL_FLAGS $file1 $file2 $file3"
else
command="$TOOL $TOOL_FLAGS $file1 $file2"
fi
echo "$command"
$command
}
# viewer (less)
launch_less() {
local file1="$1"
local command=''
command="$VIEWER $VIEWER_FLAGS $file1"
echo "$command"
$command
}
filtering_passes() {
local file="$1"
local pass
for pass in $ALL_PASSES ; do
if [ -e "$DIR/$pass/$file" ] ; then
echo $pass
fi
done
}
# GENERIC NODE/LEAF management
# generic shema for the an application_node
# copy past it, and change name with a fresh name
application_node_name() {
# dealing with path
local selfpath='name'
# GENERIC =========================================
local parentpath="$1" #
shift #
selfpath=$(concat_path "$parentpath" "$selfpath") #
set_track_path "$selfpath" #
# =================================================
# other args are options of the node.
help_for_name() {
menuitem "a" "blabla"
menuitem "b" "bloblo"
}
# introduction
cat <<EOF
This is a help message which is printed only once, whenever
we enter the node. After that the loop will start.
EOF
while [ 1 ] ; do
title "Node"
help_for_name
# GENERIC ===================
set_track_path "$selfpath" #
read -p "$TRACKPATH" -en1 #
eof_check "$?" #
case $REPLY in #
# ===========================
# insert there call to other node or leaf
a)
application_node_child "$selfpath" # optionnal args
;;
!)
return
;;
*) # will lead to loop, and rewrite the help
;;
esac
done
}
# This node is for comparing _tracks from 2 different branches
# of the compiler (usefull for comparing code after a huge modif)
node_meld_2bran() {
# GENERIC =========================================
local parentpath="$1" #
shift #
# get arguments
local SUBDIR="$1"
local FILE_FOR_MELD=$(concat_path "$SUBDIR" "$2")
# dealing with path
local selfpath='2bran'
selfpath=$(concat_path "$parentpath" "$selfpath") #
set_track_path "$selfpath" #
# =================================================
# other args are options of the node.
help_for_meld_2bran() {
menuitem "!" "quit meld 2bran mode"
menuitem "q" "quit opatrack"
}
if [ "$passes_len" -le 0 ] ; then
warn "No pass: This mode is not available"
return
fi
title "Meld 2bran: $FILE_FOR_MELD"
local FILTERING_PASSES=$(filtering_passes "$FILE_FOR_MELD")
local number_filtering=$(echo $FILTERING_PASSES | wc -w | sed -e 's/ *\(.*\)/\1/g')
while true ; do
set_track_path "$selfpath"
help_for_meld_2bran
echo "Choose the pass:"
grep_indexed_auto_selection "$FILTERING_PASSES"
code=$?
if [ ! "$code" = 0 ] ; then
return
fi
pass=$(cat $auto_selected_file)
index_pass=$(index_pass $pass)
code=$?
if [ ! "$code" = 0 ] ; then
warn "Pass: $pass Not found (i=$index_pass)"
continue
fi
file1="$DIR/$pass/$FILE_FOR_MELD"
file2="$DIR2/$pass/$FILE_FOR_MELD"
# check that the same file also exists in the other branch
if [ ! -f "$file2" ] ; then
warn "File: $file2 Not available"
continue
fi
if diff -q $file1 $file2 >/dev/null; then
warn "The files are identical, not running $TOOL"
warn "run $TOOL anyway (y/*) ?"
read -p '' -n1
eof_check "$?"
echo ''
if [ "$REPLY" = "y" ] ; then
launch_meld "$file1" "$file2"
fi
else
launch_meld "$file1" "$file2"
fi
if [ "$number_filtering" -le 1 ]; then
break
fi
done
}
# find quickly the changes
node_meld_2chan() {
# GENERIC =========================================
local parentpath="$1" #
shift #
# get arguments
local SUBDIR="$1"
local FILE_FOR_MELD=$(concat_path "$SUBDIR" "$2")
local LOG="$3"
# dealing with path
local selfpath='2chan'
selfpath=$(concat_path "$parentpath" "$selfpath") #
set_track_path "$selfpath" #
# =================================================
# other args are options of the node.
help_for_meld_2chan() {
menuitem "!" "quit meld 2chan mode"
menuitem "q" "quit opatrack"
}
if [ "$passes_len" -le 0 ] ; then
warn "No pass: This mode is not available"
return
fi
title "Meld 2chan: $FILE_FOR_MELD"
local FILTERING_PASSES=$(filtering_passes "$FILE_FOR_MELD")
local number_filtering=$(echo $FILTERING_PASSES | wc -w | sed -e 's/ *\(.*\)/\1/g')
set_track_path "$selfpath"
# help_for_meld_2chan
local no_changes=1
local i=0
if [ "$LOG" = 'LOG' ] ; then
echo "list of passes with changes:"
else
# avoid to delete the previous line
echo
fi
local always_meld=0
for pass in $FILTERING_PASSES ; do
let "i=$i+1"
file1="$DIR/$pass/$FILE_FOR_MELD"
file2="$DIR2/$pass/$FILE_FOR_MELD"
# check that the same file also exists in the other branch
if [ ! -f "$file2" ] ; then
warn "File: $file2 Not available"
continue
fi
if [ "$LOG" = 'LOG' ] ; then
if ! diff -q $file1 $file2 >/dev/null; then
no_changes=0
echo "$pass" >> $LOGFILE
fi
else
if diff -q $file1 $file2 >/dev/null; then
printf "[F[2K[0G"
printf "pass %d/%d (%s) : no changes\n" $i $number_filtering "$pass"
else
no_changes=0
echo "$pass: changes"
if [ "$always_meld" = 1 ] ; then
launch_meld "$file1" "$file2"
else
warn "run $TOOL (y/a/*) ?"
read -p '' -n1
eof_check "$?"
echo ''
case $REPLY in
y)
launch_meld "$file1" "$file2"
;;
a)
always_meld=1
launch_meld "$file1" "$file2"
;;
!)
return
;;
*)
;;
esac
fi
fi
fi
done
if [ "$no_changes" = 1 ] ; then
echo "no changes on $FILE_FOR_MELD"
fi
}
node_2branches() {
# dealing with path
local selfpath='2bran'
# GENERIC =========================================
local parentpath="$1" #
shift #
local printers_dir=$1
local FILE_FOR_MELD=$2
selfpath=$(concat_path "$parentpath" "$selfpath") #
set_track_path "$selfpath" #
# =================================================
# other args are options of the node.
help_for_name() {
menuitem "d" "2-bran sub-mode"
menuitem "c" "2-chan sub-mode"
menuitem "l" "2-log sub-mode"
menuitem "!" "quit printers mode"
menuitem "q" "quit opatrack"
}