|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Contest Management System - http://cms-dev.github.io/ |
| 4 | +# Copyright © 2019 Andrey Vihrov <andrey.vihrov@gmail.com> |
| 5 | + |
| 6 | +# This program is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Affero General Public License as |
| 8 | +# published by the Free Software Foundation, either version 3 of the |
| 9 | +# License, or (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 Affero General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Affero General Public License |
| 17 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +"""A class to update a dump created by CMS. |
| 20 | +
|
| 21 | +Used by DumpImporter and DumpUpdater. |
| 22 | +
|
| 23 | +This updater adds file name extensions to relevant executables. |
| 24 | +
|
| 25 | +Note: |
| 26 | + - File descriptions are not updated. |
| 27 | + - Out-of-tree languages should be added to LANG_EXT manually. |
| 28 | + - Custom use of USE_JAR = False should be reflected in this updater. |
| 29 | +
|
| 30 | +""" |
| 31 | + |
| 32 | +USE_JAR = True |
| 33 | + |
| 34 | +LANG_EXT = { |
| 35 | + "C# / Mono": ".exe", |
| 36 | + "Java / JDK": ".jar" if USE_JAR else ".zip", |
| 37 | + "PHP": ".php", |
| 38 | + "Python 2 / CPython": ".zip", |
| 39 | + "Python 3 / CPython": ".pyz", |
| 40 | +} |
| 41 | + |
| 42 | +class Updater: |
| 43 | + |
| 44 | + def __init__(self, data): |
| 45 | + assert data["_version"] == 43 |
| 46 | + self.objs = data |
| 47 | + |
| 48 | + def run(self): |
| 49 | + for k, v in self.objs.items(): |
| 50 | + if k.startswith("_"): |
| 51 | + continue |
| 52 | + if v["_class"] == "Executable": |
| 53 | + s = self.objs[v["submission"]] |
| 54 | + l = s["language"] |
| 55 | + sr = self.objs[v["submission_result"]] |
| 56 | + |
| 57 | + del sr["executables"][v["filename"]] |
| 58 | + v["filename"] += LANG_EXT.get(l, "") |
| 59 | + sr["executables"][v["filename"]] = k |
| 60 | + |
| 61 | + return self.objs |
0 commit comments