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

11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 colorama import init as color_init, Style
  8. from . import __version__, __email__
  9. from .config import (get_bookmarks, add_bookmarks, delete_bookmarks,
  10. list_bookmarks)
  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. color_init(autoreset=True)
  45. args = parser.parse_args()
  46. print(Style.BRIGHT + "gitup" + Style.RESET_ALL + ": the git-repo-updater")
  47. print()
  48. if args.bookmarks_to_add:
  49. add_bookmarks(args.bookmarks_to_add)
  50. if args.bookmarks_to_del:
  51. delete_bookmarks(args.bookmarks_to_del)
  52. if args.list_bookmarks:
  53. list_bookmarks()
  54. if args.directories_to_update:
  55. update_directories(args.directories_to_update)
  56. if args.update:
  57. update_bookmarks(get_bookmarks())
  58. # If they did not tell us to do anything, automatically update bookmarks:
  59. if not any(vars(args).values()):
  60. update_bookmarks(get_bookmarks())
  61. def run():
  62. """Thin wrapper for main() that catches KeyboardInterrupts."""
  63. try:
  64. main()
  65. except KeyboardInterrupt:
  66. print("Stopped by user.")