-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathjfltr
executable file
·162 lines (135 loc) · 4.79 KB
/
jfltr
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
#!/usr/bin/env bash
me=$( basename $0 )
#[[ "$1" != test && "$1" != production ]] && {
[[ "$1" == go ]] || {
cat << EOT
Usage: $me go [ export ]
Download YAMZ production tables into JSON files, and convert references in
those files from old- to new-style from either the "test" or "production"
tables. This script does not itself change any data on either the test or
production instance -- see the test_yamz_reload script.
EOT
exit
}
if [[ "$2" ]]
then
[[ "$2" != export ]] && {
echo "error: unrecognized second argument: $2"
echo
$0
exit 1
}
export=1
fi
ydb=$( ./whichydb get )
[[ $ydb != yamz ]] && {
echo 'first do "./whichydb set_production" and follow its instructions'
exit 1
}
# Temporarily put a python script we'll use in the var $python_mload,
# using a "heredoc" (<<) so we don't have worry about quotes
# surrounding it. Use the var right afterwards with python
#
read -r -d '' python_mload << 'EOT'
# start embedded Python program to normalize old- to new-style refs
import sys, json
import seaice
# Establish connection to DATABASE_URL -- we will be readonly with the
# database as we massage the json files.
#
sea = seaice.SeaIceConnector()
#cur = sea.con.cursor()
#ta = json.load(sys.stdin)
filename='Terms.json' # process Terms
with open('yolists/' + filename) as fp:
ta = json.load(fp)
for t in ta:
t['definition'] = seaice.pretty.refs_norm(sea, t['definition'])
t['examples'] = seaice.pretty.refs_norm(sea, t['examples'])
with open('ynlists/' + filename, 'w') as np:
json.dump(ta, np, sort_keys=True, indent=2, separators=(',', ': '))
print >>np # add final newline
filename='Comments.json' # process Comments
with open('yolists/' + filename) as fp:
ta = json.load(fp)
for t in ta:
t['comment_string'] = seaice.pretty.refs_norm(sea, t['comment_string'])
with open('ynlists/' + filename, 'w') as np:
json.dump(ta, np, sort_keys=True, indent=2, separators=(',', ': '))
print >>np # add final newline
filename='Users.json' # process Users
with open('yolists/' + filename) as fp:
ta = json.load(fp)
for t in ta:
if t['email'] in ('[email protected]', '[email protected]',
t['super_user'] = True
with open('ynlists/' + filename, 'w') as np:
json.dump(ta, np, sort_keys=True, indent=2, separators=(',', ': '))
print >>np # add final newline
#json.dump(ta, sys.stdout, sort_keys=True, indent=2, separators=(',', ': '))
#print >>sys.stdout # add final newline
# end embedded Python program
EOT
if [[ $export ]]
then
echo exporting $ydb tables
for t in Users Terms Comments Tracking
do
#--config=heroku
./sea.py --export=$t > $t.json
echo -n " " $( grep -c '^ {' $t.json ) $t,
done
echo " done"
fi
echo pre-processing $ydb Terms and Comments tables
for f in Terms Comments
do
perl -p \
-e 's/\s*(\\r\\n)*\s*",$/",/;' \
-e '/"definition":/ and s/\s*(\\r\\n)*\s*(#({g:[^"]+|\w+)",)$/\\r\\n$2/;' \
-e 's/"#ppsr_term *(\\r\\n\\r\\n)?(.*)"/"$2\\r\\n#ppsr_term"/;' \
-e 's/#ppsr_term/#citsci/g;' \
-e 's/#{(\d\d\d\d)/#{h$1/g;' \
-e 's/#(\d+|information)/##$1/ig;' \
-e 's/: relates to}/: related to}/g;' \
-e 's/: bretter term}/: related to}/g;' \
< $f.json > yolists/$f.json
#-e 's/ *#DesignSafeCentrifuge(\\r\\n)?"/\\r\\n#DesignSafeCentrifuge"/' \
echo -n " " $( grep -c '^ {' $f.json ) $f,
done
cp Users.json yolists/
echo " done"
echo normalizing old- to new-style refs in Terms and Comments JSON files
echo adding super_user flag for some users
# Call script saved in $python_load, passing values via environment variables.
env python -c "$python_mload"
for t in Users Terms Comments Tracking
do
echo -n " " $( grep -c '^ {' $t.json ) $t,
done
echo " done"
echo "copying finalized files into ynlists/*.json"
cp Tracking.json ynlists/ # one untouched file
cat << EOT
When done, check that yamz prod has no new terms (if not, re-run).
Then deploy new code to prod. yamz (use tyamz script for inspiration).
Test prod code a bit (CVP, Project*), then, to correct prod tables:
1. vi ynlists/{Terms,Comments}.json
2 change ownership of #citsci -> "owner_id": 1053
3. correct permanAnce (A->e)
4. globally substitute for
#citsci, #DesignSafe, #DesignSafeCentrifuge, #permanence
as needed; use form: term_string": "#{g: xqcitsci | h1266}",
#Concepts (termstring isn't right though) already in yamz:
#citsic h1266
#permanence h1265
#DesignSafeCentrifuge h1268
#DesignSafe h1267
5. use "./whichydb ..." to set DATABASE_URL for production loading
6. edit ./test_yamz_reload to make "tydb=yamz"
7. run ./test_yamz_reload go to OVERWRITE production
XXX official docs say to use ./sea.py --config=heroku, but it's not
necessary -- this could lead one into trouble?
(Finally, comment out old tag processing code and redeploy.)
EOT