-
Notifications
You must be signed in to change notification settings - Fork 1
/
plumbr.sh
145 lines (135 loc) · 3.22 KB
/
plumbr.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
# Decide on what parts of the pipeline require other parts
for NODENAME in ${PIPELINE[@]}
do {
NODE=$DIR_NODES/$NODENAME.sh
if [[ ! -f $NODE ]]
then
echo ERROR: $NODE not found
exit
fi
REQS=(`grep '^#RS requires' $NODE | cut -d\ -f3-`)
PROS=(`grep '^#RS provides' $NODE | cut -d\ -f3-`)
TYPE=(`grep '^#RS widenode' $NODE | cut -d\ -f2-`)
if [ "$TYPE" = 'widenode' ]
then
WIDENODES+=($NODENAME)
declare "WIDENODES_${NODENAME}=1"
fi
#echo ${WIDENODES[@]}
# Determine what this node provides
for PRO in ${PROS[@]}
do
if [ `arrayGet PROVIDES $PRO` ]
then
echo COLLISION: $PRO by $NODENAME is already provided by `arrayGet PROVIDES $PRO`
exit
fi
# Get rid of dots for variable declaration
PRO=`replaceDots $PRO`
# Remember the provided output
declare "PROVIDES_${PRO}=${NODENAME}"
done
# Determine what nodes provide the requirements
for REQ in ${REQS[@]}
do
if [ ! `arrayGet PROVIDES $REQ` ]
then
echo MISSING: requirement $REQ by $NODENAME is UNKNOWN
exit
fi
# Remember the stated requirement
declare "REQUIRES_${NODENAME}=${REQ} `arrayGet REQUIRES $NODENAME`"
done
} done
# Look through the pipe and see what it is connected to
traceReq(){
local TRACES=`arrayGet REQUIRES $1`
for TRACE in ${TRACES[@]}
do
IGNORETRACE=0
# If provided by conf (i.e. prev broken run) don't bother
for INNAME in ${PIPE_WANTEDIN[@]}
do
if [ "$TRACE" == "$INNAME" ]
then
IGNORETRACE=1
break
fi
done
# Not provided, trace the pipe
if [ $IGNORETRACE -eq 0 ]
then
PLUNGED+=(`arrayGet PROVIDES $TRACE`)
traceReq `arrayGet PROVIDES $TRACE`
fi
done
}
# Check for wanted outputs and only keep required nodes to reach our goals
if [ ! "$PIPE_WANTEDOUT" == "" ]
then {
PLUNGED=()
for OUTNAME in ${PIPE_WANTEDOUT[@]}
do
NODENAME=`arrayGet PROVIDES $OUTNAME`
PLUNGED+=($NODENAME)
traceReq $NODENAME
done
# Create a shorter pipeline if possible
REDUCEDPIPE=()
for PIPE in ${PIPELINE[@]}
do
for PLUN in ${PLUNGED[@]}
do
if [ "$PIPE" == "$PLUN" ]
then
REDUCEDPIPE+=($PIPE)
break
fi
done
done
# Take the shortcut
echo Plunging the pipeline resulted in: ${REDUCEDPIPE[@]}
PIPELINE=() # Empty it first, simply overwriting goes wrong
PIPELINE=${REDUCEDPIPE[@]}
} fi
NEEDS_RUN_DATE=`date +%y%m%d_%H%M%S`
# Additionally check if step is necessary for this sample at this moment, could skip if output exists and is newer than inputs and NODE.sh
needsRun() {
NODEDATE=`date -r $NODE +%s`
OUTDATE=-2
INDATE=-1
for PRO in ${PROS[@]}
do
if [ -f $FILE_OUTPUT.$PRO ]
then
OUTDATE=`date -r $FILE_OUTPUT.$PRO +%s`
if (( $OUTDATE < $NODEDATE ))
then
#rm $FILE_OUTPUT.$PRO
mv $FILE_OUTPUT.$PRO $FILE_OUTPUT.$PRO.pre$NEEDS_RUN_DATE
return 0
fi
for REQ in ${REQS[@]}
do
# Req file does not exist, removed or never there
if [[ ! -f $FILE_OUTPUT.$REQ ]]
then
return 0
fi
# If the req file is newer than the pro file, redo
INDATE=`date -r $FILE_OUTPUT.$REQ +%s`
if (( $OUTDATE < $INDATE ))
then
#rm $FILE_OUTPUT.$PRO
mv $FILE_OUTPUT.$PRO $FILE_OUTPUT.$PRO.pre$NEEDS_RUN_DATE
return 0
fi
done
else
# If file simply doesn't exist
return 0
fi
done
# Nothing to do here
return 1
}