File: dulwich-serve.py

package info (click to toggle)
hg-git 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,244 kB
  • sloc: python: 8,702; sh: 185; makefile: 23
file content (41 lines) | stat: -rwxr-xr-x 814 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
#
# Wrapper for dulwich.web that forks a web server in a subprocess and
# saves the PID.
#

import os
import sys

from dulwich import log_utils
from dulwich import repo
from dulwich import server
from dulwich import web

import dulwich


class DirBackend(server.Backend):
    def open_repository(self, path):
        return repo.Repo(path[1:])


gitdir = os.getcwd()
port = int(sys.argv[1])

log_utils.default_logging_config()
log_utils.getLogger().info(
    f"serving {gitdir} on port {port} using dulwich v"
    + ".".join(map(str, dulwich.__version__))
)

backend = DirBackend()
app = web.make_wsgi_chain(backend)
server = web.make_server(
    "localhost",
    port,
    app,
    handler_class=web.WSGIRequestHandlerLogger,
    server_class=web.WSGIServerLogger,
)
server.serve_forever()