-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathaccept-new-implementations.sh
More file actions
executable file
·104 lines (77 loc) · 3.16 KB
/
accept-new-implementations.sh
File metadata and controls
executable file
·104 lines (77 loc) · 3.16 KB
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
#!/bin/bash
googledownload="Implementations (Responses) - Form Responses 1.tsv"
tsv=implementations.tsv
# Make sure there's exactly one argument and that it's an integer:
if [ $# -eq 1 ] && [ "$1" -eq "$1" ] 2>/dev/null; then
num_new=$1
echo Accepting $num_new implementations from "$googledownload"
else
echo Usage:
echo $0 n
echo where \"n\" is the number of new implementations to take from
echo the Google TSV download into the site\'s official source list
echo of implementations.
exit -1
fi
# First confirm assumptions about fields
# echo Confirming assumptions about fields in $tsv
expectedFieldsFile=implementations-google-column-names.tsv
head -1 "$googledownload" | diff -w $expectedFieldsFile -
if [ ! $? -eq 0 ] ; then
echo Oh no\! Field names were not as expected by $0 - diff above
echo exiting
exit -2
fi
# Make sure the file has at least enough lines for the header row plus $num_new
numlines=`wc -l "$googledownload" | awk '{print $1}'`
if (( $numlines < 1 + $num_new )); then
echo Downloaded TSV file \"$googledownload\"
echo has only $numlines line\(s\) - not enough for a header row plus $num_new new implementations
exit -3;
fi
# The heart of it:
# Remove fields including timestamp, email...
# Append to end of implementations
# `cut` is adding weird ^M newlines, hence the calls to `tr`
tail -$num_new "$googledownload" | cut -f 1-3,5-21,23-24 | tr '\015' '\012' | tr -s '\012' >> $tsv
# echo check for duplicates. Field 4 is \"Name\"
duplicates=`cut -f 4 $tsv | sort | uniq -d`
if [ ! -z "$duplicates" ] ; then
echo Uh oh - there now appear to be multiple rows with the same name:
echo "$duplicates"
echo For each you probably want to choose the better one or merge the two.
echo If you regret having accepted these new implementations you could undo with:
echo " " git checkout implementations.tsv
fi
# Check if any of the submitters are new site contributors and if so
# add them to the list.
contributors=contributors.txt
new=/tmp/newcontribs
# Here's what's happening:
# We want all names alphabetical regardless of whether they have
# websites listed, so special kludge: sort on the second character
# (to ignore the "[" for links) and put a space before the
# non-website ones (so the name starts on the second character of the
# line).
# Breaking down this huge chain of pipes:
# Only the desired number | just contributor's name and possible website |
# XXX temp kludge involving Jeremy |
# convert to markdown (kludgily handing missing websites) |
# sort | uniq
tail -$num_new $tsv | cut -f 2,3 |\
fgrep -v "Jeremy Wagner" |\
awk -F'\t' '{if (length($2)==0) print "", $1; else printf("[%s](%s)\n",$1,$2);}' | \
sort -k 1.2 | uniq > $new
newbies=`comm -13 $contributors $new`
# XXX need to better handle contributors without a website
if [ ! -z "$newbies" ] ; then
echo Adding the following new contributors to $contributors:
echo " $newbies"
# Sort in the new ones, re-using $new
rm -f $new
echo "$newbies" | cat - $contributors | sort -k 1.2 | uniq > $new
cp -f $new $contributors
fi
rm -f $new
echo XXX Need to download any images...
exit 0