update_25.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env python3
  2. # Contest Management System - http://cms-dev.github.io/
  3. # Copyright © 2017 Stefano Maggiolo <s.maggiolo@gmail.com>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. """A class to update a dump created by CMS.
  18. Used by DumpImporter and DumpUpdater.
  19. This updater changes the programming language code after the change to
  20. language plugins (for example, from
  21. """
  22. import logging
  23. logger = logging.getLogger(__name__)
  24. LANGUAGE_MAP = {
  25. "c": "C11 / gcc",
  26. "cpp": "C++11 / g++",
  27. "pas": "Pascal / fpc",
  28. "py": "Python 2 / CPython",
  29. "php": "PHP",
  30. "java": "Java 1.4 / gcj",
  31. "hs": "Haskell / ghc",
  32. }
  33. class Updater:
  34. def __init__(self, data):
  35. assert data["_version"] == 24
  36. self.objs = data
  37. self._warned_lang = set()
  38. def run(self):
  39. for k, v in self.objs.items():
  40. if k.startswith("_"):
  41. continue
  42. if v["_class"] == "Contest":
  43. v["languages"] = [self._map_language(l)
  44. for l in v["languages"]]
  45. if v["_class"] == "Submission" or v["_class"] == "UserTest":
  46. v["language"] = self._map_language(v["language"])
  47. return self.objs
  48. def _map_language(self, l):
  49. if l in LANGUAGE_MAP:
  50. return LANGUAGE_MAP[l]
  51. else:
  52. if l not in self._warned_lang:
  53. logger.warning(
  54. "Unrecognized language `%s', "
  55. "copying without modifying.", l)
  56. self._warned_lang.add(l)
  57. return l