-
Notifications
You must be signed in to change notification settings - Fork 3
/
export.sh
executable file
·335 lines (296 loc) · 11.6 KB
/
export.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
#!/bin/bash
# Created by argbash-init v2.10.0
# ARG_OPTIONAL_BOOLEAN([universities],[],[Export the icons of the universities],[on])
# ARG_OPTIONAL_BOOLEAN([companies],[],[Export the icons of the companies],[on])
# ARG_OPTIONAL_BOOLEAN([studies],[],[Export the icons of the studies],[on])
# ARG_OPTIONAL_BOOLEAN([others],[],[Export the icons of the others],[on])
# ARG_OPTIONAL_BOOLEAN([background],[b],[Export the icons with their background],[on])
# ARG_OPTIONAL_BOOLEAN([transparent],[t],[Export the icons with a transparent background],[on])
# ARG_OPTIONAL_BOOLEAN([contest-package],[p],[Export the icons in the Contest Package Format],[on])
# ARG_OPTIONAL_SINGLE([output-directory],[o],[Directory to put the results],[out])
# ARG_POSITIONAL_INF([sizes],[The pixel size to export the icons in],[0],[64])
# ARG_HELP([Export the svg icons in different sizes.])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.9.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
# Generated online by https://argbash.io/generate
die()
{
local _ret="${2:-1}"
test "${_PRINT_HELP:-no}" = yes && print_help >&2
echo "$1" >&2
exit "${_ret}"
}
begins_with_short_option()
{
local first_option all_short_options='btpoh'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - POSITIONALS
_positionals=()
_arg_sizes=("64")
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_universities="on"
_arg_companies="on"
_arg_studies="on"
_arg_others="on"
_arg_background="on"
_arg_transparent="on"
_arg_contest_package="on"
_arg_output_directory="out"
print_help()
{
printf '%s\n' "Export the svg icons in different sizes."
printf 'Usage: %s [--(no-)universities] [--(no-)companies] [--(no-)studies] [--(no-)others] [-b|--(no-)background] [-t|--(no-)transparent] [-p|--(no-)contest-package] [-o|--output-directory <arg>] [-h|--help] [<sizes-1>] ... [<sizes-n>] ...\n' "$0"
printf '\t%s\n' "<sizes>: The pixel size to export the icons in (defaults for <sizes>: '64')"
printf '\t%s\n' "--universities, --no-universities: Export the icons of the universities (on by default)"
printf '\t%s\n' "--companies, --no-companies: Export the icons of the companies (on by default)"
printf '\t%s\n' "--studies, --no-studies: Export the icons of the studies (on by default)"
printf '\t%s\n' "--others, --no-others: Export the icons of the others (on by default)"
printf '\t%s\n' "-b, --background, --no-background: Export the icons with their background (on by default)"
printf '\t%s\n' "-t, --transparent, --no-transparent: Export the icons with a transparent background (on by default)"
printf '\t%s\n' "-p, --contest-package, --no-contest-package: Export the icons in the Contest Package Format (on by default)"
printf '\t%s\n' "-o, --output-directory: Directory to put the results (default: 'out')"
printf '\t%s\n' "-h, --help: Prints help"
}
parse_commandline()
{
_positionals_count=0
while test $# -gt 0
do
_key="$1"
case "$_key" in
--no-universities|--universities)
_arg_universities="on"
test "${1:0:5}" = "--no-" && _arg_universities="off"
;;
--no-companies|--companies)
_arg_companies="on"
test "${1:0:5}" = "--no-" && _arg_companies="off"
;;
--no-studies|--studies)
_arg_studies="on"
test "${1:0:5}" = "--no-" && _arg_studies="off"
;;
--no-others|--others)
_arg_others="on"
test "${1:0:5}" = "--no-" && _arg_others="off"
;;
-b|--no-background|--background)
_arg_background="on"
test "${1:0:5}" = "--no-" && _arg_background="off"
;;
-b*)
_arg_background="on"
_next="${_key##-b}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-b" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-t|--no-transparent|--transparent)
_arg_transparent="on"
test "${1:0:5}" = "--no-" && _arg_transparent="off"
;;
-t*)
_arg_transparent="on"
_next="${_key##-t}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-t" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-p|--no-contest-package|--contest-package)
_arg_contest_package="on"
test "${1:0:5}" = "--no-" && _arg_contest_package="off"
;;
-p*)
_arg_contest_package="on"
_next="${_key##-p}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-p" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-o|--output-directory)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_output_directory="$2"
shift
;;
--output-directory=*)
_arg_output_directory="${_key##--output-directory=}"
;;
-o*)
_arg_output_directory="${_key##-o}"
;;
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
_last_positional="$1"
_positionals+=("$_last_positional")
_positionals_count=$((_positionals_count + 1))
;;
esac
shift
done
}
assign_positional_args()
{
local _positional_name _shift_for=$1
_positional_names=""
_our_args=$((${#_positionals[@]} - 0))
for ((ii = 0; ii < _our_args; ii++))
do
_positional_names="$_positional_names _arg_sizes[$((ii + 0))]"
done
shift "$_shift_for"
for _positional_name in ${_positional_names}
do
test $# -gt 0 || break
eval "$_positional_name=\${1}" || die "Error during argument parsing, possibly an Argbash bug." 1
shift
done
}
parse_commandline "$@"
assign_positional_args 1 "${_positionals[@]}"
# OTHER STUFF GENERATED BY Argbash
### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash
joinByChar() {
local IFS="$1"
shift
echo "$*"
}
# This function is to export a svg to png with the given path and name
export_svg () {
svg_path=$1
name=$2
if [ ! -f "$svg_path" ]; then
echo "Can't find $svg_path for $name"
return
fi
tmpfile=$(mktemp /tmp/svg_logos.XXXXXX)
cp $svg_path $tmpfile
exports=("select:black;selection-hide")
# For every size export a transparent and background version (if neccesery)
for s in ${_arg_sizes[@]}; do
if [ "$_arg_background" = on ]; then
output_file="$_arg_output_directory/background_$s/$name.png"
exports+=("select:background;selection-unhide")
exports+=("export-type:png;export-background-opacity:0;export-width:$s;export-filename:$output_file;export-do")
fi
if [ "$_arg_transparent" = on ]; then
output_file="$_arg_output_directory/transparent_$s/$name.png"
exports+=("select:background;selection-hide")
exports+=("export-type:png;export-background-opacity:0;export-width:$s;export-filename:$output_file;export-do")
fi
done
echo "Exporting $name from $svg_path"
inkscape --actions="$(joinByChar ';' ${exports[@]})" $tmpfile
rm "$tmpfile"
}
UNIVERSITIES_PATH="universities"
COMPANIES_PATH="companies"
STUDIES_PATH="studies"
OTHERS_PATH="others"
CONTEST_PACKAGE_PATH="${_arg_output_directory}/contest-package"
# Make the output directories
[ -d $_arg_output_directory ] || mkdir $_arg_output_directory
for s in ${_arg_sizes[@]}; do
if [ "$_arg_background" = on ]; then
output_dir="$_arg_output_directory/background_$s"
[ -d $output_dir ] || mkdir $output_dir
fi
if [ "$_arg_transparent" = on ]; then
output_dir="$_arg_output_directory/transparent_$s"
[ -d $output_dir ] || mkdir $output_dir
fi
done
# Merge the organization jsons
organizations_paths=()
if [ "$_arg_universities" = on ]; then
organizations_paths+=( "$UNIVERSITIES_PATH/organizations.json" )
fi
if [ "$_arg_companies" = on ]; then
organizations_paths+=( "$COMPANIES_PATH/organizations.json" )
fi
if [ "$_arg_studies" = on ]; then
organizations_paths+=( "$STUDIES_PATH/organizations.json" )
fi
if [ "$_arg_others" = on ]; then
organizations_paths+=( "$OTHERS_PATH/organizations.json" )
fi
jq -s "[.[][] | {\"id\": .id, \"icpc_id\": (.icpc_id? + \"\"), \"name\": .name, \"formal_name\": .formal_name, \"country\": (.country? + \"\"), \"url\": (.url? + \"\") , \"twitter_hashtag\": (.twitter_hashtag? + \"\"), \"twitter_account\": (.twitter_account? + \"\"), \"location\": (.location? + {})}]" "${organizations_paths[@]}" > "$_arg_output_directory/organizations.json"
# Export the svgs
if [ "$_arg_universities" = on ]; then
organizations=$(cat "$UNIVERSITIES_PATH/organizations.json" | jq -r .\[\].id)
for i in $organizations; do
export_svg "$UNIVERSITIES_PATH/logos/$i.svg" $i
done
fi
if [ "$_arg_companies" = on ]; then
organizations=$(cat "$COMPANIES_PATH/organizations.json" | jq -r .\[\].id)
for i in $organizations; do
export_svg "$COMPANIES_PATH/logos/$i.svg" $i
done
fi
if [ "$_arg_studies" = on ]; then
SAVEIFS=$IFS # Save current IFS (Internal Field Separator)
IFS=$'\n' # Change IFS to newline char
organizations=($(cat "$STUDIES_PATH/organizations.json" | jq -r .\[\].id))
combinations=($(cat "$STUDIES_PATH/organizations.json" | jq -r ".[].studies|join(\" \")"))
IFS=$SAVEIFS # Restore original IFS
for i in "${!organizations[@]}"; do
tmpsvg=$(mktemp /tmp/svg_logos.XXXXXX)
$STUDIES_PATH/generate_affiliation.py -o "$tmpsvg" ${combinations[$i]}
export_svg "$tmpsvg" "${organizations[$i]}"
rm "$tmpsvg"
done
fi
if [ "$_arg_others" = on ]; then
others=$(cat "$OTHERS_PATH/organizations.json" | jq -r .\[\].id)
for i in $others; do
export_svg "$OTHERS_PATH/logos/$i.svg" $i
done
fi
if [ "$_arg_contest_package" = on ]; then
mkdir -p "$CONTEST_PACKAGE_PATH/organizations"
cp "$_arg_output_directory/organizations.json" "$CONTEST_PACKAGE_PATH/"
for o in $(jq -r .\[\].id < "$CONTEST_PACKAGE_PATH/organizations.json"); do
mkdir -p "$CONTEST_PACKAGE_PATH/organizations/$o"
for s in "${_arg_sizes[@]}"; do
input="transparent"
if [ "$_arg_background" = on ]; then
input="background"
fi
cp "${_arg_output_directory}/${input}_${s}/${o}.png" "${CONTEST_PACKAGE_PATH}/organizations/${o}/logo.${s}x${s}.png"
done
# Add svg too? CDS seems to support it.
if [[ $o =~ ^C- ]]; then
cp "${COMPANIES_PATH}/logos/${o}.svg" "${CONTEST_PACKAGE_PATH}/organizations/${o}/logo.svg"
elif [[ $o =~ ^O- ]]; then
cp "${OTHERS_PATH}/logos/${o}.svg" "${CONTEST_PACKAGE_PATH}/organizations/${o}/logo.svg"
elif [[ $o =~ ^S- ]]; then
echo "skipping svg copy for ${o}"
else
cp "${UNIVERSITIES_PATH}/logos/${o}.svg" "${CONTEST_PACKAGE_PATH}/organizations/${o}/logo.svg"
fi
done
cat > "${CONTEST_PACKAGE_PATH}/readme.txt" <<<"The contents of this file is to be used with the contest package to be downloaded from ICPC under hamburger menu -> Exports -> Zips -> CPF.
Extract the contest package and extract the values of this package over it.
The new directory can be used to feed DOMjudge (using the import-contest command) and/or put in CDS.
Adding banner and contest logo in directory contest/[banner|logo].png
Adding team pictures in teams/[teamid]/photo.jpg
accounts can be created by adding an accounts.json file
"
fi
# ] <-- needed because of Argbash