annotate tests/dumbhttp.py @ 26730:a1e43e85d294

merge-tools: allow marking a mergetool as completely disabled Very often in my life I'm finding that the only configured merge tool present on the system is vimdiff[0], and it's currently impossible (as far as I can tell) short of specifying `ui.merge = `[1] to actually *disable* a merge tool. This allows vimdiff-haters to put: [merge-tools] vimdiff.disable = yes in their ~/.hgrc and never see vimdiff again. I'm stopping short of putting this as a commented out entry in the sample new user hgrc (seen when a user runs `hg config --edit` with no ~/.hgrc) for now, but I might come back and do that later. 0: vimdiff is at an awkward intersection: it's usually installed by the vim package which is often installed as a vi substitute, so it's mere presence doesn't imply me wanting it, unlike (say) kdiff3. 1: There's a related problem I ran into today where specifying `ui.merge = :merge` failed because :merge isn't a command, which I think is a regression. I'll try and figure that out and at least file a bug.
author Augie Fackler <augie@google.com>
date Wed, 14 Oct 2015 12:57:33 -0400
parents 6eab50a34fed
children 0bb8c405a7c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22959
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
1 #!/usr/bin/env python
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
2
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
3 """
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
4 Small and dumb HTTP server for use in tests.
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
5 """
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
6
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
7 from optparse import OptionParser
23136
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
8 import BaseHTTPServer, SimpleHTTPServer, signal, sys
22959
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
9
23136
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
10 from mercurial import cmdutil
22959
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
11
23136
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
12 class simplehttpservice(object):
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
13 def __init__(self, host, port):
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
14 self.address = (host, port)
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
15 def init(self):
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
16 self.httpd = BaseHTTPServer.HTTPServer(
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
17 self.address, SimpleHTTPServer.SimpleHTTPRequestHandler)
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
18 def run(self):
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
19 self.httpd.serve_forever()
22959
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
20
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
21 if __name__ == '__main__':
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
22 parser = OptionParser()
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
23 parser.add_option('-p', '--port', dest='port', type='int', default=8000,
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
24 help='TCP port to listen on', metavar='PORT')
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
25 parser.add_option('-H', '--host', dest='host', default='localhost',
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
26 help='hostname or IP to listen on', metavar='HOST')
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
27 parser.add_option('--pid', dest='pid',
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
28 help='file name where the PID of the server is stored')
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
29 parser.add_option('-f', '--foreground', dest='foreground',
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
30 action='store_true',
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
31 help='do not start the HTTP server in the background')
23136
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
32 parser.add_option('--daemon-pipefds')
22959
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
33
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
34 (options, args) = parser.parse_args()
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
35
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
36 signal.signal(signal.SIGTERM, lambda x, y: sys.exit(0))
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
37
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
38 if options.foreground and options.pid:
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
39 parser.error("options --pid and --foreground are mutually exclusive")
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
40
23136
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
41 opts = {'pid_file': options.pid,
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
42 'daemon': not options.foreground,
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
43 'daemon_pipefds': options.daemon_pipefds}
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
44 service = simplehttpservice(options.host, options.port)
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
45 cmdutil.service(opts, initfn=service.init, runfn=service.run,
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
46 runargs=[sys.executable, __file__] + sys.argv[1:])