__init__.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import argparse
  4. import commands.clone, commands.search, commands.show, commands.update
  5. if __name__ == '__main__':
  6. # Arguments
  7. # --------------------------------------
  8. parser = argparse.ArgumentParser()
  9. parser.add_argument( "--indexfile",
  10. type = str,
  11. default = "/var/cache/gitlist/index",
  12. help = "The name of the index to create" )
  13. parser.add_argument( "--gitreposdir",
  14. type = str,
  15. default = "/etc/gitlist/gitrepos.d"
  16. help = "The name of the directory where the " \
  17. "gitrepos files are" )
  18. # --------------------------------------
  19. subparsers = parser.add_subparsers( dest = "command",
  20. title = "commands" )
  21. # Clone
  22. sp_clone = subparsers.add_parser( "clone",
  23. help = "Clone a git repository" )
  24. commands.clone.init(sp_clone)
  25. # Help
  26. sp_help = subparsers.add_parser( "help",
  27. help = "Print this help" )
  28. # Search
  29. sp_search = subparsers.add_parser( "search",
  30. help = "Print this search" )
  31. commands.search.init(sp_search)
  32. # Show
  33. sp_show = subparsers.add_parser( "show",
  34. help = "Print this show" )
  35. commands.show.init(sp_show)
  36. # Update
  37. sp_update = subparsers.add_parser( "update",
  38. help = "Print this update" )
  39. commands.update.init(sp_update)
  40. args = parser.parse_args()
  41. # Logging
  42. # --------------------------------------
  43. logger = logging.getLogger("gitlist")
  44. log.setLevel(logging.DEBUG)
  45. # Console handler
  46. loghandler_console = logging.StreamHandler()
  47. loghandler_console.setLevel(logging.WARNING)
  48. # Adjust for verbosity
  49. if(args.verbose):
  50. loghandler_console.setLevel(logging.DEBUG)
  51. # Format for console (no need for time)
  52. logformatter_console = logging.Formatter("%(name)s:%(levelname)s: %(message)s")
  53. # And we're set!
  54. loghandler_console.setFormatter(logformatter_console)
  55. logger.addHandler(loghandler_console)
  56. # Script
  57. # --------------------------------------
  58. # Start with help
  59. if args.command in [ "help", None ]:
  60. parser.print_help()
  61. exit() # TODO add return codes?
  62. # CLONE
  63. # opt: proto, ask
  64. # - Resolve name to giturl from cache ## NOT GITURL, GITREPO FILE
  65. # - if ask: get gitrepo and ask before cloning ? ## NO ASK ALWAYS
  66. # - launch git with right params ; tries proto in order
  67. # SEARCH
  68. # opt: thourough
  69. # - grep through cache file (tags), or gitrepos file if thourough
  70. # - get corresponding gitrepos to print desc?
  71. # SHOW
  72. # - grep through cache file
  73. # - get corresponding gitrepo
  74. # - show gitrepo
  75. # UPDATE
  76. # - parse all gitrepo files one by one
  77. # - generate cache file
  78. # - cache file format is: shortname gitreponame tags...