annotate mercurial/server.py @ 30519:a0878bc87379

server: add public function to select either cmdserver or hgweb
author Yuya Nishihara <yuya@tcha.org>
date Sat, 15 Oct 2016 14:19:16 +0900
parents add7bcad1d9c
children ff7df4bb75de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30515
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
1 # server.py - utility and factory of server
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
2 #
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
4 #
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
7
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
8 from __future__ import absolute_import
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
9
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
10 import errno
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
11 import os
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
12 import sys
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
13 import tempfile
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
14
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
15 from .i18n import _
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
16
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
17 from . import (
30516
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
18 commandserver,
30515
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
19 error,
30518
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
20 hgweb,
30515
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
21 util,
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
22 )
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
23
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
24 def runservice(opts, parentfn=None, initfn=None, runfn=None, logfile=None,
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
25 runargs=None, appendpid=False):
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
26 '''Run a command as a service.'''
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
27
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
28 def writepid(pid):
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
29 if opts['pid_file']:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
30 if appendpid:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
31 mode = 'a'
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
32 else:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
33 mode = 'w'
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
34 fp = open(opts['pid_file'], mode)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
35 fp.write(str(pid) + '\n')
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
36 fp.close()
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
37
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
38 if opts['daemon'] and not opts['daemon_postexec']:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
39 # Signal child process startup with file removal
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
40 lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-')
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
41 os.close(lockfd)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
42 try:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
43 if not runargs:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
44 runargs = util.hgcmd() + sys.argv[1:]
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
45 runargs.append('--daemon-postexec=unlink:%s' % lockpath)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
46 # Don't pass --cwd to the child process, because we've already
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
47 # changed directory.
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
48 for i in xrange(1, len(runargs)):
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
49 if runargs[i].startswith('--cwd='):
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
50 del runargs[i]
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
51 break
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
52 elif runargs[i].startswith('--cwd'):
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
53 del runargs[i:i + 2]
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
54 break
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
55 def condfn():
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
56 return not os.path.exists(lockpath)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
57 pid = util.rundetached(runargs, condfn)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
58 if pid < 0:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
59 raise error.Abort(_('child process failed to start'))
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
60 writepid(pid)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
61 finally:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
62 try:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
63 os.unlink(lockpath)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
64 except OSError as e:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
65 if e.errno != errno.ENOENT:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
66 raise
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
67 if parentfn:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
68 return parentfn(pid)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
69 else:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
70 return
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
71
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
72 if initfn:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
73 initfn()
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
74
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
75 if not opts['daemon']:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
76 writepid(util.getpid())
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
77
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
78 if opts['daemon_postexec']:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
79 try:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
80 os.setsid()
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
81 except AttributeError:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
82 pass
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
83 for inst in opts['daemon_postexec']:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
84 if inst.startswith('unlink:'):
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
85 lockpath = inst[7:]
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
86 os.unlink(lockpath)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
87 elif inst.startswith('chdir:'):
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
88 os.chdir(inst[6:])
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
89 elif inst != 'none':
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
90 raise error.Abort(_('invalid value for --daemon-postexec: %s')
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
91 % inst)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
92 util.hidewindow()
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
93 util.stdout.flush()
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
94 util.stderr.flush()
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
95
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
96 nullfd = os.open(os.devnull, os.O_RDWR)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
97 logfilefd = nullfd
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
98 if logfile:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
99 logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
100 os.dup2(nullfd, 0)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
101 os.dup2(logfilefd, 1)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
102 os.dup2(logfilefd, 2)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
103 if nullfd not in (0, 1, 2):
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
104 os.close(nullfd)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
105 if logfile and logfilefd not in (0, 1, 2):
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
106 os.close(logfilefd)
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
107
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
108 if runfn:
d9d8d78e6bc9 server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
109 return runfn()
30516
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
110
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
111 _cmdservicemap = {
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
112 'pipe': commandserver.pipeservice,
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
113 'unix': commandserver.unixforkingservice,
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
114 }
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
115
30519
a0878bc87379 server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30518
diff changeset
116 def _createcmdservice(ui, repo, opts):
30516
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
117 mode = opts['cmdserver']
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
118 try:
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
119 return _cmdservicemap[mode](ui, repo, opts)
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
120 except KeyError:
dd539e2d89aa server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents: 30515
diff changeset
121 raise error.Abort(_('unknown mode %s') % mode)
30518
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
122
30519
a0878bc87379 server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30518
diff changeset
123 def _createhgwebservice(ui, repo, opts):
30518
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
124 # this way we can check if something was given in the command-line
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
125 if opts.get('port'):
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
126 opts['port'] = util.getport(opts.get('port'))
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
127
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
128 alluis = set([ui])
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
129 if repo:
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
130 baseui = repo.baseui
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
131 alluis.update([repo.baseui, repo.ui])
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
132 else:
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
133 baseui = ui
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
134 webconf = opts.get('web_conf') or opts.get('webdir_conf')
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
135 if webconf:
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
136 # load server settings (e.g. web.port) to "copied" ui, which allows
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
137 # hgwebdir to reload webconf cleanly
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
138 servui = ui.copy()
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
139 servui.readconfig(webconf, sections=['web'])
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
140 alluis.add(servui)
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
141 else:
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
142 servui = ui
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
143
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
144 optlist = ("name templates style address port prefix ipv6"
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
145 " accesslog errorlog certificate encoding")
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
146 for o in optlist.split():
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
147 val = opts.get(o, '')
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
148 if val in (None, ''): # should check against default options instead
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
149 continue
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
150 for u in alluis:
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
151 u.setconfig("web", o, val, 'serve')
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
152
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
153 app = hgweb.createapp(baseui, repo, webconf)
add7bcad1d9c server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30516
diff changeset
154 return hgweb.httpservice(servui, app, opts)
30519
a0878bc87379 server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30518
diff changeset
155
a0878bc87379 server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30518
diff changeset
156 def createservice(ui, repo, opts):
a0878bc87379 server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30518
diff changeset
157 if opts["cmdserver"]:
a0878bc87379 server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30518
diff changeset
158 return _createcmdservice(ui, repo, opts)
a0878bc87379 server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30518
diff changeset
159 else:
a0878bc87379 server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents: 30518
diff changeset
160 return _createhgwebservice(ui, repo, opts)