forked from PSLmodels/taxdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsvmake
executable file
·127 lines (114 loc) · 2.69 KB
/
csvmake
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
#!/bin/bash
# executes taxdata Python scripts through the specified last stage
function usage {
echo "USAGE: ./csvmake DATATYPE LASTSTAGE"
echo " where DATATYPE can be puf or cps"
echo " and LASTSTAGE can be 1 or 2 or 3"
echo " Note: run ./csvmake in top-level taxdata directory"
echo "Execution time will be roughly one hour when LASTSTAGE is 2 or 3"
exit 1
}
function gitdiffs {
git diff --quiet
if [ $? -eq 0 ]; then
echo "NO 'git diff' OUTPUT ==> NO CHANGES IN FILES"
else
echo "SOME 'git diff' OUTPUT ==> CHANGES IN FILES"
echo "USE 'git status' TO SEE IF CSV OUTPUT FILES CHANGED"
fi
}
# process command-line arguments
if [ $# -ne 2 ]; then
echo "ERROR: number of command-line arguments is not two"
usage
fi
DTYPE=$1
if [ $DTYPE != "puf" ] && [ $DTYPE != "cps" ]; then
echo "ERROR: DATATYPE is neither puf nor cps"
usage
fi
LSTAGE=$2
if [ $LSTAGE -ne 1 ] && [ $LSTAGE -ne 2 ] && [ $LSTAGE -ne 3 ]; then
echo "ERROR: LASTSTAGE is neither 1 nor 2 nor 3"
usage
fi
# TODO TEMPORARY CODE BELOW
if [ $DTYPE == "cps" ]; then
echo "ERROR: DATATYPE cannot be cps yet"
usage
fi
# TODO TEMPORARY CODE ABOVE
# execute $DTYPE_data script before taking steps
DP=$DTYPE"_data"
cd $DP
echo "`date` : $DP START"
python finalprep.py
if [ $? -ne 0 ]; then
echo "ERROR: executing $DP_data/finalprep.py script"
gitdiffs
exit 1
fi
echo "`date` : $DP FINISH"
cd ..
# execute stage1 scripts
cd stage1
echo "`date` : stage1 START"
python stage1.py
if [ $? -ne 0 ]; then
echo "ERROR: executing stage1.py script"
gitdiffs
exit 1
fi
python factors_finalprep.py
if [ $? -ne 0 ]; then
echo "ERROR: executing stage1/finalprep.py script"
gitdiffs
exit 1
fi
echo "`date` : stage1 FINISH"
cd ..
# consider stopping after stage1 scripts have executed
if [ $LSTAGE -eq 1 ]; then
echo "STOPPING AFTER stage1"
gitdiffs
exit 0
fi
# execute $DTYPE_stage2 script
S2=$DTYPE"_stage2"
cd $S2
echo "`date` : $S2 START"
python stage2.py
RC=$?
rm -f *.pyc
if [ $RC -ne 0 ]; then
echo "ERROR: executing $S2/stage2.py script"
gitdiffs
exit 1
fi
echo "`date` : $S2 FINISH"
cd ..
# consider stopping after $DTYPE_stage2 script has executed
if [ $LSTAGE -eq 2 ]; then
echo "STOPPING AFTER $S2"
gitdiffs
exit 0
fi
# execute $DTYPE_stage3 script
S3=$DTYPE"_stage3"
cd $S3
echo "`date` : $S3 START"
python stage3.py
if [ $? -ne 0 ]; then
echo "ERROR: executing $S3/stage3.py script"
gitdiffs
exit 1
fi
echo "`date` : $S3 FINISH"
cd ..
# consider stopping after $DTYPE_stage3 script has executed
if [ $LSTAGE -eq 3 ]; then
echo "STOPPING AFTER $S3"
gitdiffs
exit 0
fi
exit 0