A console script that allows you to easily update multiple git repositories at once
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

75 строки
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2011-2014 Ben Kurtovic <ben.kurtovic@gmail.com>
  4. # See the LICENSE file for details.
  5. from __future__ import print_function
  6. import argparse
  7. from . import __version__, __email__
  8. from .config import (get_bookmarks, add_bookmarks, delete_bookmarks,
  9. list_bookmarks)
  10. from .output import out, bold
  11. from .update import update_bookmarks, update_directories
  12. def main():
  13. """Parse arguments and then call the appropriate function(s)."""
  14. parser = argparse.ArgumentParser(
  15. description="""Easily pull to multiple git repositories at once.""",
  16. epilog="""
  17. Both relative and absolute paths are accepted by all arguments.
  18. Questions? Comments? Email the author at {0}.""".format(__email__),
  19. add_help=False)
  20. group_u = parser.add_argument_group("updating repositories")
  21. group_b = parser.add_argument_group("bookmarking")
  22. group_m = parser.add_argument_group("miscellaneous")
  23. group_u.add_argument(
  24. 'directories_to_update', nargs="*", metavar="path",
  25. help="""update all repositories in this directory (or the directory
  26. itself, if it is a repo)""")
  27. group_u.add_argument(
  28. '-u', '--update', action="store_true", help="""update all bookmarks
  29. (default behavior when called without arguments)""")
  30. group_b.add_argument(
  31. '-a', '--add', dest="bookmarks_to_add", nargs="+", metavar="path",
  32. help="add directory(s) as bookmarks")
  33. group_b.add_argument(
  34. '-d', '--delete', dest="bookmarks_to_del", nargs="+", metavar="path",
  35. help="delete bookmark(s) (leaves actual directories alone)")
  36. group_b.add_argument(
  37. '-l', '--list', dest="list_bookmarks", action="store_true",
  38. help="list current bookmarks")
  39. group_m.add_argument(
  40. '-h', '--help', action="help", help="show this help message and exit")
  41. group_m.add_argument(
  42. '-v', '--version', action="version",
  43. version="gitup version " + __version__)
  44. args = parser.parse_args()
  45. print(bold("gitup") + ": the git-repo-updater")
  46. if args.bookmarks_to_add:
  47. add_bookmarks(args.bookmarks_to_add)
  48. if args.bookmarks_to_del:
  49. delete_bookmarks(args.bookmarks_to_del)
  50. if args.list_bookmarks:
  51. list_bookmarks()
  52. if args.directories_to_update:
  53. update_directories(args.directories_to_update)
  54. if args.update:
  55. update_bookmarks(get_bookmarks())
  56. # If they did not tell us to do anything, automatically update bookmarks:
  57. if not any(vars(args).values()):
  58. update_bookmarks(get_bookmarks())
  59. def run():
  60. """Thin wrapper for main() that catches KeyboardInterrupts."""
  61. try:
  62. main()
  63. except KeyboardInterrupt:
  64. out(0, "Stopped by user.")