Show More
@@ -27,7 +27,7 b' You can discover Zeroconf-enabled reposi' | |||
|
27 | 27 | import socket, time, os |
|
28 | 28 | |
|
29 | 29 | import Zeroconf |
|
30 | from mercurial import ui, hg, encoding | |
|
30 | from mercurial import ui, hg, encoding, util | |
|
31 | 31 | from mercurial import extensions |
|
32 | 32 | from mercurial.hgweb import hgweb_mod |
|
33 | 33 | from mercurial.hgweb import hgwebdir_mod |
@@ -107,7 +107,7 b' class hgwebzc(hgweb_mod.hgweb):' | |||
|
107 | 107 | path = self.repo.ui.config("web", "prefix", "").strip('/') |
|
108 | 108 | desc = self.repo.ui.config("web", "description", name) |
|
109 | 109 | publish(name, desc, path, |
|
110 |
|
|
|
110 | util.getport(self.repo.ui.config("web", "port", 8000))) | |
|
111 | 111 | |
|
112 | 112 | class hgwebdirzc(hgwebdir_mod.hgwebdir): |
|
113 | 113 | def __init__(self, conf, baseui=None): |
@@ -119,7 +119,7 b' class hgwebdirzc(hgwebdir_mod.hgwebdir):' | |||
|
119 | 119 | name = os.path.basename(repo) |
|
120 | 120 | path = (prefix + repo).strip('/') |
|
121 | 121 | desc = u.config('web', 'description', name) |
|
122 |
publish(name, desc, path, |
|
|
122 | publish(name, desc, path, util.getport(u.config("web", "port", 8000))) | |
|
123 | 123 | |
|
124 | 124 | # listen |
|
125 | 125 |
@@ -3332,7 +3332,7 b' def serve(ui, repo, **opts):' | |||
|
3332 | 3332 | |
|
3333 | 3333 | # this way we can check if something was given in the command-line |
|
3334 | 3334 | if opts.get('port'): |
|
3335 |
opts['port'] = |
|
|
3335 | opts['port'] = util.getport(opts.get('port')) | |
|
3336 | 3336 | |
|
3337 | 3337 | baseui = repo and repo.baseui or ui |
|
3338 | 3338 | optlist = ("name templates style address port prefix ipv6" |
@@ -269,7 +269,7 b' def create_server(ui, app):' | |||
|
269 | 269 | import mimetypes; mimetypes.init() |
|
270 | 270 | |
|
271 | 271 | address = ui.config('web', 'address', '') |
|
272 |
port = |
|
|
272 | port = util.getport(ui.config('web', 'port', 8000)) | |
|
273 | 273 | try: |
|
274 | 274 | return cls(ui, app, (address, port), handler) |
|
275 | 275 | except socket.error, inst: |
@@ -37,7 +37,7 b' def _smtp(ui):' | |||
|
37 | 37 | mailhost = ui.config('smtp', 'host') |
|
38 | 38 | if not mailhost: |
|
39 | 39 | raise util.Abort(_('no [smtp]host in hgrc - cannot send mail')) |
|
40 |
mailport = |
|
|
40 | mailport = util.getport(ui.config('smtp', 'port', 25)) | |
|
41 | 41 | ui.note(_('sending mail: smtp host %s, port %s\n') % |
|
42 | 42 | (mailhost, mailport)) |
|
43 | 43 | s.connect(host=mailhost, port=mailport) |
@@ -17,7 +17,7 b' from i18n import _' | |||
|
17 | 17 | import error, osutil, encoding |
|
18 | 18 | import errno, re, shutil, sys, tempfile, traceback |
|
19 | 19 | import os, stat, time, calendar, textwrap, unicodedata, signal |
|
20 | import imp | |
|
20 | import imp, socket | |
|
21 | 21 | |
|
22 | 22 | # Python compatibility |
|
23 | 23 | |
@@ -1414,3 +1414,19 b' def interpolate(prefix, mapping, s, fn=N' | |||
|
1414 | 1414 | r = re.compile(r'%s(%s)' % (prefix, '|'.join(mapping.keys()))) |
|
1415 | 1415 | return r.sub(lambda x: fn(mapping[x.group()[1:]]), s) |
|
1416 | 1416 | |
|
1417 | def getport(port): | |
|
1418 | """Return the port for a given network service. | |
|
1419 | ||
|
1420 | If port is an integer, it's returned as is. If it's a string, it's | |
|
1421 | looked up using socket.getservbyname(). If there's no matching | |
|
1422 | service, util.Abort is raised. | |
|
1423 | """ | |
|
1424 | try: | |
|
1425 | return int(port) | |
|
1426 | except ValueError: | |
|
1427 | pass | |
|
1428 | ||
|
1429 | try: | |
|
1430 | return socket.getservbyname(port) | |
|
1431 | except socket.error: | |
|
1432 | raise Abort(_("no port number associated with service '%s'") % port) |
@@ -10,7 +10,11 b' hgserve()' | |||
|
10 | 10 | echo % errors |
|
11 | 11 | cat errors.log |
|
12 | 12 | sleep 1 |
|
13 | kill `cat hg.pid` | |
|
13 | if [ "$KILLQUIETLY" = "Y" ]; then | |
|
14 | kill `cat hg.pid` 2>/dev/null | |
|
15 | else | |
|
16 | kill `cat hg.pid` | |
|
17 | fi | |
|
14 | 18 | sleep 1 |
|
15 | 19 | } |
|
16 | 20 | |
@@ -36,6 +40,9 b' hgserve' | |||
|
36 | 40 | echo % With -v and -p HGPORT2 |
|
37 | 41 | hgserve -p "$HGPORT2" |
|
38 | 42 | |
|
43 | echo '% With -v and -p http (should fail)' | |
|
44 | KILLQUIETLY=Y hgserve -p http | |
|
45 | ||
|
39 | 46 | echo % With --prefix foo |
|
40 | 47 | hgserve --prefix foo |
|
41 | 48 |
@@ -7,6 +7,10 b' listening at http://localhost/ (bound to' | |||
|
7 | 7 | % With -v and -p HGPORT2 |
|
8 | 8 | listening at http://localhost/ (bound to 127.0.0.1:HGPORT2) |
|
9 | 9 | % errors |
|
10 | % With -v and -p http (should fail) | |
|
11 | abort: cannot start server at 'localhost:80': Permission denied | |
|
12 | abort: child process failed to start | |
|
13 | % errors | |
|
10 | 14 | % With --prefix foo |
|
11 | 15 | listening at http://localhost/foo/ (bound to 127.0.0.1:HGPORT1) |
|
12 | 16 | % errors |
General Comments 0
You need to be logged in to leave comments.
Login now