Created
October 8, 2014 20:00
-
-
Save sarum9in/90de9be7acde0348f9c9 to your computer and use it in GitHub Desktop.
polyport.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
exec 2>&1 | |
archive="${1:?you have to specify archive}" | |
on_exit() | |
{ | |
if [[ $tmp ]] | |
then | |
rm -rf "$tmp" | |
fi | |
if [[ $query ]] | |
then | |
rm -f "$query" | |
fi | |
} | |
trap on_exit EXIT INT TERM | |
tmp="$(mktemp -d)" | |
query="$(mktemp)" | |
cd "$tmp" | |
unzip "$archive" &>/dev/null | |
root="$(dirname "$0")" | |
for i in * | |
do | |
if [[ -d $i ]] | |
then | |
dst="$root/Archive/$i" | |
rm -rf "$dst" | |
mkdir "$dst" | |
# tests | |
mkdir "$dst/tests" | |
for test_a in `ls "$i/tests/"*.a` | |
do | |
test_id="$(basename "$test_a" .a)" | |
cp -f "$i/tests/$test_id" "$dst/tests/$test_id.in" | |
cp -f "$i/tests/$test_id.a" "$dst/tests/$test_id.out" | |
done | |
"$(dirname "$0")/rmCR.sh" "$dst/tests/"* | |
# checker | |
mkdir "$dst/checker" | |
cp -f "$i/check."* "$dst/checker" | |
echo "checker=check_new" >> "$dst/conf.txt" | |
# statement | |
mkdir "$dst/problem" | |
cp -f "$i/statements/.pdf/russian/problem.pdf" "$dst/problem/statement_ru.pdf" | |
#cp -f "$i/statements/.pdf/english/problem.pdf" "$dst/problem/statement_en.pdf" | |
echo "text=statement_ru.pdf" >> "$dst/conf.txt" | |
# resource limits | |
ml="$(sed -nr 's|^.*<memory-limit>(.*)</memory-limit>.*$|\1|p' <"$i/problem.xml")" | |
echo "ML=$(echo "$ml / (2 ^ 20)" | bc -ql)" >> "$dst/conf.txt" | |
tl="$(sed -nr 's|^.*<time-limit>(.*)</time-limit>.*$|\1|p' <"$i/problem.xml")" | |
echo "TL=$(echo "$tl / 1000" | bc -ql)" >> "$dst/conf.txt" | |
# author | |
echo "author=blakman" >> "$dst/conf.txt" | |
# name | |
echo "name=$(sed -nr 's|^.*<name language="russian" value="([^"]*)"/>.*$|\1|p' <"$i/problem.xml" | iconv -t cp1251)" >> "$dst/conf.txt" | |
# in/out | |
input="$(sed -nr 's|^.*<judging input-file="([^"]*)" output-file="[^"]*">.*$|\1|p' <"$i/problem.xml")" | |
output="$(sed -nr 's|^.*<judging input-file="[^"]*" output-file="([^"]*)">.*$|\1|p' <"$i/problem.xml")" | |
if [[ -n $input ]] | |
then | |
echo "input=$input" >> "$dst/conf.txt" | |
fi | |
if [[ -n $output ]] | |
then | |
echo "output=$output" >> "$dst/conf.txt" | |
fi | |
# misc | |
mkdir "$dst/misc" | |
cp -rf "$i/statements" "$dst/misc" | |
cp -rf "$i/files" "$dst/misc" | |
cp -rf "$i/solutions" "$dst/misc" | |
cp -f "$i/problem.xml" "$dst/misc" | |
fi | |
done | |
"$root/repack.sh" * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment