7 # of the GNU General Public License, incorporated herein by reference. |
7 # of the GNU General Public License, incorporated herein by reference. |
8 |
8 |
9 import os, mimetools, cStringIO |
9 import os, mimetools, cStringIO |
10 from mercurial.i18n import gettext as _ |
10 from mercurial.i18n import gettext as _ |
11 from mercurial import ui, hg, util, templater |
11 from mercurial import ui, hg, util, templater |
12 from common import get_mtime, staticfile, style_map, paritygen |
12 from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen |
13 from hgweb_mod import hgweb |
13 from hgweb_mod import hgweb |
14 |
14 |
15 # This is a stopgap |
15 # This is a stopgap |
16 class hgwebdir(object): |
16 class hgwebdir(object): |
17 def __init__(self, config, parentui=None): |
17 def __init__(self, config, parentui=None): |
213 req.write(tmpl("index", entries=entries, subdir=subdir, |
213 req.write(tmpl("index", entries=entries, subdir=subdir, |
214 sortcolumn=sortcolumn, descending=descending, |
214 sortcolumn=sortcolumn, descending=descending, |
215 **dict(sort))) |
215 **dict(sort))) |
216 |
216 |
217 try: |
217 try: |
218 virtual = req.env.get("PATH_INFO", "").strip('/') |
218 try: |
219 if virtual.startswith('static/'): |
219 virtual = req.env.get("PATH_INFO", "").strip('/') |
220 static = os.path.join(templater.templatepath(), 'static') |
220 if virtual.startswith('static/'): |
221 fname = virtual[7:] |
221 static = os.path.join(templater.templatepath(), 'static') |
222 req.write(staticfile(static, fname, req) or |
222 fname = virtual[7:] |
223 tmpl('error', error='%r not found' % fname)) |
223 req.write(staticfile(static, fname, req)) |
224 elif virtual: |
224 elif virtual: |
225 repos = dict(self.repos) |
225 repos = dict(self.repos) |
226 while virtual: |
226 while virtual: |
227 real = repos.get(virtual) |
227 real = repos.get(virtual) |
228 if real: |
228 if real: |
229 req.env['REPO_NAME'] = virtual |
229 req.env['REPO_NAME'] = virtual |
230 try: |
230 try: |
231 repo = hg.repository(parentui, real) |
231 repo = hg.repository(parentui, real) |
232 hgweb(repo).run_wsgi(req) |
232 hgweb(repo).run_wsgi(req) |
233 except IOError, inst: |
233 return |
234 req.write(tmpl("error", error=inst.strerror)) |
234 except IOError, inst: |
235 except hg.RepoError, inst: |
235 raise ErrorResponse(500, inst.strerror) |
236 req.write(tmpl("error", error=str(inst))) |
236 except hg.RepoError, inst: |
237 return |
237 raise ErrorResponse(500, str(inst)) |
238 |
238 |
239 # browse subdirectories |
239 # browse subdirectories |
240 subdir = virtual + '/' |
240 subdir = virtual + '/' |
241 if [r for r in repos if r.startswith(subdir)]: |
241 if [r for r in repos if r.startswith(subdir)]: |
242 makeindex(req, subdir) |
242 makeindex(req, subdir) |
243 return |
243 return |
244 |
244 |
245 up = virtual.rfind('/') |
245 up = virtual.rfind('/') |
246 if up < 0: |
246 if up < 0: |
247 break |
247 break |
248 virtual = virtual[:up] |
248 virtual = virtual[:up] |
249 |
249 |
250 req.write(tmpl("notfound", repo=virtual)) |
250 req.respond(404, tmpl("notfound", repo=virtual)) |
251 else: |
|
252 if req.form.has_key('static'): |
|
253 static = os.path.join(templater.templatepath(), "static") |
|
254 fname = req.form['static'][0] |
|
255 req.write(staticfile(static, fname, req) |
|
256 or tmpl("error", error="%r not found" % fname)) |
|
257 else: |
251 else: |
258 makeindex(req) |
252 if req.form.has_key('static'): |
|
253 static = os.path.join(templater.templatepath(), "static") |
|
254 fname = req.form['static'][0] |
|
255 req.write(staticfile(static, fname, req)) |
|
256 else: |
|
257 makeindex(req) |
|
258 except ErrorResponse, err: |
|
259 req.respond(err.code, tmpl('error', error=err.message or '')) |
259 finally: |
260 finally: |
260 tmpl = None |
261 tmpl = None |