123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #!/usr/bin/python
- # dul-web - HTTP-based git server
- # Copyright (C) 2010 Google, Inc. <dborowitz@google.com>
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; version 2
- # or (at your option) a later version of the License.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- # MA 02110-1301, USA.
- import os
- import sys
- from dulwich.log_utils import default_logging_config
- from dulwich.repo import Repo
- from dulwich.server import DictBackend
- from dulwich.web import (
- logger,
- HTTPGitApplication,
- )
- from wsgiref.simple_server import (
- WSGIRequestHandler,
- make_server,
- )
- class HTTPGitRequestHandler(WSGIRequestHandler):
- """Handler that uses dulwich's logger for logging exceptions."""
- def log_exception(self, exc_info):
- logger.exception('Exception happened during processing of request',
- exc_info=exc_info)
- def log_message(self, format, *args):
- logger.info(format, *args)
- def log_error(self, *args):
- logger.error(*args)
- # TODO: allow serving on other addresses/ports via command-line flag
- LISTEN_ADDR=''
- PORT = 8000
- if __name__ == "__main__":
- if len(sys.argv) > 1:
- gitdir = sys.argv[1]
- else:
- gitdir = os.getcwd()
- default_logging_config()
- backend = DictBackend({"/": Repo(gitdir)})
- app = HTTPGitApplication(backend)
- server = make_server(LISTEN_ADDR, PORT, app,
- handler_class=HTTPGitRequestHandler)
- logger.info('Listening for HTTP connections on %s:%d', LISTEN_ADDR, PORT)
- server.serve_forever()
|