author | Augie Fackler <augie@google.com> |
Wed, 06 Dec 2017 16:42:24 -0500 | |
changeset 35306 | 03a83ace9816 |
parent 34924 | bfcd0d227972 |
child 37119 | d4a2e0d5d042 |
permissions | -rw-r--r-- |
30506
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 os |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
11 |
import tempfile |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
12 |
|
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
13 |
from .i18n import _ |
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 . import ( |
30513
ff7df4bb75de
chgserver: make it a core module and drop extension flags
Yuya Nishihara <yuya@tcha.org>
parents:
30510
diff
changeset
|
16 |
chgserver, |
32005
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
17 |
cmdutil, |
30507
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
18 |
commandserver, |
30506
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
19 |
error, |
30509
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
20 |
hgweb, |
32530
3f0936b2cea9
server: use pycompat to get argv
Augie Fackler <raf@durin42.com>
parents:
32291
diff
changeset
|
21 |
pycompat, |
30506
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
22 |
util, |
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 |
|
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
25 |
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
|
26 |
runargs=None, appendpid=False): |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
27 |
'''Run a command as a service.''' |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
28 |
|
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
29 |
def writepid(pid): |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
30 |
if opts['pid_file']: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
31 |
if appendpid: |
32548
d770a08ee9d9
server: write out pid using bytes IO instead of str IO
Augie Fackler <raf@durin42.com>
parents:
32530
diff
changeset
|
32 |
mode = 'ab' |
30506
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
33 |
else: |
32548
d770a08ee9d9
server: write out pid using bytes IO instead of str IO
Augie Fackler <raf@durin42.com>
parents:
32530
diff
changeset
|
34 |
mode = 'wb' |
30506
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
35 |
fp = open(opts['pid_file'], mode) |
32617
e48cb1c7a902
py3: simply use b'%d\n' to format pid in server.py
Yuya Nishihara <yuya@tcha.org>
parents:
32548
diff
changeset
|
36 |
fp.write('%d\n' % pid) |
30506
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
37 |
fp.close() |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
38 |
|
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
39 |
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
|
40 |
# Signal child process startup with file removal |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
41 |
lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-') |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
42 |
os.close(lockfd) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
43 |
try: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
44 |
if not runargs: |
32530
3f0936b2cea9
server: use pycompat to get argv
Augie Fackler <raf@durin42.com>
parents:
32291
diff
changeset
|
45 |
runargs = util.hgcmd() + pycompat.sysargv[1:] |
30506
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
46 |
runargs.append('--daemon-postexec=unlink:%s' % lockpath) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
47 |
# 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
|
48 |
# changed directory. |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
49 |
for i in xrange(1, len(runargs)): |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
50 |
if runargs[i].startswith('--cwd='): |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
51 |
del runargs[i] |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
52 |
break |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
53 |
elif runargs[i].startswith('--cwd'): |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
54 |
del runargs[i:i + 2] |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
55 |
break |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
56 |
def condfn(): |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
57 |
return not os.path.exists(lockpath) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
58 |
pid = util.rundetached(runargs, condfn) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
59 |
if pid < 0: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
60 |
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
|
61 |
writepid(pid) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
62 |
finally: |
31548 | 63 |
util.tryunlink(lockpath) |
30506
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
64 |
if parentfn: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
65 |
return parentfn(pid) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
66 |
else: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
67 |
return |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
68 |
|
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
69 |
if initfn: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
70 |
initfn() |
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 not opts['daemon']: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
73 |
writepid(util.getpid()) |
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 opts['daemon_postexec']: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
76 |
try: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
77 |
os.setsid() |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
78 |
except AttributeError: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
79 |
pass |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
80 |
for inst in opts['daemon_postexec']: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
81 |
if inst.startswith('unlink:'): |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
82 |
lockpath = inst[7:] |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
83 |
os.unlink(lockpath) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
84 |
elif inst.startswith('chdir:'): |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
85 |
os.chdir(inst[6:]) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
86 |
elif inst != 'none': |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
87 |
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
|
88 |
% inst) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
89 |
util.hidewindow() |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
90 |
util.stdout.flush() |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
91 |
util.stderr.flush() |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
92 |
|
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
93 |
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
|
94 |
logfilefd = nullfd |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
95 |
if logfile: |
34924
bfcd0d227972
server: drop executable bit from daemon log file
Yuya Nishihara <yuya@tcha.org>
parents:
32617
diff
changeset
|
96 |
logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND, |
bfcd0d227972
server: drop executable bit from daemon log file
Yuya Nishihara <yuya@tcha.org>
parents:
32617
diff
changeset
|
97 |
0o666) |
30506
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
98 |
os.dup2(nullfd, 0) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
99 |
os.dup2(logfilefd, 1) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
100 |
os.dup2(logfilefd, 2) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
101 |
if nullfd not in (0, 1, 2): |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
102 |
os.close(nullfd) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
103 |
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
|
104 |
os.close(logfilefd) |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
105 |
|
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
106 |
if runfn: |
d9d8d78e6bc9
server: move cmdutil.service() to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
107 |
return runfn() |
30507
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
108 |
|
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
109 |
_cmdservicemap = { |
30513
ff7df4bb75de
chgserver: make it a core module and drop extension flags
Yuya Nishihara <yuya@tcha.org>
parents:
30510
diff
changeset
|
110 |
'chgunix': chgserver.chgunixservice, |
30507
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
111 |
'pipe': commandserver.pipeservice, |
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
112 |
'unix': commandserver.unixforkingservice, |
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
113 |
} |
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
114 |
|
30510
a0878bc87379
server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30509
diff
changeset
|
115 |
def _createcmdservice(ui, repo, opts): |
30507
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
116 |
mode = opts['cmdserver'] |
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
117 |
try: |
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
118 |
return _cmdservicemap[mode](ui, repo, opts) |
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
119 |
except KeyError: |
dd539e2d89aa
server: move service table and factory from commandserver
Yuya Nishihara <yuya@tcha.org>
parents:
30506
diff
changeset
|
120 |
raise error.Abort(_('unknown mode %s') % mode) |
30509
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
121 |
|
30510
a0878bc87379
server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30509
diff
changeset
|
122 |
def _createhgwebservice(ui, repo, opts): |
30509
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
123 |
# 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:
30507
diff
changeset
|
124 |
if opts.get('port'): |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
125 |
opts['port'] = util.getport(opts.get('port')) |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
126 |
|
32291
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32005
diff
changeset
|
127 |
alluis = {ui} |
30509
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
128 |
if repo: |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
129 |
baseui = repo.baseui |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
130 |
alluis.update([repo.baseui, repo.ui]) |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
131 |
else: |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
132 |
baseui = ui |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
133 |
webconf = opts.get('web_conf') or opts.get('webdir_conf') |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
134 |
if webconf: |
32005
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
135 |
if opts.get('subrepos'): |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
136 |
raise error.Abort(_('--web-conf cannot be used with --subrepos')) |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
137 |
|
30509
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
138 |
# 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:
30507
diff
changeset
|
139 |
# hgwebdir to reload webconf cleanly |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
140 |
servui = ui.copy() |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
141 |
servui.readconfig(webconf, sections=['web']) |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
142 |
alluis.add(servui) |
32005
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
143 |
elif opts.get('subrepos'): |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
144 |
servui = ui |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
145 |
|
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
146 |
# If repo is None, hgweb.createapp() already raises a proper abort |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
147 |
# message as long as webconf is None. |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
148 |
if repo: |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
149 |
webconf = dict() |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31548
diff
changeset
|
150 |
cmdutil.addwebdirpath(repo, "", webconf) |
30509
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
151 |
else: |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
152 |
servui = ui |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
153 |
|
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
154 |
optlist = ("name templates style address port prefix ipv6" |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
155 |
" accesslog errorlog certificate encoding") |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
156 |
for o in optlist.split(): |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
157 |
val = opts.get(o, '') |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
158 |
if val in (None, ''): # should check against default options instead |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
159 |
continue |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
160 |
for u in alluis: |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
161 |
u.setconfig("web", o, val, 'serve') |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
162 |
|
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
163 |
app = hgweb.createapp(baseui, repo, webconf) |
add7bcad1d9c
server: move service factory from hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30507
diff
changeset
|
164 |
return hgweb.httpservice(servui, app, opts) |
30510
a0878bc87379
server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30509
diff
changeset
|
165 |
|
a0878bc87379
server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30509
diff
changeset
|
166 |
def createservice(ui, repo, opts): |
a0878bc87379
server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30509
diff
changeset
|
167 |
if opts["cmdserver"]: |
a0878bc87379
server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30509
diff
changeset
|
168 |
return _createcmdservice(ui, repo, opts) |
a0878bc87379
server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30509
diff
changeset
|
169 |
else: |
a0878bc87379
server: add public function to select either cmdserver or hgweb
Yuya Nishihara <yuya@tcha.org>
parents:
30509
diff
changeset
|
170 |
return _createhgwebservice(ui, repo, opts) |