Render help content in a browser on a Posix-like system. This includes Linux and MacOS X.
| 259 | |
| 260 | |
| 261 | class PosixBrowserHelpRenderer(BrowserHelpRenderer): |
| 262 | """ |
| 263 | Render help content in a browser on a Posix-like system. This includes |
| 264 | Linux and MacOS X. |
| 265 | """ |
| 266 | |
| 267 | def _convert_doc_content(self, contents): |
| 268 | settings_overrides = self._DEFAULT_DOCUTILS_SETTINGS_OVERRIDES.copy() |
| 269 | settings_overrides["report_level"] = 3 |
| 270 | man_contents = publish_string( |
| 271 | contents, |
| 272 | writer=manpage.Writer(), |
| 273 | settings_overrides=self._DEFAULT_DOCUTILS_SETTINGS_OVERRIDES, |
| 274 | ) |
| 275 | if self._exists_on_path('groff'): |
| 276 | cmdline = ['groff', '-m', 'man', '-T', 'html'] |
| 277 | elif self._exists_on_path('mandoc'): |
| 278 | cmdline = ['mandoc', '-T', 'html'] |
| 279 | else: |
| 280 | raise ExecutableNotFoundError('groff or mandoc') |
| 281 | LOG.debug("Running command: %s", cmdline) |
| 282 | p3 = self._popen(cmdline, stdin=PIPE, stdout=PIPE, stderr=PIPE) |
| 283 | output = p3.communicate(input=man_contents)[0] |
| 284 | return output |
| 285 | |
| 286 | def _exists_on_path(self, name): |
| 287 | # Since we're only dealing with POSIX systems, we can |
| 288 | # ignore things like PATHEXT. |
| 289 | return any( |
| 290 | [ |
| 291 | os.path.exists(os.path.join(p, name)) |
| 292 | for p in os.environ.get('PATH', '').split(os.pathsep) |
| 293 | ] |
| 294 | ) |
| 295 | |
| 296 | |
| 297 | class WindowsPagingHelpRenderer(PagingHelpRenderer): |