sapling/eden/hg-server/tests/dumbhttp.py
Durham Goode 98d9269874 server: copy hg to a new hg-server directory
Summary:
Create a fork of the Mercurial code that we can use to build server
rpms. The hg servers will continue to exist for a few more months while we move
the darkstorm and ediscovery use cases off them. In the mean time, we want to
start making breaking changes to the client, so let's create a stable copy of
the hg code to produce rpms for the hg servers.

The fork is based off c7770c78d, the latest hg release.

This copies the files as is, then adds some minor tweaks to get it to build:
- Disables some lint checks that appear to be bypassed by path
- sed replace eden/scm with eden/hg-server
- Removed a dependency on scm/telemetry from the edenfs-client tests since
  scm/telemetry pulls in the original eden/scm/lib/configparser which conflicts
  with the hg-server conflict parser.

allow-large-files

Reviewed By: quark-zju

Differential Revision: D27632557

fbshipit-source-id: b2f442f4ec000ea08e4d62de068750832198e1f4
2021-04-09 10:09:06 -07:00

103 lines
2.5 KiB
Python
Executable File

#!/usr/bin/env python
from __future__ import absolute_import
import optparse
import os
import signal
import socket
import sys
from edenscm.mercurial import server, util
"""
Small and dumb HTTP server for use in tests.
"""
httpserver = util.httpserver
OptionParser = optparse.OptionParser
if os.environ.get("HGIPV6", "0") == "1":
class simplehttpserver(httpserver.httpserver):
address_family = socket.AF_INET6
else:
simplehttpserver = httpserver.httpserver
class _httprequesthandler(httpserver.simplehttprequesthandler):
def log_message(self, format, *args):
httpserver.simplehttprequesthandler.log_message(self, format, *args)
sys.stderr.flush()
class simplehttpservice(object):
def __init__(self, host, port):
self.address = (host, port)
def init(self):
self.httpd = simplehttpserver(self.address, _httprequesthandler)
def run(self):
self.httpd.serve_forever()
if __name__ == "__main__":
parser = OptionParser()
parser.add_option(
"-p",
"--port",
dest="port",
type="int",
default=8000,
help="TCP port to listen on",
metavar="PORT",
)
parser.add_option(
"-H",
"--host",
dest="host",
default="localhost",
help="hostname or IP to listen on",
metavar="HOST",
)
parser.add_option("--logfile", help="file name of access/error log")
parser.add_option(
"--pid", dest="pid", help="file name where the PID of the server is stored"
)
parser.add_option(
"-f",
"--foreground",
dest="foreground",
action="store_true",
help="do not start the HTTP server in the background",
)
parser.add_option("--daemon-postexec", action="append")
(options, args) = parser.parse_args()
signal.signal(signal.SIGTERM, lambda x, y: sys.exit(0))
if options.foreground and options.logfile:
parser.error("options --logfile and --foreground are mutually " "exclusive")
if options.foreground and options.pid:
parser.error("options --pid and --foreground are mutually exclusive")
opts = {
"pid_file": options.pid,
"daemon": not options.foreground,
"daemon_postexec": options.daemon_postexec,
}
service = simplehttpservice(options.host, options.port)
server.runservice(
opts,
initfn=service.init,
runfn=service.run,
logfile=options.logfile,
runargs=["hg", "debugpython", "--", __file__] + sys.argv[1:],
)