87 static = os.path.join(templater.templatepath(), 'static') |
88 static = os.path.join(templater.templatepath(), 'static') |
88 if virtual.startswith('static/'): |
89 if virtual.startswith('static/'): |
89 fname = virtual[7:] |
90 fname = virtual[7:] |
90 else: |
91 else: |
91 fname = req.form['static'][0] |
92 fname = req.form['static'][0] |
92 return staticfile(static, fname, req), |
93 req.write(staticfile(static, fname, req)) |
|
94 return |
93 |
95 |
94 # top-level index |
96 # top-level index |
95 elif not virtual: |
97 elif not virtual: |
96 req.respond(HTTP_OK, ctype) |
98 req.respond(HTTP_OK, ctype) |
97 return ''.join(self.makeindex(req, tmpl)), |
99 req.write(self.makeindex(req, tmpl)) |
|
100 return |
98 |
101 |
99 # nested indexes and hgwebs |
102 # nested indexes and hgwebs |
100 |
103 |
101 repos = dict(self.repos) |
104 repos = dict(self.repos) |
102 while virtual: |
105 while virtual: |
103 real = repos.get(virtual) |
106 real = repos.get(virtual) |
104 if real: |
107 if real: |
105 req.env['REPO_NAME'] = virtual |
108 req.env['REPO_NAME'] = virtual |
106 try: |
109 try: |
107 repo = hg.repository(self.parentui, real) |
110 repo = hg.repository(self.parentui, real) |
108 return hgweb(repo).run_wsgi(req) |
111 hgweb(repo).run_wsgi(req) |
|
112 return |
109 except IOError, inst: |
113 except IOError, inst: |
110 msg = inst.strerror |
114 msg = inst.strerror |
111 raise ErrorResponse(HTTP_SERVER_ERROR, msg) |
115 raise ErrorResponse(HTTP_SERVER_ERROR, msg) |
112 except RepoError, inst: |
116 except RepoError, inst: |
113 raise ErrorResponse(HTTP_SERVER_ERROR, str(inst)) |
117 raise ErrorResponse(HTTP_SERVER_ERROR, str(inst)) |
114 |
118 |
115 # browse subdirectories |
119 # browse subdirectories |
116 subdir = virtual + '/' |
120 subdir = virtual + '/' |
117 if [r for r in repos if r.startswith(subdir)]: |
121 if [r for r in repos if r.startswith(subdir)]: |
118 req.respond(HTTP_OK, ctype) |
122 req.respond(HTTP_OK, ctype) |
119 return ''.join(self.makeindex(req, tmpl, subdir)), |
123 req.write(self.makeindex(req, tmpl, subdir)) |
|
124 return |
120 |
125 |
121 up = virtual.rfind('/') |
126 up = virtual.rfind('/') |
122 if up < 0: |
127 if up < 0: |
123 break |
128 break |
124 virtual = virtual[:up] |
129 virtual = virtual[:up] |
125 |
130 |
126 # prefixes not found |
131 # prefixes not found |
127 req.respond(HTTP_NOT_FOUND, ctype) |
132 req.respond(HTTP_NOT_FOUND, ctype) |
128 return ''.join(tmpl("notfound", repo=virtual)), |
133 req.write(tmpl("notfound", repo=virtual)) |
129 |
134 |
130 except ErrorResponse, err: |
135 except ErrorResponse, err: |
131 req.respond(err.code, ctype) |
136 req.respond(err.code, ctype) |
132 return ''.join(tmpl('error', error=err.message or '')), |
137 req.write(tmpl('error', error=err.message or '')) |
133 finally: |
138 finally: |
134 tmpl = None |
139 tmpl = None |
135 |
140 |
136 def makeindex(self, req, tmpl, subdir=""): |
141 def makeindex(self, req, tmpl, subdir=""): |
137 |
142 |