rbx.cp 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. rbx/__init__.py +0 -0
  2. rbx/annotations.py +127 -0
  3. rbx/autoenum.py +333 -0
  4. rbx/box/__init__.py +0 -0
  5. rbx/box/builder.py +77 -0
  6. rbx/box/cd.py +37 -0
  7. rbx/box/checkers.py +134 -0
  8. rbx/box/code.py +185 -0
  9. rbx/box/compile.py +56 -0
  10. rbx/box/conftest.py +42 -0
  11. rbx/box/contest/__init__.py +0 -0
  12. rbx/box/contest/build_contest_statements.py +347 -0
  13. rbx/box/contest/contest_package.py +76 -0
  14. rbx/box/contest/contest_utils.py +20 -0
  15. rbx/box/contest/main.py +179 -0
  16. rbx/box/contest/schema.py +155 -0
  17. rbx/box/contest/statements.py +82 -0
  18. rbx/box/creation.py +72 -0
  19. rbx/box/download.py +64 -0
  20. rbx/box/environment.py +345 -0
  21. rbx/box/extensions.py +26 -0
  22. rbx/box/generators.py +478 -0
  23. rbx/box/generators_test.py +63 -0
  24. rbx/box/main.py +449 -0
  25. rbx/box/package.py +316 -0
  26. rbx/box/packaging/boca/extension.py +27 -0
  27. rbx/box/packaging/boca/packager.py +245 -0
  28. rbx/box/packaging/contest_main.py +82 -0
  29. rbx/box/packaging/main.py +68 -0
  30. rbx/box/packaging/packager.py +117 -0
  31. rbx/box/packaging/polygon/packager.py +320 -0
  32. rbx/box/packaging/polygon/test.py +81 -0
  33. rbx/box/packaging/polygon/xml_schema.py +106 -0
  34. rbx/box/presets/__init__.py +503 -0
  35. rbx/box/presets/fetch.py +70 -0
  36. rbx/box/presets/lock_schema.py +20 -0
  37. rbx/box/presets/schema.py +59 -0
  38. rbx/box/schema.py +394 -0
  39. rbx/box/solutions.py +792 -0
  40. rbx/box/solutions_test.py +41 -0
  41. rbx/box/statements/__init__.py +0 -0
  42. rbx/box/statements/build_statements.py +359 -0
  43. rbx/box/statements/builders.py +375 -0
  44. rbx/box/statements/joiners.py +113 -0
  45. rbx/box/statements/latex.py +47 -0
  46. rbx/box/statements/latex_jinja.py +214 -0
  47. rbx/box/statements/schema.py +138 -0
  48. rbx/box/stresses.py +292 -0
  49. rbx/box/stressing/__init__.py +0 -0
  50. rbx/box/stressing/finder_parser.py +359 -0
  51. rbx/box/stressing/generator_parser.py +258 -0
  52. rbx/box/testcases.py +54 -0
  53. rbx/box/ui/__init__.py +0 -0
  54. rbx/box/ui/captured_log.py +372 -0
  55. rbx/box/ui/css/app.tcss +48 -0
  56. rbx/box/ui/main.py +38 -0
  57. rbx/box/ui/run.py +209 -0
  58. rbx/box/validators.py +245 -0
  59. rbx/box/validators_test.py +15 -0
  60. rbx/checker.py +128 -0
  61. rbx/clone.py +197 -0
  62. rbx/config.py +271 -0
  63. rbx/conftest.py +38 -0
  64. rbx/console.py +27 -0
  65. rbx/create.py +37 -0
  66. rbx/edit.py +24 -0
  67. rbx/grading/__init__.py +0 -0
  68. rbx/grading/caching.py +356 -0
  69. rbx/grading/conftest.py +33 -0
  70. rbx/grading/judge/__init__.py +0 -0
  71. rbx/grading/judge/cacher.py +503 -0
  72. rbx/grading/judge/digester.py +35 -0
  73. rbx/grading/judge/sandbox.py +748 -0
  74. rbx/grading/judge/sandboxes/__init__.py +0 -0
  75. rbx/grading/judge/sandboxes/isolate.py +683 -0
  76. rbx/grading/judge/sandboxes/stupid_sandbox.py +310 -0
  77. rbx/grading/judge/sandboxes/timeit.py +217 -0
  78. rbx/grading/judge/storage.py +284 -0
  79. rbx/grading/judge/test.py +38 -0
  80. rbx/grading/judge/testiso.py +54 -0
  81. rbx/grading/steps.py +522 -0
  82. rbx/grading/steps_with_caching.py +59 -0
  83. rbx/grading/steps_with_caching_run_test.py +429 -0
  84. rbx/grading_utils.py +148 -0
  85. rbx/hydration.py +101 -0
  86. rbx/main.py +122 -0
  87. rbx/metadata.py +105 -0
  88. rbx/providers/__init__.py +43 -0
  89. rbx/providers/codeforces.py +73 -0
  90. rbx/providers/provider.py +26 -0
  91. rbx/resources/checkers/boilerplate.cpp +20 -0
  92. rbx/resources/default_config.json +48 -0
  93. rbx/resources/envs/default.rbx.yml +37 -0
  94. rbx/resources/envs/isolate.rbx.yml +37 -0
  95. rbx/resources/packagers/boca/checker.sh +43 -0
  96. rbx/resources/packagers/boca/compare +53 -0
  97. rbx/resources/packagers/boca/compile/c +172 -0
  98. rbx/resources/packagers/boca/compile/cc +173 -0
  99. rbx/resources/packagers/boca/compile/cpp +172 -0
  100. rbx/resources/packagers/boca/compile/java +194 -0
  101. rbx/resources/packagers/boca/compile/kt +155 -0
  102. rbx/resources/packagers/boca/compile/pas +172 -0
  103. rbx/resources/packagers/boca/compile/py2 +173 -0
  104. rbx/resources/packagers/boca/compile/py3 +173 -0
  105. rbx/resources/packagers/boca/run/c +128 -0
  106. rbx/resources/packagers/boca/run/cc +128 -0
  107. rbx/resources/packagers/boca/run/cpp +128 -0
  108. rbx/resources/packagers/boca/run/java +194 -0
  109. rbx/resources/packagers/boca/run/kt +159 -0
  110. rbx/resources/packagers/boca/run/py2 +166 -0
  111. rbx/resources/packagers/boca/run/py3 +166 -0
  112. rbx/resources/presets/default/contest/contest.rbx.yml +14 -0
  113. rbx/resources/presets/default/contest/statement/contest.rbx.tex +97 -0
  114. rbx/resources/presets/default/contest/statement/olymp.sty +250 -0
  115. rbx/resources/presets/default/contest/statement/template.rbx.tex +42 -0
  116. rbx/resources/presets/default/preset.rbx.yml +12 -0
  117. rbx/resources/presets/default/problem/.gitignore +6 -0
  118. rbx/resources/presets/default/problem/gen.cpp +9 -0
  119. rbx/resources/presets/default/problem/problem.rbx.yml +44 -0
  120. rbx/resources/presets/default/problem/random.py +3 -0
  121. rbx/resources/presets/default/problem/random.txt +2 -0
  122. rbx/resources/presets/default/problem/sols/main.cpp +9 -0
  123. rbx/resources/presets/default/problem/sols/slow.cpp +15 -0
  124. rbx/resources/presets/default/problem/sols/wa.cpp +9 -0
  125. rbx/resources/presets/default/problem/statement/olymp.sty +250 -0
  126. rbx/resources/presets/default/problem/statement/projecao.png +0 -0
  127. rbx/resources/presets/default/problem/statement/statement.rbx.tex +18 -0
  128. rbx/resources/presets/default/problem/statement/template.rbx.tex +89 -0
  129. rbx/resources/presets/default/problem/tests/samples/000.in +1 -0
  130. rbx/resources/presets/default/problem/tests/samples/001.in +1 -0
  131. rbx/resources/presets/default/problem/validator.cpp +16 -0
  132. rbx/resources/presets/default/problem/wcmp.cpp +34 -0
  133. rbx/resources/templates/template.cpp +19 -0
  134. rbx/run.py +45 -0
  135. rbx/schema.py +64 -0
  136. rbx/submit.py +61 -0
  137. rbx/submitors/__init__.py +18 -0
  138. rbx/submitors/codeforces.py +120 -0
  139. rbx/submitors/submitor.py +25 -0
  140. rbx/test.py +347 -0
  141. rbx/testcase.py +70 -0
  142. rbx/testcase_rendering.py +79 -0
  143. rbx/testdata/box1/gen1.cpp +7 -0
  144. rbx/testdata/box1/gen2.cpp +9 -0
  145. rbx/testdata/box1/genScript.py +2 -0
  146. rbx/testdata/box1/hard-tle.sol.cpp +26 -0
  147. rbx/testdata/box1/ole.cpp +17 -0
  148. rbx/testdata/box1/problem.rbx.yml +39 -0
  149. rbx/testdata/box1/re.sol.cpp +23 -0
  150. rbx/testdata/box1/sol.cpp +22 -0
  151. rbx/testdata/box1/tests/1.in +1 -0
  152. rbx/testdata/box1/tle-and-incorrect.sol.cpp +33 -0
  153. rbx/testdata/box1/tle.sol.cpp +35 -0
  154. rbx/testdata/box1/validator.cpp +11 -0
  155. rbx/testdata/box1/wa.sol.cpp +22 -0
  156. rbx/testdata/caching/executable.py +1 -0
  157. rbx/testdata/compatible +0 -0
  158. rbx/testing_utils.py +65 -0
  159. rbx/utils.py +162 -0
  160. rbx_cp-0.5.0.dist-info/LICENSE +201 -0
  161. rbx_cp-0.5.0.dist-info/METADATA +89 -0
  162. rbx_cp-0.5.0.dist-info/RECORD +164 -0
  163. rbx_cp-0.5.0.dist-info/WHEEL +4 -0
  164. rbx_cp-0.5.0.dist-info/entry_points.txt +4 -0
@@ -0,0 +1,172 @@
1
+ #!/bin/bash
2
+ # ////////////////////////////////////////////////////////////////////////////////
3
+ # //BOCA Online Contest Administrator
4
+ # // Copyright (C) 2003-2014 by BOCA System (bocasystem@gmail.com)
5
+ # //
6
+ # // This program is free software: you can redistribute it and/or modify
7
+ # // it under the terms of the GNU General Public License as published by
8
+ # // the Free Software Foundation, either version 3 of the License, or
9
+ # // (at your option) any later version.
10
+ # //
11
+ # // This program is distributed in the hope that it will be useful,
12
+ # // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # // GNU General Public License for more details.
15
+ # // You should have received a copy of the GNU General Public License
16
+ # // along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ # ////////////////////////////////////////////////////////////////////////////////
18
+ #Last modified: 21/august/2014 by cassio@ime.usp.br
19
+ #
20
+ # parameters are:
21
+ # $1 source_file
22
+ # $2 exe_file (default run.exe)
23
+ # $3 timelimit
24
+ # $4 maximum allowed memory (in MBytes, default 512M)
25
+ #
26
+ # the output of the submission should be directed to the standard output
27
+ #
28
+ # the return code show what happened (according to safeexec):
29
+ # 0 ok
30
+ # 1 compile error
31
+ # 2 runtime error
32
+ # 3 timelimit exceeded
33
+ # 4 internal error
34
+ # 5 parameter error
35
+ # 6 internal error
36
+ # 7 memory limit exceeded
37
+ # 8 security threat
38
+ # 9 runtime error
39
+ # other_codes are unknown to boca: in this case BOCA will present the
40
+ # last line of standard output to the judge
41
+
42
+ umask 0022
43
+
44
+ if [ "$1" == "" ]; then
45
+ echo "parameter problem"
46
+ exit 43
47
+ fi
48
+ if [ ! -r "$1" ]; then
49
+ echo "$1 not found or it's not readable"
50
+ exit 44
51
+ fi
52
+ name="$1"
53
+ if [ ! -r "$1" ]; then
54
+ echo "$1 not found or it's not readable"
55
+ exit 44
56
+ fi
57
+ mkdir -p src
58
+ if [ "${name##*.}" == "zip" -a "${name##*.}" == "ZIP" ]; then
59
+ unzip "$name" -d src
60
+ name="*.c"
61
+ else
62
+ cp "$name" src
63
+ fi
64
+ id -u bocajail >/dev/null 2>/dev/null
65
+ if [ $? == 0 ]; then
66
+ bocau=$(id -u bocajail)
67
+ bocag=$(id -g bocajail)
68
+ chown bocajail.nogroup .
69
+ else
70
+ bocau=$(id -u nobody)
71
+ bocag=$(id -g nobody)
72
+ chown nobody.nogroup .
73
+ fi
74
+ if [ "$bocau" == "" -o "$bocag" == "" ]; then
75
+ echo "error finding user to run script"
76
+ exit 43
77
+ fi
78
+
79
+ # this script makes use of safeexec to execute the code with less privilegies
80
+ # make sure that directories below are correct.
81
+ sf=$(which safeexec)
82
+ [ -x "$sf" ] || sf=/usr/bin/safeexec
83
+ if [ ! -x $sf ]; then
84
+ echo "$sf not found or it's not executable"
85
+ exit 46
86
+ fi
87
+ maxm=512000
88
+ if [ "$4" != "" ]; then
89
+ if [ "$4" -gt "512" ]; then
90
+ maxm=${4}000
91
+ fi
92
+ fi
93
+
94
+ # setting up the timelimit according to the problem
95
+ if [ "$3" == "" ]; then
96
+ time=5
97
+ else
98
+ time=$3
99
+ fi
100
+ let "ttime = $time + 30"
101
+
102
+ if [ "$2" == "" ]; then
103
+ exe=run.exe
104
+ else
105
+ exe=$2
106
+ fi
107
+
108
+ rm -f "$exe" compileit.retcode runit.retcode 2>/dev/null
109
+ cat <<EOF >compileit.sh
110
+ #!/bin/bash
111
+ cc=\`which gcc\`
112
+ [ -x "\$cc" ] || cc=/usr/bin/gcc
113
+ if [ ! -x "\$cc" ]; then
114
+ echo "\$cc not found or it's not executable"
115
+ exit 47
116
+ fi
117
+ cd src
118
+ "\$cc" {{rbxFlags}} "../$exe" "$name"
119
+ echo \$? > ../compileit.retcode
120
+ exit 0
121
+ EOF
122
+ chmod 755 compileit.sh
123
+
124
+ cdir=$(pwd)
125
+ echo "Current directory is $cdir" >&2
126
+ echo $cdir | grep -q "/bocajail"
127
+ if [ $? == 0 ]; then
128
+ cdir=$(echo $cdir | sed "s/.*\/bocajail//")
129
+ echo "Internal directory is $cdir"
130
+ cat <<EOF >runit.sh
131
+ #!/bin/bash
132
+ cd "$cdir"
133
+ [ -f /proc/cpuinfo ] || /bin/mount -t proc proc /proc
134
+ #/bin/mount --bind /dev /dev
135
+ [ -d /sys/kernel ] || /bin/mount -t sysfs sysfs /sys
136
+ $sf -r1 -F1000 -n0 -U$bocau -G$bocag -C. -ostdout0 -estderr0 -d$maxm -m$maxm -f20000 -t$ttime -T$ttime ./compileit.sh
137
+ echo \$? > runit.retcode
138
+ if [ ! -e /bocajail ]; then
139
+ /bin/umount /proc 2>/dev/null
140
+ #/bin/umount /dev
141
+ /bin/umount /sys 2>/dev/null
142
+ fi
143
+ EOF
144
+ chmod 755 runit.sh
145
+ chroot /bocajail "$cdir/runit.sh"
146
+ if [ -r runit.retcode ]; then
147
+ ret=$(cat runit.retcode)
148
+ else
149
+ ret=99
150
+ fi
151
+ else
152
+ echo "COMPILATION IS NOT BEING CHROOTED -- THIS IS NOT AN IDEAL SETTING"
153
+ $sf -r1 -F1000 -n0 -U$bocau -G$bocag -C. -ostdout0 -estderr0 -d$maxm -m$maxm -f20000 -t$ttime -T$ttime ./compileit.sh
154
+ ret=$?
155
+ fi
156
+ if [ -f "stdout0" ]; then
157
+ cat "stdout0"
158
+ fi
159
+ if [ -f "stderr0" ]; then
160
+ cat "stderr0"
161
+ fi
162
+ rm -rf src/
163
+ if [ "$ret" != "0" ]; then
164
+ echo "Compilation Error: $ret"
165
+ exit $ret
166
+ fi
167
+ ret=$(cat compileit.retcode)
168
+ if [ "$ret" != "0" ]; then
169
+ echo "Compilation Error: $ret"
170
+ ret=1
171
+ fi
172
+ exit $ret
@@ -0,0 +1,173 @@
1
+ #!/bin/bash
2
+ # ////////////////////////////////////////////////////////////////////////////////
3
+ # //BOCA Online Contest Administrator
4
+ # // Copyright (C) 2003-2014 by BOCA System (bocasystem@gmail.com)
5
+ # //
6
+ # // This program is free software: you can redistribute it and/or modify
7
+ # // it under the terms of the GNU General Public License as published by
8
+ # // the Free Software Foundation, either version 3 of the License, or
9
+ # // (at your option) any later version.
10
+ # //
11
+ # // This program is distributed in the hope that it will be useful,
12
+ # // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # // GNU General Public License for more details.
15
+ # // You should have received a copy of the GNU General Public License
16
+ # // along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ # ////////////////////////////////////////////////////////////////////////////////
18
+ #Last modified: 26/august/2014 by cassio@ime.usp.br
19
+ # definition of -std=c++XX, as configured in the Boca extension.
20
+ #
21
+ # parameters are:
22
+ # $1 source_file
23
+ # $2 exe_file (default run.exe)
24
+ # $3 timelimit
25
+ # $4 maximum allowed memory (in MBytes)
26
+ #
27
+ # the output of the submission should be directed to the standard output
28
+ #
29
+ # the return code show what happened (according to safeexec):
30
+ # 0 ok
31
+ # 1 compile error
32
+ # 2 runtime error
33
+ # 3 timelimit exceeded
34
+ # 4 internal error
35
+ # 5 parameter error
36
+ # 6 internal error
37
+ # 7 memory limit exceeded
38
+ # 8 security threat
39
+ # 9 runtime error
40
+ # other_codes are unknown to boca: in this case BOCA will present the
41
+ # last line of standard output to the judge
42
+
43
+ umask 0022
44
+
45
+ if [ "$1" == "" ]; then
46
+ echo "parameter problem"
47
+ exit 43
48
+ fi
49
+ if [ ! -r "$1" ]; then
50
+ echo "$1 not found or it's not readable"
51
+ exit 44
52
+ fi
53
+ name="$1"
54
+ if [ ! -r "$1" ]; then
55
+ echo "$1 not found or it's not readable"
56
+ exit 44
57
+ fi
58
+ mkdir -p src
59
+ if [ "${name##*.}" == "zip" -a "${name##*.}" == "ZIP" ]; then
60
+ unzip "$name" -d src
61
+ name="*.c"
62
+ else
63
+ cp "$name" src
64
+ fi
65
+ id -u bocajail >/dev/null 2>/dev/null
66
+ if [ $? == 0 ]; then
67
+ bocau=$(id -u bocajail)
68
+ bocag=$(id -g bocajail)
69
+ chown bocajail.nogroup .
70
+ else
71
+ bocau=$(id -u nobody)
72
+ bocag=$(id -g nobody)
73
+ chown nobody.nogroup .
74
+ fi
75
+ if [ "$bocau" == "" -o "$bocag" == "" ]; then
76
+ echo "error finding user to run script"
77
+ exit 43
78
+ fi
79
+
80
+ # this script makes use of safeexec to execute the code with less privilegies
81
+ # make sure that directories below are correct.
82
+ sf=$(which safeexec)
83
+ [ -x "$sf" ] || sf=/usr/bin/safeexec
84
+ if [ ! -x $sf ]; then
85
+ echo "$sf not found or it's not executable"
86
+ exit 46
87
+ fi
88
+ maxm=512000
89
+ if [ "$4" != "" ]; then
90
+ if [ "$4" -gt "512" ]; then
91
+ maxm=${4}000
92
+ fi
93
+ fi
94
+
95
+ # setting up the timelimit according to the problem
96
+ if [ "$3" == "" ]; then
97
+ time=5
98
+ else
99
+ time=$3
100
+ fi
101
+ let "ttime = $time + 30"
102
+
103
+ if [ "$2" == "" ]; then
104
+ exe=run.exe
105
+ else
106
+ exe=$2
107
+ fi
108
+
109
+ rm -f "$exe" compileit.retcode runit.retcode 2>/dev/null
110
+ cat <<EOF >compileit.sh
111
+ #!/bin/bash
112
+ cc=\`which g++\`
113
+ [ -x "\$cc" ] || cc=/usr/bin/g++
114
+ if [ ! -x "\$cc" ]; then
115
+ echo "\$cc not found or it's not executable"
116
+ exit 47
117
+ fi
118
+ cd src
119
+ "\$cc" {{rbxFlags}} -o "../$exe" "$name"
120
+ echo \$? > ../compileit.retcode
121
+ exit 0
122
+ EOF
123
+ chmod 755 compileit.sh
124
+
125
+ cdir=$(pwd)
126
+ echo "Current directory is $cdir" >&2
127
+ echo $cdir | grep -q "/bocajail"
128
+ if [ $? == 0 ]; then
129
+ cdir=$(echo $cdir | sed "s/.*\/bocajail//")
130
+ echo "Internal directory is $cdir"
131
+ cat <<EOF >runit.sh
132
+ #!/bin/bash
133
+ cd "$cdir"
134
+ [ -f /proc/cpuinfo ] || /bin/mount -t proc proc /proc
135
+ #/bin/mount --bind /dev /dev
136
+ [ -d /sys/kernel ] || /bin/mount -t sysfs sysfs /sys
137
+ $sf -r1 -F1000 -n0 -U$bocau -G$bocag -C. -ostdout0 -estderr0 -d$maxm -m$maxm -f20000 -t$ttime -T$ttime ./compileit.sh
138
+ echo \$? > runit.retcode
139
+ if [ ! -d /bocajail ]; then
140
+ /bin/umount /proc 2>/dev/null
141
+ #/bin/umount /dev
142
+ /bin/umount /sys 2>/dev/null
143
+ fi
144
+ EOF
145
+ chmod 755 runit.sh
146
+ chroot /bocajail "$cdir/runit.sh"
147
+ if [ -r runit.retcode ]; then
148
+ ret=$(cat runit.retcode)
149
+ else
150
+ ret=99
151
+ fi
152
+ else
153
+ echo "COMPILATION IS NOT BEING CHROOTED -- THIS IS NOT AN IDEAL SETTING"
154
+ $sf -r1 -F1000 -n0 -U$bocau -G$bocag -C. -ostdout0 -estderr0 -d$maxm -m$maxm -f20000 -t$ttime -T$ttime ./compileit.sh
155
+ ret=$?
156
+ fi
157
+ if [ -f "stdout0" ]; then
158
+ cat "stdout0"
159
+ fi
160
+ if [ -f "stderr0" ]; then
161
+ cat "stderr0"
162
+ fi
163
+ rm -rf src/
164
+ if [ "$ret" != "0" ]; then
165
+ echo "Compilation Error: $ret"
166
+ exit $ret
167
+ fi
168
+ ret=$(cat compileit.retcode)
169
+ if [ "$ret" != "0" ]; then
170
+ echo "Compilation Error: $ret"
171
+ ret=1
172
+ fi
173
+ exit $ret
@@ -0,0 +1,172 @@
1
+ #!/bin/bash
2
+ # ////////////////////////////////////////////////////////////////////////////////
3
+ # //BOCA Online Contest Administrator
4
+ # // Copyright (C) 2003-2014 by BOCA System (bocasystem@gmail.com)
5
+ # //
6
+ # // This program is free software: you can redistribute it and/or modify
7
+ # // it under the terms of the GNU General Public License as published by
8
+ # // the Free Software Foundation, either version 3 of the License, or
9
+ # // (at your option) any later version.
10
+ # //
11
+ # // This program is distributed in the hope that it will be useful,
12
+ # // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # // GNU General Public License for more details.
15
+ # // You should have received a copy of the GNU General Public License
16
+ # // along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ # ////////////////////////////////////////////////////////////////////////////////
18
+ #Last modified: 21/august/2014 by cassio@ime.usp.br
19
+ #
20
+ # parameters are:
21
+ # $1 source_file
22
+ # $2 exe_file (default run.exe)
23
+ # $3 timelimit
24
+ # $4 maximum allowed memory (in MBytes)
25
+ #
26
+ # the output of the submission should be directed to the standard output
27
+ #
28
+ # the return code show what happened (according to safeexec):
29
+ # 0 ok
30
+ # 1 compile error
31
+ # 2 runtime error
32
+ # 3 timelimit exceeded
33
+ # 4 internal error
34
+ # 5 parameter error
35
+ # 6 internal error
36
+ # 7 memory limit exceeded
37
+ # 8 security threat
38
+ # 9 runtime error
39
+ # other_codes are unknown to boca: in this case BOCA will present the
40
+ # last line of standard output to the judge
41
+
42
+ umask 0022
43
+
44
+ if [ "$1" == "" ]; then
45
+ echo "parameter problem"
46
+ exit 43
47
+ fi
48
+ if [ ! -r "$1" ]; then
49
+ echo "$1 not found or it's not readable"
50
+ exit 44
51
+ fi
52
+ name="$1"
53
+ if [ ! -r "$1" ]; then
54
+ echo "$1 not found or it's not readable"
55
+ exit 44
56
+ fi
57
+ mkdir -p src
58
+ if [ "${name##*.}" == "zip" -a "${name##*.}" == "ZIP" ]; then
59
+ unzip "$name" -d src
60
+ name="*.c"
61
+ else
62
+ cp "$name" src
63
+ fi
64
+ id -u bocajail >/dev/null 2>/dev/null
65
+ if [ $? == 0 ]; then
66
+ bocau=$(id -u bocajail)
67
+ bocag=$(id -g bocajail)
68
+ chown bocajail.nogroup .
69
+ else
70
+ bocau=$(id -u nobody)
71
+ bocag=$(id -g nobody)
72
+ chown nobody.nogroup .
73
+ fi
74
+ if [ "$bocau" == "" -o "$bocag" == "" ]; then
75
+ echo "error finding user to run script"
76
+ exit 43
77
+ fi
78
+
79
+ # this script makes use of safeexec to execute the code with less privilegies
80
+ # make sure that directories below are correct.
81
+ sf=$(which safeexec)
82
+ [ -x "$sf" ] || sf=/usr/bin/safeexec
83
+ if [ ! -x $sf ]; then
84
+ echo "$sf not found or it's not executable"
85
+ exit 46
86
+ fi
87
+ maxm=512000
88
+ if [ "$4" != "" ]; then
89
+ if [ "$4" -gt "512" ]; then
90
+ maxm=${4}000
91
+ fi
92
+ fi
93
+
94
+ # setting up the timelimit according to the problem
95
+ if [ "$3" == "" ]; then
96
+ time=5
97
+ else
98
+ time=$3
99
+ fi
100
+ let "ttime = $time + 30"
101
+
102
+ if [ "$2" == "" ]; then
103
+ exe=run.exe
104
+ else
105
+ exe=$2
106
+ fi
107
+
108
+ rm -f "$exe" compileit.retcode runit.retcode 2>/dev/null
109
+ cat <<EOF >compileit.sh
110
+ #!/bin/bash
111
+ cc=\`which g++\`
112
+ [ -x "\$cc" ] || cc=/usr/bin/g++
113
+ if [ ! -x "\$cc" ]; then
114
+ echo "\$cc not found or it's not executable"
115
+ exit 47
116
+ fi
117
+ cd src
118
+ "\$cc" {{rbxFlags}} -o "../$exe" "$name"
119
+ echo \$? > ../compileit.retcode
120
+ exit 0
121
+ EOF
122
+ chmod 755 compileit.sh
123
+
124
+ cdir=$(pwd)
125
+ echo "Current directory is $cdir" >&2
126
+ echo $cdir | grep -q "/bocajail"
127
+ if [ $? == 0 ]; then
128
+ cdir=$(echo $cdir | sed "s/.*\/bocajail//")
129
+ echo "Internal directory is $cdir"
130
+ cat <<EOF >runit.sh
131
+ #!/bin/bash
132
+ cd "$cdir"
133
+ [ -f /proc/cpuinfo ] || /bin/mount -t proc proc /proc
134
+ #/bin/mount --bind /dev /dev
135
+ [ -d /sys/kernel ] || /bin/mount -t sysfs sysfs /sys
136
+ $sf -r1 -F1000 -n0 -U$bocau -G$bocag -C. -ostdout0 -estderr0 -d$maxm -m$maxm -f20000 -t$ttime -T$ttime ./compileit.sh
137
+ echo \$? > runit.retcode
138
+ if [ ! -d /bocajail ]; then
139
+ /bin/umount /proc 2>/dev/null
140
+ #/bin/umount /dev
141
+ /bin/umount /sys 2>/dev/null
142
+ fi
143
+ EOF
144
+ chmod 755 runit.sh
145
+ chroot /bocajail "$cdir/runit.sh"
146
+ if [ -r runit.retcode ]; then
147
+ ret=$(cat runit.retcode)
148
+ else
149
+ ret=99
150
+ fi
151
+ else
152
+ echo "COMPILATION IS NOT BEING CHROOTED -- THIS IS NOT AN IDEAL SETTING"
153
+ $sf -r1 -F1000 -n0 -U$bocau -G$bocag -C. -ostdout0 -estderr0 -d$maxm -m$maxm -f20000 -t$ttime -T$ttime ./compileit.sh
154
+ ret=$?
155
+ fi
156
+ if [ -f "stdout0" ]; then
157
+ cat "stdout0"
158
+ fi
159
+ if [ -f "stderr0" ]; then
160
+ cat "stderr0"
161
+ fi
162
+ rm -rf src/
163
+ if [ "$ret" != "0" ]; then
164
+ echo "Compilation Error: $ret"
165
+ exit $ret
166
+ fi
167
+ ret=$(cat compileit.retcode)
168
+ if [ "$ret" != "0" ]; then
169
+ echo "Compilation Error: $ret"
170
+ ret=1
171
+ fi
172
+ exit $ret