update_44.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python3
  2. # Contest Management System - http://cms-dev.github.io/
  3. # Copyright © 2019 Andrey Vihrov <andrey.vihrov@gmail.com>
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. """A class to update a dump created by CMS.
  17. Used by DumpImporter and DumpUpdater.
  18. This updater adds file name extensions to relevant executables.
  19. Note:
  20. - File descriptions are not updated.
  21. - Out-of-tree languages should be added to LANG_EXT manually.
  22. - Custom use of USE_JAR = False should be reflected in this updater.
  23. """
  24. USE_JAR = True
  25. LANG_EXT = {
  26. "C# / Mono": ".exe",
  27. "Java / JDK": ".jar" if USE_JAR else ".zip",
  28. "PHP": ".php",
  29. "Python 2 / CPython": ".zip",
  30. "Python 3 / CPython": ".pyz",
  31. }
  32. class Updater:
  33. def __init__(self, data):
  34. assert data["_version"] == 43
  35. self.objs = data
  36. def run(self):
  37. for k, v in self.objs.items():
  38. if k.startswith("_"):
  39. continue
  40. if v["_class"] == "Executable":
  41. s = self.objs[v["submission"]]
  42. l = s["language"]
  43. sr = self.objs[v["submission_result"]]
  44. del sr["executables"][v["filename"]]
  45. v["filename"] += LANG_EXT.get(l, "")
  46. sr["executables"][v["filename"]] = k
  47. return self.objs