Add a command-line option providing information about tools.
- All tools have a url. - Not deriving the url from the package database.
This commit is contained in:
parent
332666ec43
commit
e60bde2a84
5 changed files with 58 additions and 29 deletions
|
|
@ -48,8 +48,8 @@ There is a wrapper script available to make running easier:
|
|||
|
||||
Extensions(98) | Tools(60)
|
||||
----------:| -----
|
||||
.* | [contents](http://pygments.org/) • metadata • [git_blame](https://git-scm.com/docs/git-blame) • [git_log](https://git-scm.com/docs/git-log)
|
||||
.py | [python_syntax](https://en.wikipedia.org/wiki/Python_syntax_and_semantics) • [python_unittests](https://docs.python.org/3/library/unittest.html) • [pytest](https://docs.pytest.org/en/latest/) • [pydoc](https://docs.python.org/3/library/pydoc.html) • [mypy](http://mypy-lang.org/) • [python_coverage](https://coverage.readthedocs.io/) • [pycodestyle](http://pycodestyle.pycqa.org/en/latest/) • [pydocstyle](http://www.pydocstyle.org/en/2.1.1/usage.html) • [pyflakes](https://pypi.org/project/pyflakes/) • [pylint](https://www.pylint.org/) • [python_gut](https://github.com/ahamilton/eris/blob/master/gut.py) • [python_modulefinder](https://docs.python.org/3/library/modulefinder.html) • [dis](https://docs.python.org/3/library/dis.html) • [python_mccabe](https://pypi.org/project/mccabe/) • [bandit](https://pypi.org/project/bandit/)
|
||||
.* | [contents](http://pygments.org/) • [metadata](https://github.com/ahamilton/eris) • [git_blame](https://git-scm.com/docs/git-blame) • [git_log](https://git-scm.com/docs/git-log)
|
||||
.py | [python_syntax](https://en.wikipedia.org/wiki/Python_syntax_and_semantics) • [python_unittests](https://docs.python.org/3/library/unittest.html) • [pytest](https://docs.pytest.org/en/latest/) • [pydoc](https://docs.python.org/3/library/pydoc.html) • [mypy](http://mypy-lang.org/) • [python_coverage](https://coverage.readthedocs.io/) • [pycodestyle](http://pycodestyle.pycqa.org/en/latest/) • [pydocstyle](http://www.pydocstyle.org/en/2.1.1/usage.html) • [pyflakes](https://pypi.org/project/pyflakes/) • [pylint](https://www.pylint.org/) • [python_gut](https://github.com/ahamilton/eris) • [python_modulefinder](https://docs.python.org/3/library/modulefinder.html) • [dis](https://docs.python.org/3/library/dis.html) • [python_mccabe](https://pypi.org/project/mccabe/) • [bandit](https://pypi.org/project/bandit/)
|
||||
.pl .pm .t | [perl_syntax](https://en.wikipedia.org/wiki/Perl) • [perldoc](http://perldoc.perl.org/)
|
||||
.p6 .pm6 | [perl6_syntax](https://rakudo.org/)
|
||||
.pod .pod6 | [perldoc](http://perldoc.perl.org/)
|
||||
|
|
@ -63,7 +63,7 @@ Extensions(98) | Tools(60)
|
|||
.bash .sh .dash .ksh | [shellcheck](https://www.shellcheck.net/)
|
||||
.wasm | [wasm_validate](https://github.com/WebAssembly/wabt) • [wasm_objdump](https://github.com/WebAssembly/wabt)
|
||||
.pdf | [pdf2txt](https://github.com/pdfminer/pdfminer.six)
|
||||
.html .htm | [html_syntax](http://www.html-tidy.org/) • [html2text](http://www.mbayer.de/html2text/) • [elinks](http://elinks.cz/)
|
||||
.html .htm | [html_syntax](https://www.html-tidy.org/) • [html2text](http://www.mbayer.de/html2text/) • [elinks](http://elinks.cz/)
|
||||
.yaml .yml | [yamllint](https://github.com/adrienverge/yamllint)
|
||||
.md .epub .docx .odt .rst | [pandoc](https://pandoc.org/)
|
||||
.zip .jar .apk .egg .whl | [zipinfo](http://www.info-zip.org/UnZip.html)
|
||||
|
|
|
|||
|
|
@ -51,12 +51,14 @@ USAGE = """
|
|||
Usage:
|
||||
eris [options] <directory>
|
||||
eris -h | --help
|
||||
eris -i | --info
|
||||
|
||||
Example:
|
||||
# eris my_project
|
||||
|
||||
Options:
|
||||
-h, --help Show the full help.
|
||||
-i, --info Show information about the available tools.
|
||||
-w COUNT, --workers=COUNT The number of processes working in parallel.
|
||||
By default it is the number of cpus minus 1.
|
||||
-e "COMMAND", --editor="COMMAND" The command used to start the editor, in
|
||||
|
|
@ -1195,12 +1197,37 @@ def manage_cache(root_path):
|
|||
open(timestamp_path, "w").close()
|
||||
|
||||
|
||||
def print_tool_info():
|
||||
extensions_for_tool = {}
|
||||
for extensions, tools_ in tools.TOOLS_FOR_EXTENSIONS:
|
||||
for extension in extensions:
|
||||
for tool in tools_:
|
||||
extensions_for_tool.setdefault(
|
||||
tool, {extension}).add(extension)
|
||||
for tool in sorted(tools.tools_all(), key=lambda t: t.__name__):
|
||||
print(termstr.TermStr(tool.__name__).bold())
|
||||
print("url:", tool.url)
|
||||
extensions = list(extensions_for_tool.get(tool, {"*"}))
|
||||
print("extensions:", ", ".join(extensions))
|
||||
if hasattr(tool, "command"):
|
||||
print(f"command: {tool.command} foo.{extensions[0]}")
|
||||
else:
|
||||
print("function:", "tools." + tool.__name__)
|
||||
available = ("yes" if tools.is_tool_available(tool) else
|
||||
termstr.TermStr("no").fg_color(termstr.Color.red))
|
||||
print("available:", available)
|
||||
print()
|
||||
|
||||
|
||||
def check_arguments():
|
||||
cmdline_help = __doc__ + USAGE.replace("*", "")
|
||||
arguments = docopt.docopt(cmdline_help, help=False)
|
||||
if arguments["--help"]:
|
||||
print(cmdline_help)
|
||||
sys.exit(0)
|
||||
if arguments["--info"]:
|
||||
print_tool_info()
|
||||
sys.exit(0)
|
||||
worker_count = None
|
||||
try:
|
||||
if arguments["--workers"] is not None:
|
||||
|
|
|
|||
|
|
@ -190,7 +190,8 @@ def _pretty_bytes(bytes):
|
|||
return f"{conversion} {units[unit_index]}"
|
||||
|
||||
|
||||
@deps(deps={"file", "coreutils"}, executables={"file"})
|
||||
@deps(deps={"file", "coreutils"}, url="https://github.com/ahamilton/eris",
|
||||
executables={"file"})
|
||||
def metadata(path):
|
||||
|
||||
def detail(value, unit):
|
||||
|
|
@ -237,7 +238,7 @@ def metadata(path):
|
|||
return (Status.normal, fill3.join("", text))
|
||||
|
||||
|
||||
@deps(deps={"pip/pygments"}, url="python3-pygments")
|
||||
@deps(deps={"pip/pygments"}, url="http://pygments.org/")
|
||||
def contents(path):
|
||||
with open(path) as file_:
|
||||
try:
|
||||
|
|
@ -333,7 +334,7 @@ def python_coverage(path):
|
|||
return status, _colorize_coverage_report(lines)
|
||||
|
||||
|
||||
@deps(url="https://github.com/ahamilton/eris/blob/master/gut.py")
|
||||
@deps(url="https://github.com/ahamilton/eris")
|
||||
def python_gut(path):
|
||||
with open(path) as module_file:
|
||||
output = gut.gut_module(module_file.read())
|
||||
|
|
@ -379,7 +380,7 @@ def perltidy(path):
|
|||
return Status.normal, _syntax_highlight_using_path(stdout, path)
|
||||
|
||||
|
||||
@deps(deps={"tidy"}, url="tidy", executables={"tidy"})
|
||||
@deps(deps={"tidy"}, url="https://www.html-tidy.org/", executables={"tidy"})
|
||||
def html_syntax(path):
|
||||
# Stop tidy from modifiying input path by piping in input.
|
||||
tidy_process = subprocess.run(f"cat {shlex.quote(path)} | tidy",
|
||||
|
|
@ -388,7 +389,7 @@ def html_syntax(path):
|
|||
return status, _fix_input(tidy_process.stderr)
|
||||
|
||||
|
||||
@deps(deps={"pandoc"}, url="pandoc", executables={"pandoc"})
|
||||
@deps(deps={"pandoc"}, url="https://pandoc.org/", executables={"pandoc"})
|
||||
def pandoc(path):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
temp_path = os.path.join(temp_dir, "temp.html")
|
||||
|
|
@ -458,14 +459,15 @@ def make_tool_function(dependencies, command, url=None, success_status=None,
|
|||
error_status=None, has_color=False, timeout=None):
|
||||
if url is None:
|
||||
url = dependencies[0]
|
||||
command = command.split()
|
||||
executables = set([command[0]])
|
||||
command_parts = command.split()
|
||||
executables = set([command_parts[0]])
|
||||
success_status = None if success_status is None else Status[success_status]
|
||||
error_status = None if error_status is None else Status[error_status]
|
||||
@deps(deps=set(dependencies), url=url, executables=executables)
|
||||
def func(path):
|
||||
return _run_command(command + [path], success_status, error_status,
|
||||
has_color, timeout)
|
||||
return _run_command(command_parts + [path], success_status,
|
||||
error_status, has_color, timeout)
|
||||
func.command = command
|
||||
return func
|
||||
|
||||
|
||||
|
|
@ -750,20 +752,6 @@ def tool_name_colored(tool, path):
|
|||
return termstr.TermStr(tool.__name__, char_style)
|
||||
|
||||
|
||||
@functools.lru_cache()
|
||||
def get_homepage_of_package(package):
|
||||
line = subprocess.getoutput(f"dpkg-query --status {package}|grep Homepage")
|
||||
return line.split()[1]
|
||||
|
||||
|
||||
def url_of_tool(tool):
|
||||
try:
|
||||
url = tool.url
|
||||
return url if url.startswith("http") else get_homepage_of_package(url)
|
||||
except AttributeError:
|
||||
return None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
tool_name, path = sys.argv[1:3]
|
||||
tool = locals()[tool_name]
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ tools_for_extensions = [
|
|||
|
||||
[zipinfo]
|
||||
dependencies = ["unzip"]
|
||||
url = "http://www.info-zip.org/UnZip.html"
|
||||
command = "zipinfo"
|
||||
success_status = "normal"
|
||||
|
||||
|
|
@ -172,31 +173,37 @@ tools_for_extensions = [
|
|||
|
||||
[unrar]
|
||||
dependencies = ["unrar"]
|
||||
url = "http://www.rarlabs.com/"
|
||||
command = "unrar l"
|
||||
success_status = "normal"
|
||||
|
||||
[7z]
|
||||
dependencies = ["p7zip"]
|
||||
url = "http://p7zip.sourceforge.net/"
|
||||
command = "7zr l"
|
||||
success_status = "normal"
|
||||
|
||||
[unxz]
|
||||
dependencies = ["xz-utils"]
|
||||
url = "https://tukaani.org/xz/"
|
||||
command = "unxz --list"
|
||||
success_status = "normal"
|
||||
|
||||
[dpkg_contents]
|
||||
dependencies = ["dpkg"]
|
||||
url = "https://wiki.debian.org/Teams/Dpkg"
|
||||
command = "dpkg --contents"
|
||||
success_status = "normal"
|
||||
|
||||
[dpkg_info]
|
||||
dependencies = ["dpkg"]
|
||||
url = "https://wiki.debian.org/Teams/Dpkg"
|
||||
command = "dpkg --info"
|
||||
success_status = "normal"
|
||||
|
||||
[rpm]
|
||||
dependencies = ["rpm"]
|
||||
url = "http://rpm.org/"
|
||||
command = "rpm --query --list"
|
||||
success_status = "normal"
|
||||
|
||||
|
|
@ -220,11 +227,13 @@ tools_for_extensions = [
|
|||
|
||||
[html2text]
|
||||
dependencies = ["html2text"]
|
||||
url = "http://www.mbayer.de/html2text/"
|
||||
command = "html2text"
|
||||
success_status = "normal"
|
||||
|
||||
[elinks]
|
||||
dependencies = ["elinks"]
|
||||
url = "http://elinks.cz/"
|
||||
command = "elinks -dump-color-mode 1 -dump -no-numbering -no-references"
|
||||
success_status = "normal"
|
||||
has_color = true
|
||||
|
|
@ -254,23 +263,28 @@ tools_for_extensions = [
|
|||
|
||||
[shellcheck]
|
||||
dependencies = ["shellcheck"]
|
||||
url = "https://www.shellcheck.net/"
|
||||
command = "shellcheck --color=always"
|
||||
has_color = true
|
||||
|
||||
[cppcheck]
|
||||
dependencies = ["cppcheck"]
|
||||
url = "http://sourceforge.net/p/cppcheck/wiki/Home/"
|
||||
command = "cppcheck"
|
||||
|
||||
[ruby_syntax]
|
||||
dependencies = ["ruby2.5"]
|
||||
url = "http://www.ruby-lang.org/"
|
||||
command = "ruby -c"
|
||||
|
||||
[lua_syntax]
|
||||
dependencies = ["lua5.3"]
|
||||
url = "http://www.lua.org"
|
||||
command = "luac -p"
|
||||
|
||||
[js_syntax]
|
||||
dependencies = ["nodejs"]
|
||||
url = "http://nodejs.org/"
|
||||
command = "node --check"
|
||||
|
||||
[lua_check]
|
||||
|
|
@ -308,6 +322,7 @@ tools_for_extensions = [
|
|||
|
||||
[mediainfo]
|
||||
dependencies = ["mediainfo"]
|
||||
url = "https://mediaarea.net/MediaInfo"
|
||||
command = "mediainfo"
|
||||
success_status = "normal"
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ import eris.tools as tools
|
|||
|
||||
|
||||
def tool_markup(tool):
|
||||
url = tools.url_of_tool(tool)
|
||||
return (tool.__name__ if url is None else f"[{tool.__name__}]({url})")
|
||||
return f"[{tool.__name__}]({tool.url})"
|
||||
|
||||
|
||||
def main():
|
||||
|
|
@ -76,7 +75,7 @@ Extensions({len(extension_set)-1}) | Tools({len(tool_set)})
|
|||
for extensions, tools_ in all_tools:
|
||||
print("%s | %s" % (
|
||||
" ".join("." + extension for extension in extensions),
|
||||
" • ".join(tool_markup(tool) for tool in tools_)))
|
||||
" • ".join(f"[{tool.__name__}]({tool.url})" for tool in tools_)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue