dul-web 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/python
  2. # dul-web - HTTP-based git server
  3. # Copyright (C) 2010 Google, Inc. <dborowitz@google.com>
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; version 2
  8. # or (at your option) a later version of the License.
  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 General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. import os
  20. import sys
  21. from dulwich.log_utils import default_logging_config
  22. from dulwich.repo import Repo
  23. from dulwich.server import DictBackend
  24. from dulwich.web import (
  25. logger,
  26. HTTPGitApplication,
  27. HTTPGitRequestHandler,
  28. )
  29. from wsgiref.simple_server import (
  30. make_server,
  31. )
  32. # TODO: allow serving on other addresses/ports via command-line flag
  33. LISTEN_ADDR=''
  34. PORT = 8000
  35. if __name__ == "__main__":
  36. if len(sys.argv) > 1:
  37. gitdir = sys.argv[1]
  38. else:
  39. gitdir = os.getcwd()
  40. default_logging_config()
  41. backend = DictBackend({"/": Repo(gitdir)})
  42. app = HTTPGitApplication(backend)
  43. server = make_server(LISTEN_ADDR, PORT, app,
  44. handler_class=HTTPGitRequestHandler)
  45. logger.info('Listening for HTTP connections on %s:%d', LISTEN_ADDR, PORT)
  46. server.serve_forever()