Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/hgwebdir_mod.py @ 5603:74f65f44a9aa
hgwebdir: refactor inner loop
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Mon, 03 Dec 2007 19:19:12 +0100 |
parents | d676d0f35bd8 |
children | 0145f9afb0e7 |
comparison
equal
deleted
inserted
replaced
5602:d676d0f35bd8 | 5603:74f65f44a9aa |
---|---|
71 | 71 |
72 def run_wsgi(self, req): | 72 def run_wsgi(self, req): |
73 | 73 |
74 try: | 74 try: |
75 try: | 75 try: |
76 | |
76 virtual = req.env.get("PATH_INFO", "").strip('/') | 77 virtual = req.env.get("PATH_INFO", "").strip('/') |
77 if virtual.startswith('static/'): | 78 |
79 # a static file | |
80 if virtual.startswith('static/') or 'static' in req.form: | |
78 static = os.path.join(templater.templatepath(), 'static') | 81 static = os.path.join(templater.templatepath(), 'static') |
79 fname = virtual[7:] | 82 if virtual.startswith('static/'): |
83 fname = virtual[7:] | |
84 else: | |
85 fname = req.form['static'][0] | |
80 req.write(staticfile(static, fname, req)) | 86 req.write(staticfile(static, fname, req)) |
81 elif virtual: | 87 return |
82 repos = dict(self.repos) | 88 |
83 while virtual: | 89 # top-level index |
84 real = repos.get(virtual) | 90 elif not virtual: |
85 if real: | 91 tmpl = self.templater(req) |
86 req.env['REPO_NAME'] = virtual | 92 self.makeindex(req, tmpl) |
87 try: | 93 return |
88 repo = hg.repository(self.parentui, real) | 94 |
89 hgweb(repo).run_wsgi(req) | 95 # nested indexes and hgwebs |
90 return | 96 repos = dict(self.repos) |
91 except IOError, inst: | 97 while virtual: |
92 raise ErrorResponse(500, inst.strerror) | 98 real = repos.get(virtual) |
93 except hg.RepoError, inst: | 99 if real: |
94 raise ErrorResponse(500, str(inst)) | 100 req.env['REPO_NAME'] = virtual |
95 | 101 try: |
96 # browse subdirectories | 102 repo = hg.repository(self.parentui, real) |
97 subdir = virtual + '/' | 103 hgweb(repo).run_wsgi(req) |
98 if [r for r in repos if r.startswith(subdir)]: | |
99 tmpl = self.templater(req) | |
100 self.makeindex(req, tmpl, subdir) | |
101 return | 104 return |
102 | 105 except IOError, inst: |
103 up = virtual.rfind('/') | 106 raise ErrorResponse(500, inst.strerror) |
104 if up < 0: | 107 except hg.RepoError, inst: |
105 break | 108 raise ErrorResponse(500, str(inst)) |
106 virtual = virtual[:up] | 109 |
107 | 110 # browse subdirectories |
108 tmpl = self.templater(req) | 111 subdir = virtual + '/' |
109 req.respond(404, tmpl("notfound", repo=virtual)) | 112 if [r for r in repos if r.startswith(subdir)]: |
110 else: | |
111 if req.form.has_key('static'): | |
112 static = os.path.join(templater.templatepath(), "static") | |
113 fname = req.form['static'][0] | |
114 req.write(staticfile(static, fname, req)) | |
115 else: | |
116 tmpl = self.templater(req) | 113 tmpl = self.templater(req) |
117 self.makeindex(req, tmpl) | 114 self.makeindex(req, tmpl, subdir) |
115 return | |
116 | |
117 up = virtual.rfind('/') | |
118 if up < 0: | |
119 break | |
120 virtual = virtual[:up] | |
121 | |
122 # prefixes not found | |
123 tmpl = self.templater(req) | |
124 req.respond(404, tmpl("notfound", repo=virtual)) | |
125 | |
118 except ErrorResponse, err: | 126 except ErrorResponse, err: |
127 tmpl = self.templater(req) | |
119 req.respond(err.code, tmpl('error', error=err.message or '')) | 128 req.respond(err.code, tmpl('error', error=err.message or '')) |
120 finally: | 129 finally: |
121 tmpl = None | 130 tmpl = None |
122 | 131 |
123 def makeindex(self, req, tmpl, subdir=""): | 132 def makeindex(self, req, tmpl, subdir=""): |