A console script that allows you to easily update multiple git repositories at once
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

58 Zeilen
1.6 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2011-2018 Ben Kurtovic <ben.kurtovic@gmail.com>
  4. # Released under the terms of the MIT License. See LICENSE for details.
  5. import os
  6. from configparser import ConfigParser, NoSectionError
  7. __all__ = ["run_migrations"]
  8. def _get_old_path():
  9. """Return the old default path to the configuration file."""
  10. xdg_cfg = os.environ.get("XDG_CONFIG_HOME") or os.path.join("~", ".config")
  11. return os.path.join(os.path.expanduser(xdg_cfg), "gitup", "config.ini")
  12. def _migrate_old_path():
  13. """Migrate the old config location (~/.gitup) to the new one."""
  14. old_path = os.path.expanduser(os.path.join("~", ".gitup"))
  15. if not os.path.exists(old_path):
  16. return
  17. temp_path = _get_old_path()
  18. temp_dir = os.path.dirname(temp_path)
  19. if not os.path.exists(temp_dir):
  20. os.makedirs(temp_dir)
  21. os.rename(old_path, temp_path)
  22. def _migrate_old_format():
  23. """Migrate the old config file format (.INI) to our custom list format."""
  24. old_path = _get_old_path()
  25. if not os.path.exists(old_path):
  26. return
  27. config = ConfigParser(delimiters="=")
  28. config.optionxform = lambda opt: opt
  29. config.read(old_path)
  30. try:
  31. bookmarks = [path.encode("utf8") for path, _ in config.items("bookmarks")]
  32. except NoSectionError:
  33. bookmarks = []
  34. new_path = os.path.join(os.path.split(old_path)[0], "bookmarks")
  35. os.rename(old_path, new_path)
  36. with open(new_path, "wb") as handle:
  37. handle.write(b"\n".join(bookmarks))
  38. def run_migrations():
  39. """Run any necessary migrations to ensure the config file is up-to-date."""
  40. _migrate_old_path()
  41. _migrate_old_format()