Show More
@@ -1,107 +1,110 b'' | |||||
1 | # hgweb/__init__.py - web interface to a mercurial repository |
|
1 | # hgweb/__init__.py - web interface to a mercurial repository | |
2 | # |
|
2 | # | |
3 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
|
3 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> | |
4 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
4 | # Copyright 2005 Matt Mackall <mpm@selenic.com> | |
5 | # |
|
5 | # | |
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
7 | # GNU General Public License version 2 or any later version. |
|
7 | # GNU General Public License version 2 or any later version. | |
8 |
|
8 | |||
9 | from __future__ import absolute_import |
|
9 | from __future__ import absolute_import | |
10 |
|
10 | |||
11 | import os |
|
11 | import os | |
12 |
|
12 | |||
13 | from ..i18n import _ |
|
13 | from ..i18n import _ | |
14 |
|
14 | |||
15 | from .. import ( |
|
15 | from .. import ( | |
16 | error, |
|
16 | error, | |
17 | pycompat, |
|
17 | pycompat, | |
18 | ) |
|
18 | ) | |
19 |
|
19 | |||
20 | from ..utils import ( |
|
20 | from ..utils import ( | |
21 | procutil, |
|
21 | procutil, | |
22 | ) |
|
22 | ) | |
23 |
|
23 | |||
24 | from . import ( |
|
24 | from . import ( | |
25 | hgweb_mod, |
|
25 | hgweb_mod, | |
26 | hgwebdir_mod, |
|
26 | hgwebdir_mod, | |
27 | server, |
|
27 | server, | |
28 | ) |
|
28 | ) | |
29 |
|
29 | |||
30 | def hgweb(config, name=None, baseui=None): |
|
30 | def hgweb(config, name=None, baseui=None): | |
31 | '''create an hgweb wsgi object |
|
31 | '''create an hgweb wsgi object | |
32 |
|
32 | |||
33 | config can be one of: |
|
33 | config can be one of: | |
34 | - repo object (single repo view) |
|
34 | - repo object (single repo view) | |
35 | - path to repo (single repo view) |
|
35 | - path to repo (single repo view) | |
36 | - path to config file (multi-repo view) |
|
36 | - path to config file (multi-repo view) | |
37 | - dict of virtual:real pairs (multi-repo view) |
|
37 | - dict of virtual:real pairs (multi-repo view) | |
38 | - list of virtual:real tuples (multi-repo view) |
|
38 | - list of virtual:real tuples (multi-repo view) | |
39 | ''' |
|
39 | ''' | |
40 |
|
40 | |||
|
41 | if isinstance(config, pycompat.unicode): | |||
|
42 | raise error.ProgrammingError( | |||
|
43 | 'Mercurial only supports encoded strings: %r' % config) | |||
41 | if ((isinstance(config, bytes) and not os.path.isdir(config)) or |
|
44 | if ((isinstance(config, bytes) and not os.path.isdir(config)) or | |
42 | isinstance(config, dict) or isinstance(config, list)): |
|
45 | isinstance(config, dict) or isinstance(config, list)): | |
43 | # create a multi-dir interface |
|
46 | # create a multi-dir interface | |
44 | return hgwebdir_mod.hgwebdir(config, baseui=baseui) |
|
47 | return hgwebdir_mod.hgwebdir(config, baseui=baseui) | |
45 | return hgweb_mod.hgweb(config, name=name, baseui=baseui) |
|
48 | return hgweb_mod.hgweb(config, name=name, baseui=baseui) | |
46 |
|
49 | |||
47 | def hgwebdir(config, baseui=None): |
|
50 | def hgwebdir(config, baseui=None): | |
48 | return hgwebdir_mod.hgwebdir(config, baseui=baseui) |
|
51 | return hgwebdir_mod.hgwebdir(config, baseui=baseui) | |
49 |
|
52 | |||
50 | class httpservice(object): |
|
53 | class httpservice(object): | |
51 | def __init__(self, ui, app, opts): |
|
54 | def __init__(self, ui, app, opts): | |
52 | self.ui = ui |
|
55 | self.ui = ui | |
53 | self.app = app |
|
56 | self.app = app | |
54 | self.opts = opts |
|
57 | self.opts = opts | |
55 |
|
58 | |||
56 | def init(self): |
|
59 | def init(self): | |
57 | procutil.setsignalhandler() |
|
60 | procutil.setsignalhandler() | |
58 | self.httpd = server.create_server(self.ui, self.app) |
|
61 | self.httpd = server.create_server(self.ui, self.app) | |
59 |
|
62 | |||
60 | if (self.opts['port'] and |
|
63 | if (self.opts['port'] and | |
61 | not self.ui.verbose and |
|
64 | not self.ui.verbose and | |
62 | not self.opts['print_url']): |
|
65 | not self.opts['print_url']): | |
63 | return |
|
66 | return | |
64 |
|
67 | |||
65 | if self.httpd.prefix: |
|
68 | if self.httpd.prefix: | |
66 | prefix = self.httpd.prefix.strip('/') + '/' |
|
69 | prefix = self.httpd.prefix.strip('/') + '/' | |
67 | else: |
|
70 | else: | |
68 | prefix = '' |
|
71 | prefix = '' | |
69 |
|
72 | |||
70 | port = r':%d' % self.httpd.port |
|
73 | port = r':%d' % self.httpd.port | |
71 | if port == r':80': |
|
74 | if port == r':80': | |
72 | port = r'' |
|
75 | port = r'' | |
73 |
|
76 | |||
74 | bindaddr = self.httpd.addr |
|
77 | bindaddr = self.httpd.addr | |
75 | if bindaddr == r'0.0.0.0': |
|
78 | if bindaddr == r'0.0.0.0': | |
76 | bindaddr = r'*' |
|
79 | bindaddr = r'*' | |
77 | elif r':' in bindaddr: # IPv6 |
|
80 | elif r':' in bindaddr: # IPv6 | |
78 | bindaddr = r'[%s]' % bindaddr |
|
81 | bindaddr = r'[%s]' % bindaddr | |
79 |
|
82 | |||
80 | fqaddr = self.httpd.fqaddr |
|
83 | fqaddr = self.httpd.fqaddr | |
81 | if r':' in fqaddr: |
|
84 | if r':' in fqaddr: | |
82 | fqaddr = r'[%s]' % fqaddr |
|
85 | fqaddr = r'[%s]' % fqaddr | |
83 |
|
86 | |||
84 | url = 'http://%s%s/%s' % ( |
|
87 | url = 'http://%s%s/%s' % ( | |
85 | pycompat.sysbytes(fqaddr), pycompat.sysbytes(port), prefix) |
|
88 | pycompat.sysbytes(fqaddr), pycompat.sysbytes(port), prefix) | |
86 | if self.opts['print_url']: |
|
89 | if self.opts['print_url']: | |
87 | self.ui.write('%s\n' % url) |
|
90 | self.ui.write('%s\n' % url) | |
88 | else: |
|
91 | else: | |
89 | if self.opts['port']: |
|
92 | if self.opts['port']: | |
90 | write = self.ui.status |
|
93 | write = self.ui.status | |
91 | else: |
|
94 | else: | |
92 | write = self.ui.write |
|
95 | write = self.ui.write | |
93 | write(_('listening at %s (bound to %s:%d)\n') % |
|
96 | write(_('listening at %s (bound to %s:%d)\n') % | |
94 | (url, pycompat.sysbytes(bindaddr), self.httpd.port)) |
|
97 | (url, pycompat.sysbytes(bindaddr), self.httpd.port)) | |
95 | self.ui.flush() # avoid buffering of status message |
|
98 | self.ui.flush() # avoid buffering of status message | |
96 |
|
99 | |||
97 | def run(self): |
|
100 | def run(self): | |
98 | self.httpd.serve_forever() |
|
101 | self.httpd.serve_forever() | |
99 |
|
102 | |||
100 | def createapp(baseui, repo, webconf): |
|
103 | def createapp(baseui, repo, webconf): | |
101 | if webconf: |
|
104 | if webconf: | |
102 | return hgwebdir_mod.hgwebdir(webconf, baseui=baseui) |
|
105 | return hgwebdir_mod.hgwebdir(webconf, baseui=baseui) | |
103 | else: |
|
106 | else: | |
104 | if not repo: |
|
107 | if not repo: | |
105 | raise error.RepoError(_("there is no Mercurial repository" |
|
108 | raise error.RepoError(_("there is no Mercurial repository" | |
106 | " here (.hg not found)")) |
|
109 | " here (.hg not found)")) | |
107 | return hgweb_mod.hgweb(repo, baseui=baseui) |
|
110 | return hgweb_mod.hgweb(repo, baseui=baseui) |
General Comments 0
You need to be logged in to leave comments.
Login now