dul-web 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. )
  28. from wsgiref.simple_server import (
  29. WSGIRequestHandler,
  30. make_server,
  31. )
  32. class HTTPGitRequestHandler(WSGIRequestHandler):
  33. """Handler that uses dulwich's logger for logging exceptions."""
  34. def log_exception(self, exc_info):
  35. logger.exception('Exception happened during processing of request',
  36. exc_info=exc_info)
  37. def log_message(self, format, *args):
  38. logger.info(format, *args)
  39. def log_error(self, *args):
  40. logger.error(*args)
  41. # TODO: allow serving on other addresses/ports via command-line flag
  42. LISTEN_ADDR=''
  43. PORT = 8000
  44. if __name__ == "__main__":
  45. if len(sys.argv) > 1:
  46. gitdir = sys.argv[1]
  47. else:
  48. gitdir = os.getcwd()
  49. default_logging_config()
  50. backend = DictBackend({"/": Repo(gitdir)})
  51. app = HTTPGitApplication(backend)
  52. server = make_server(LISTEN_ADDR, PORT, app,
  53. handler_class=HTTPGitRequestHandler)
  54. logger.info('Listening for HTTP connections on %s:%d', LISTEN_ADDR, PORT)
  55. server.serve_forever()