Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/hgwebdir_mod.py @ 4841:9b0ebb5e0f94
hgweb: let hgwebdir browse subdirectories
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Thu, 05 Jul 2007 19:44:06 -0700 |
parents | 53eca35c3aeb |
children | 496ac05c6a31 |
comparison
equal
deleted
inserted
replaced
4840:a265fe42abe7 | 4841:9b0ebb5e0f94 |
---|---|
88 return parentui.config(section, name, default, untrusted) | 88 return parentui.config(section, name, default, untrusted) |
89 | 89 |
90 url = req.env['REQUEST_URI'].split('?')[0] | 90 url = req.env['REQUEST_URI'].split('?')[0] |
91 if not url.endswith('/'): | 91 if not url.endswith('/'): |
92 url += '/' | 92 url += '/' |
93 | 93 pathinfo = req.env.get('PATH_INFO', '').strip('/') + '/' |
94 staticurl = config('web', 'staticurl') or url + 'static/' | 94 base = url[:len(url) - len(pathinfo)] |
95 if not base.endswith('/'): | |
96 base += '/' | |
97 | |
98 staticurl = config('web', 'staticurl') or base + 'static/' | |
95 if not staticurl.endswith('/'): | 99 if not staticurl.endswith('/'): |
96 staticurl += '/' | 100 staticurl += '/' |
97 | 101 |
98 style = self.style | 102 style = self.style |
99 if style is None: | 103 if style is None: |
116 if i[0] in allowed or ui.configbool("web", "allow" + i[0], | 120 if i[0] in allowed or ui.configbool("web", "allow" + i[0], |
117 untrusted=True): | 121 untrusted=True): |
118 yield {"type" : i[0], "extension": i[1], | 122 yield {"type" : i[0], "extension": i[1], |
119 "node": nodeid, "url": url} | 123 "node": nodeid, "url": url} |
120 | 124 |
121 def entries(sortcolumn="", descending=False, **map): | 125 def entries(sortcolumn="", descending=False, subdir="", **map): |
122 def sessionvars(**map): | 126 def sessionvars(**map): |
123 fields = [] | 127 fields = [] |
124 if req.form.has_key('style'): | 128 if req.form.has_key('style'): |
125 style = req.form['style'][0] | 129 style = req.form['style'][0] |
126 if style != get('web', 'style', ''): | 130 if style != get('web', 'style', ''): |
132 separator = ';' | 136 separator = ';' |
133 | 137 |
134 rows = [] | 138 rows = [] |
135 parity = paritygen(self.stripecount) | 139 parity = paritygen(self.stripecount) |
136 for name, path in self.repos: | 140 for name, path in self.repos: |
141 if not name.startswith(subdir): | |
142 continue | |
143 | |
137 u = ui.ui(parentui=parentui) | 144 u = ui.ui(parentui=parentui) |
138 try: | 145 try: |
139 u.readconfig(os.path.join(path, '.hg', 'hgrc')) | 146 u.readconfig(os.path.join(path, '.hg', 'hgrc')) |
140 except IOError: | 147 except IOError: |
141 pass | 148 pass |
143 return u.config(section, name, default, untrusted=True) | 150 return u.config(section, name, default, untrusted=True) |
144 | 151 |
145 if u.configbool("web", "hidden", untrusted=True): | 152 if u.configbool("web", "hidden", untrusted=True): |
146 continue | 153 continue |
147 | 154 |
148 url = ('/'.join([req.env["REQUEST_URI"].split('?')[0], name]) | 155 url = ('/'.join([req.env["REQUEST_URI"].split('?')[0], name[len(subdir):]]) |
149 .replace("//", "/")) + '/' | 156 .replace("//", "/")) + '/' |
150 | 157 |
151 # update time with local timezone | 158 # update time with local timezone |
152 try: | 159 try: |
153 d = (get_mtime(path), util.makedate()[1]) | 160 d = (get_mtime(path), util.makedate()[1]) |
183 rows.reverse() | 190 rows.reverse() |
184 for key, row in rows: | 191 for key, row in rows: |
185 row['parity'] = parity.next() | 192 row['parity'] = parity.next() |
186 yield row | 193 yield row |
187 | 194 |
195 def makeindex(req, subdir=""): | |
196 sortable = ["name", "description", "contact", "lastchange"] | |
197 sortcolumn, descending = self.repos_sorted | |
198 if req.form.has_key('sort'): | |
199 sortcolumn = req.form['sort'][0] | |
200 descending = sortcolumn.startswith('-') | |
201 if descending: | |
202 sortcolumn = sortcolumn[1:] | |
203 if sortcolumn not in sortable: | |
204 sortcolumn = "" | |
205 | |
206 sort = [("sort_%s" % column, | |
207 "%s%s" % ((not descending and column == sortcolumn) | |
208 and "-" or "", column)) | |
209 for column in sortable] | |
210 req.write(tmpl("index", entries=entries, subdir=subdir, | |
211 sortcolumn=sortcolumn, descending=descending, | |
212 **dict(sort))) | |
213 | |
188 try: | 214 try: |
189 virtual = req.env.get("PATH_INFO", "").strip('/') | 215 virtual = req.env.get("PATH_INFO", "").strip('/') |
190 if virtual.startswith('static/'): | 216 if virtual.startswith('static/'): |
191 static = os.path.join(templater.templatepath(), 'static') | 217 static = os.path.join(templater.templatepath(), 'static') |
192 fname = virtual[7:] | 218 fname = virtual[7:] |
209 except IOError, inst: | 235 except IOError, inst: |
210 req.write(tmpl("error", error=inst.strerror)) | 236 req.write(tmpl("error", error=inst.strerror)) |
211 except hg.RepoError, inst: | 237 except hg.RepoError, inst: |
212 req.write(tmpl("error", error=str(inst))) | 238 req.write(tmpl("error", error=str(inst))) |
213 else: | 239 else: |
214 req.write(tmpl("notfound", repo=virtual)) | 240 subdir=req.env.get("PATH_INFO", "").strip('/') + '/' |
241 if [r for r in self.repos if r[0].startswith(subdir)]: | |
242 makeindex(req, subdir) | |
243 else: | |
244 req.write(tmpl("notfound", repo=virtual)) | |
215 else: | 245 else: |
216 if req.form.has_key('static'): | 246 if req.form.has_key('static'): |
217 static = os.path.join(templater.templatepath(), "static") | 247 static = os.path.join(templater.templatepath(), "static") |
218 fname = req.form['static'][0] | 248 fname = req.form['static'][0] |
219 req.write(staticfile(static, fname, req) | 249 req.write(staticfile(static, fname, req) |
220 or tmpl("error", error="%r not found" % fname)) | 250 or tmpl("error", error="%r not found" % fname)) |
221 else: | 251 else: |
222 sortable = ["name", "description", "contact", "lastchange"] | 252 makeindex(req) |
223 sortcolumn, descending = self.repos_sorted | |
224 if req.form.has_key('sort'): | |
225 sortcolumn = req.form['sort'][0] | |
226 descending = sortcolumn.startswith('-') | |
227 if descending: | |
228 sortcolumn = sortcolumn[1:] | |
229 if sortcolumn not in sortable: | |
230 sortcolumn = "" | |
231 | |
232 sort = [("sort_%s" % column, | |
233 "%s%s" % ((not descending and column == sortcolumn) | |
234 and "-" or "", column)) | |
235 for column in sortable] | |
236 req.write(tmpl("index", entries=entries, | |
237 sortcolumn=sortcolumn, descending=descending, | |
238 **dict(sort))) | |
239 finally: | 253 finally: |
240 tmpl = None | 254 tmpl = None |