| 86 | | self.log.debug(req.path_info) |
|---|
| 87 | | match = re.match('^/doxygen(?:/?$|/([^/]*)(?:/?$|/(.*)$))', |
|---|
| 88 | | req.path_info) |
|---|
| 89 | | if match: |
|---|
| 90 | | self.log.debug('matched group 1: %s' % (match.group(1),)) |
|---|
| 91 | | self.log.debug('matched group 2: %s' % (match.group(2),)) |
|---|
| 92 | | |
|---|
| 93 | | if not match.group(1) and not match.group(2): |
|---|
| 94 | | # Request for documentation index. |
|---|
| 95 | | req.args['path'] = os.path.join(self.base_path, |
|---|
| 96 | | self.default_doc) |
|---|
| 97 | | req.args['action'] = 'index' |
|---|
| 98 | | else: |
|---|
| 99 | | # Get doc and file from request. |
|---|
| 100 | | if not match.group(2): |
|---|
| 101 | | doc = self.default_doc |
|---|
| 102 | | file = match.group(1) |
|---|
| 103 | | else: |
|---|
| 104 | | doc = match.group(1) |
|---|
| 105 | | file = match.group(2) |
|---|
| 106 | | |
|---|
| 107 | | self.log.debug('documentation: %s' % (doc,)) |
|---|
| 108 | | self.log.debug('file: %s' % (file,)) |
|---|
| 109 | | |
|---|
| 110 | | if re.match(r'''^search.php$''', file): |
|---|
| 111 | | # Request for searching. |
|---|
| 112 | | req.args['action'] = 'search' |
|---|
| 113 | | |
|---|
| 114 | | elif re.match(r'''^(.*)[.](%s)''' % (ext,), file): |
|---|
| 115 | | # Request for documentation file. |
|---|
| 116 | | path = os.path.join(self.base_path, doc, file) |
|---|
| 117 | | self.log.debug('path: %s' % (path,)) |
|---|
| 118 | | if os.path.exists(path): |
|---|
| 119 | | req.args['path'] = path |
|---|
| 120 | | req.args['action'] = 'file' |
|---|
| 121 | | else: |
|---|
| 122 | | req.args['action'] = 'search' |
|---|
| 123 | | req.args['query'] = file |
|---|
| 124 | | |
|---|
| 125 | | else: |
|---|
| 126 | | match = re.match(r'''^(.*)[.](%s)''' % (source_ext,), file) |
|---|
| 127 | | if match: |
|---|
| 128 | | # Request for source file documentation. |
|---|
| 129 | | path = os.path.join(self.base_path, doc, '%s_8%s.html' |
|---|
| 130 | | % (match.group(1), match.group(2))) |
|---|
| 131 | | self.log.debug('path: %s' % (path,)) |
|---|
| 132 | | if os.path.exists(path): |
|---|
| 133 | | req.args['path'] = path |
|---|
| 134 | | req.args['action'] = 'file' |
|---|
| 135 | | else: |
|---|
| 136 | | req.args['action'] = 'search' |
|---|
| 137 | | req.args['query'] = file |
|---|
| 138 | | |
|---|
| 139 | | else: |
|---|
| 140 | | path = os.path.join(self.base_path, doc, 'class%s.html' |
|---|
| 141 | | % (file,)) |
|---|
| 142 | | if os.path.exists(path): |
|---|
| 143 | | req.args['path'] = path |
|---|
| 144 | | req.args['action'] = 'file' |
|---|
| 145 | | else: |
|---|
| 146 | | path = os.path.join(self.base_path, doc, |
|---|
| 147 | | 'struct%s.html' % (file,)) |
|---|
| 148 | | if os.path.exists(path): |
|---|
| 149 | | req.args['path'] = path |
|---|
| 150 | | req.args['action'] = 'file' |
|---|
| 151 | | else: |
|---|
| 152 | | results = self._search_in_documentation(doc, |
|---|
| 153 | | [file]) |
|---|
| 154 | | for result in results: |
|---|
| 155 | | self.log.debug(result) |
|---|
| 156 | | if result['name'] == file: |
|---|
| 157 | | req.redirect(req.href.doxygen(doc) |
|---|
| 158 | | + '/' + result['url']) |
|---|
| 159 | | req.args['action'] = 'search' |
|---|
| 160 | | req.args['query'] = file |
|---|
| 161 | | # Request matched. |
|---|
| | 89 | if re.match(r'^/doxygen(?:$|/)', req.path_info): |
|---|
| | 90 | if 'path' not in req.args: |
|---|
| | 91 | segments = filter(None, req.path_info.split('/')) |
|---|
| | 92 | segments = segments[1:] # ditch 'doxygen' |
|---|
| | 93 | action, path, link = self._doxygen_lookup(segments) |
|---|
| | 94 | if action: |
|---|
| | 95 | req.args['action'] = action |
|---|
| | 96 | if action == 'search' and path: |
|---|
| | 97 | req.args['query'] = path |
|---|
| | 98 | req.args['path'] = path |
|---|
| 186 | | # Get access to database |
|---|
| 187 | | db = self.env.get_db_cnx() |
|---|
| 188 | | cursor = db.cursor() |
|---|
| 189 | | |
|---|
| 190 | | # Get wiki index # FIXME: use WikiPage() instead |
|---|
| 191 | | sql = "SELECT text FROM wiki WHERE name = %s" |
|---|
| 192 | | cursor.execute(sql, (self.wiki_index,)) |
|---|
| 193 | | text = system_message('Error', 'Wiki page %s does not exists' % |
|---|
| 194 | | self.wiki_index) |
|---|
| 195 | | for row in cursor: |
|---|
| 196 | | text = wiki_to_html(row[0], self.env, req) |
|---|
| 197 | | |
|---|
| 198 | | # Display wiki index page |
|---|
| 199 | | req.hdf['doxygen.text'] = text |
|---|
| | 118 | if WikiSystem(self.env).has_page(self.wiki_index): |
|---|
| | 119 | req.redirect(req.href.wiki(self.wiki_index)) |
|---|
| | 120 | # Display missing wiki |
|---|
| | 121 | text = wiki_to_html('Doxygen index page [wiki:%s] does not ' |
|---|
| | 122 | 'exists' % self.wiki_index, self.env, req) |
|---|
| | 123 | req.hdf['doxygen.text'] = system_message('Error', text) |
|---|
| 264 | | yield ('doxygen', self._doxygen_link) |
|---|
| | 185 | def doxygen_link(formatter, ns, params, label): |
|---|
| | 186 | action, path, link = self._doxygen_lookup(params.split('/')) |
|---|
| | 187 | if action in ('view', 'index', 'redirect'): |
|---|
| | 188 | return html.a(label, title=params, |
|---|
| | 189 | href=formatter.href.doxygen(link, path=path)) |
|---|
| | 190 | else: |
|---|
| | 191 | return html.a(label, title=params, class_='missing', |
|---|
| | 192 | href=formatter.href.doxygen()) |
|---|
| | 193 | yield ('doxygen', doxygen_link) |
|---|
| | 199 | |
|---|
| | 200 | def _doxygen_lookup(self, segments): |
|---|
| | 201 | """Try to interpret path components as a request for doxygen targets |
|---|
| | 202 | |
|---|
| | 203 | Return an `(action,path,link)` pair, where: |
|---|
| | 204 | - `action` describes what should be done (one of 'view', |
|---|
| | 205 | 'search' or 'index'), |
|---|
| | 206 | - `path` is the location on disk of the resource. |
|---|
| | 207 | - `link` is the link to the resource, relative to the |
|---|
| | 208 | req.href.doxygen base, |
|---|
| | 209 | """ |
|---|
| | 210 | doc, file = segments[:-1], segments and segments[-1] |
|---|
| | 211 | doc = doc and os.path.join(*doc) or self.default_doc |
|---|
| | 212 | def lookup(file, category='undefined'): |
|---|
| | 213 | path = os.path.join(self.base_path, doc, file) |
|---|
| | 214 | self.log.debug('%s file "%s" (at %s)' % (category, file, path)) |
|---|
| | 215 | return os.path.exists(path) and path, doc + '/' + file |
|---|
| | 216 | |
|---|
| | 217 | if not file: |
|---|
| | 218 | path, link = lookup('index.html', 'index') |
|---|
| | 219 | return 'index', path, link |
|---|
| | 220 | |
|---|
| | 221 | self.log.debug('looking up "%s" in documentation "%s"' % (file, doc)) |
|---|
| | 222 | |
|---|
| | 223 | # Direct request for searching |
|---|
| | 224 | if file == 'search.php': |
|---|
| | 225 | return 'search', None, None |
|---|
| | 226 | |
|---|
| | 227 | # Request for a documentation file. |
|---|
| | 228 | doc_ext_re = '|'.join(self.ext.split(' ')) |
|---|
| | 229 | if re.match(r'''^(.*)[.](%s)''' % doc_ext_re, file): |
|---|
| | 230 | path, link = lookup(file, 'documentation') |
|---|
| | 231 | if path: |
|---|
| | 232 | return 'view', path, link |
|---|
| | 233 | else: |
|---|
| | 234 | return 'search', file, None |
|---|
| | 235 | |
|---|
| | 236 | # Request for source file documentation. |
|---|
| | 237 | source_ext_re = '|'.join(self.source_ext.split(' ')) |
|---|
| | 238 | match = re.match(r'''^(.*)[.](%s)''' % source_ext_re, file) |
|---|
| | 239 | if match: |
|---|
| | 240 | basename, suffix = match.groups() |
|---|
| | 241 | basename = basename.replace('_', '__') |
|---|
| | 242 | path, link = lookup('%s_8%s.html' % (basename, suffix), 'source') |
|---|
| | 243 | if path: |
|---|
| | 244 | return 'view', path, link |
|---|
| | 245 | else: |
|---|
| | 246 | return 'search', file, None |
|---|
| | 247 | |
|---|
| | 248 | # Request for summary pages |
|---|
| | 249 | if file in self.SUMMARY_PAGES: |
|---|
| | 250 | path, link = lookup(file + '.html', 'summary') |
|---|
| | 251 | if path: |
|---|
| | 252 | return 'view', path, link |
|---|
| | 253 | |
|---|
| | 254 | # Request for a named object |
|---|
| | 255 | # TODO: |
|---|
| | 256 | # - do something about dirs |
|---|
| | 257 | # - expand with enum, defs, etc. |
|---|
| | 258 | # - this doesn't work well with the CREATE_SUBDIRS Doxygen option |
|---|
| | 259 | path, link = lookup('class%s.html' % file, 'class') |
|---|
| | 260 | if not path: |
|---|
| | 261 | path, link = lookup('struct%s.html' % file, 'struct') |
|---|
| | 262 | if path: |
|---|
| | 263 | return 'view', path, link |
|---|
| | 264 | |
|---|
| | 265 | # Revert to search... |
|---|
| | 266 | results = self._search_in_documentation(doc, [file]) |
|---|
| | 267 | class_ref = file+' Class Reference' |
|---|
| | 268 | for result in results: |
|---|
| | 269 | self.log.debug('Reverted to search, found: ' + repr(result)) |
|---|
| | 270 | name = result['name'] |
|---|
| | 271 | if name == file or name == class_ref: |
|---|
| | 272 | path, link = lookup(result['url']) |
|---|
| | 273 | return 'redirect', path, link |
|---|
| | 274 | self.log.debug('%s not found in %s' % (file, doc)) |
|---|
| | 275 | return 'search', file, None |
|---|
| | 276 | |
|---|