update_43.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python3
  2. # Contest Management System - http://cms-dev.github.io/
  3. # Copyright © 2020 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. The Java 1.4 / gcj programming language is removed.
  19. """
  20. import logging
  21. logger = logging.getLogger(__name__)
  22. JAVA_GCJ = "Java 1.4 / gcj"
  23. JAVA_JDK = "Java / JDK"
  24. class Updater:
  25. def __init__(self, data):
  26. assert data["_version"] == 42
  27. self.objs = data
  28. def run(self):
  29. objs_to_remove = []
  30. for k, v in self.objs.items():
  31. if k.startswith("_"):
  32. continue
  33. if v["_class"] == "Contest":
  34. l = v["languages"]
  35. if JAVA_GCJ in l:
  36. l.remove(JAVA_GCJ)
  37. if JAVA_JDK not in l:
  38. l.append(JAVA_JDK)
  39. elif v["_class"] in ["Submission", "UserTest"]:
  40. if v["language"] == JAVA_GCJ:
  41. logger.warning("%s %s uses %s, updating to %s."
  42. % (v["_class"], k, v["language"], JAVA_JDK))
  43. v["language"] = JAVA_JDK
  44. for r in v["results"]:
  45. objs_to_remove.extend(
  46. self.objs[r]["executables"].values())
  47. self.objs[r]["executables"].clear()
  48. for obj in objs_to_remove:
  49. del self.objs[obj]
  50. return self.objs