Files
clang-p2996/cross-project-tests/debuginfo-tests/dexter/dex/tools/help/Tool.py
Tobias Hieta f98ee40f4b [NFC][Py Reformat] Reformat python files in the rest of the dirs
This is an ongoing series of commits that are reformatting our
Python code. This catches the last of the python files to
reformat. Since they where so few I bunched them together.

Reformatting is done with `black`.

If you end up having problems merging this commit because you
have made changes to a python file, the best way to handle that
is to run git checkout --ours <yourfile> and then reformat it
with black.

If you run into any problems, post to discourse about it and
we will try to help.

RFC Thread below:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: jhenderson, #libc, Mordante, sivachandra

Differential Revision: https://reviews.llvm.org/D150784
2023-05-25 11:17:05 +02:00

59 lines
2.0 KiB
Python

# DExTer : Debugging Experience Tester
# ~~~~~~ ~ ~~ ~ ~~
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""Help tool."""
import imp
import textwrap
from dex.tools import ToolBase, get_tool_names, get_tools_directory, tool_main
from dex.utils.ReturnCode import ReturnCode
class Tool(ToolBase):
"""Provides help info on subtools."""
@property
def name(self):
return "DExTer help"
@property
def _visible_tool_names(self):
return [t for t in get_tool_names() if not t.endswith("-")]
def add_tool_arguments(self, parser, defaults):
parser.description = Tool.__doc__
parser.add_argument(
"tool", choices=self._visible_tool_names, nargs="?", help="name of subtool"
)
def handle_options(self, defaults):
pass
@property
def _default_text(self):
s = "\n<b>The following subtools are available:</>\n\n"
tools_directory = get_tools_directory()
for tool_name in sorted(self._visible_tool_names):
internal_name = tool_name.replace("-", "_")
module_info = imp.find_module(internal_name, [tools_directory])
tool_doc = imp.load_module(internal_name, *module_info).Tool.__doc__
tool_doc = tool_doc.strip() if tool_doc else ""
tool_doc = textwrap.fill(" ".join(tool_doc.split()), 80)
s += "<g>{}</>\n{}\n\n".format(tool_name, tool_doc)
return s
def go(self) -> ReturnCode:
if self.context.options.tool is None:
self.context.o.auto(self._default_text)
return ReturnCode.OK
tool_name = self.context.options.tool.replace("-", "_")
tools_directory = get_tools_directory()
module_info = imp.find_module(tool_name, [tools_directory])
module = imp.load_module(tool_name, *module_info)
return tool_main(self.context, module.Tool(self.context), ["--help"])