##// END OF EJS Templates
mail/hgweb: support service names for ports (issue2350)...
Brodie Rao -
r12076:49463314 default
parent child Browse files
Show More
@@ -27,7 +27,7 b' You can discover Zeroconf-enabled reposi'
27 import socket, time, os
27 import socket, time, os
28
28
29 import Zeroconf
29 import Zeroconf
30 from mercurial import ui, hg, encoding
30 from mercurial import ui, hg, encoding, util
31 from mercurial import extensions
31 from mercurial import extensions
32 from mercurial.hgweb import hgweb_mod
32 from mercurial.hgweb import hgweb_mod
33 from mercurial.hgweb import hgwebdir_mod
33 from mercurial.hgweb import hgwebdir_mod
@@ -107,7 +107,7 b' class hgwebzc(hgweb_mod.hgweb):'
107 path = self.repo.ui.config("web", "prefix", "").strip('/')
107 path = self.repo.ui.config("web", "prefix", "").strip('/')
108 desc = self.repo.ui.config("web", "description", name)
108 desc = self.repo.ui.config("web", "description", name)
109 publish(name, desc, path,
109 publish(name, desc, path,
110 int(self.repo.ui.config("web", "port", 8000)))
110 util.getport(self.repo.ui.config("web", "port", 8000)))
111
111
112 class hgwebdirzc(hgwebdir_mod.hgwebdir):
112 class hgwebdirzc(hgwebdir_mod.hgwebdir):
113 def __init__(self, conf, baseui=None):
113 def __init__(self, conf, baseui=None):
@@ -119,7 +119,7 b' class hgwebdirzc(hgwebdir_mod.hgwebdir):'
119 name = os.path.basename(repo)
119 name = os.path.basename(repo)
120 path = (prefix + repo).strip('/')
120 path = (prefix + repo).strip('/')
121 desc = u.config('web', 'description', name)
121 desc = u.config('web', 'description', name)
122 publish(name, desc, path, int(u.config("web", "port", 8000)))
122 publish(name, desc, path, util.getport(u.config("web", "port", 8000)))
123
123
124 # listen
124 # listen
125
125
@@ -3332,7 +3332,7 b' def serve(ui, repo, **opts):'
3332
3332
3333 # this way we can check if something was given in the command-line
3333 # this way we can check if something was given in the command-line
3334 if opts.get('port'):
3334 if opts.get('port'):
3335 opts['port'] = int(opts.get('port'))
3335 opts['port'] = util.getport(opts.get('port'))
3336
3336
3337 baseui = repo and repo.baseui or ui
3337 baseui = repo and repo.baseui or ui
3338 optlist = ("name templates style address port prefix ipv6"
3338 optlist = ("name templates style address port prefix ipv6"
@@ -269,7 +269,7 b' def create_server(ui, app):'
269 import mimetypes; mimetypes.init()
269 import mimetypes; mimetypes.init()
270
270
271 address = ui.config('web', 'address', '')
271 address = ui.config('web', 'address', '')
272 port = int(ui.config('web', 'port', 8000))
272 port = util.getport(ui.config('web', 'port', 8000))
273 try:
273 try:
274 return cls(ui, app, (address, port), handler)
274 return cls(ui, app, (address, port), handler)
275 except socket.error, inst:
275 except socket.error, inst:
@@ -37,7 +37,7 b' def _smtp(ui):'
37 mailhost = ui.config('smtp', 'host')
37 mailhost = ui.config('smtp', 'host')
38 if not mailhost:
38 if not mailhost:
39 raise util.Abort(_('no [smtp]host in hgrc - cannot send mail'))
39 raise util.Abort(_('no [smtp]host in hgrc - cannot send mail'))
40 mailport = int(ui.config('smtp', 'port', 25))
40 mailport = util.getport(ui.config('smtp', 'port', 25))
41 ui.note(_('sending mail: smtp host %s, port %s\n') %
41 ui.note(_('sending mail: smtp host %s, port %s\n') %
42 (mailhost, mailport))
42 (mailhost, mailport))
43 s.connect(host=mailhost, port=mailport)
43 s.connect(host=mailhost, port=mailport)
@@ -17,7 +17,7 b' from i18n import _'
17 import error, osutil, encoding
17 import error, osutil, encoding
18 import errno, re, shutil, sys, tempfile, traceback
18 import errno, re, shutil, sys, tempfile, traceback
19 import os, stat, time, calendar, textwrap, unicodedata, signal
19 import os, stat, time, calendar, textwrap, unicodedata, signal
20 import imp
20 import imp, socket
21
21
22 # Python compatibility
22 # Python compatibility
23
23
@@ -1414,3 +1414,19 b' def interpolate(prefix, mapping, s, fn=N'
1414 r = re.compile(r'%s(%s)' % (prefix, '|'.join(mapping.keys())))
1414 r = re.compile(r'%s(%s)' % (prefix, '|'.join(mapping.keys())))
1415 return r.sub(lambda x: fn(mapping[x.group()[1:]]), s)
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 echo % errors
10 echo % errors
11 cat errors.log
11 cat errors.log
12 sleep 1
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 sleep 1
18 sleep 1
15 }
19 }
16
20
@@ -36,6 +40,9 b' hgserve'
36 echo % With -v and -p HGPORT2
40 echo % With -v and -p HGPORT2
37 hgserve -p "$HGPORT2"
41 hgserve -p "$HGPORT2"
38
42
43 echo '% With -v and -p http (should fail)'
44 KILLQUIETLY=Y hgserve -p http
45
39 echo % With --prefix foo
46 echo % With --prefix foo
40 hgserve --prefix foo
47 hgserve --prefix foo
41
48
@@ -7,6 +7,10 b' listening at http://localhost/ (bound to'
7 % With -v and -p HGPORT2
7 % With -v and -p HGPORT2
8 listening at http://localhost/ (bound to 127.0.0.1:HGPORT2)
8 listening at http://localhost/ (bound to 127.0.0.1:HGPORT2)
9 % errors
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 % With --prefix foo
14 % With --prefix foo
11 listening at http://localhost/foo/ (bound to 127.0.0.1:HGPORT1)
15 listening at http://localhost/foo/ (bound to 127.0.0.1:HGPORT1)
12 % errors
16 % errors
General Comments 0
You need to be logged in to leave comments. Login now