Acute 0.2.2 – Integrate Help Commands to Single Interface – pydoc3, puppet describe and man in GoldenDict

Access all documentation commands and dictionaries trough a single interface.
Acute(1) suppresses output if it’s just “documentation not found”, so your interface stays clean.
With GoldenDict and acute, you can see real time queries to help commands along offline programmer’s dictionaries and regular dictionaries.
By using ‘grep’ as a command, you can quickly add any one-thing-per-line as a dictionary.

Configure GoldenDict

Save acute to a text file, give execute permission and copy it to /usr/local/bin/acute. You can find acute source code at the end of the page.

$ nano acute  # copy-paste, ctrl-X y enter
$ chmod ugo+x acute
$ sudo cp acute /usr/local/bin/acute

Add commands to GoldenDict. Here are some examples for Python 3, manual pages and Puppet.
In GoldenDict: Edit: Dictionaries: Programs

acute -d -f "^No Python documentation " pydoc3 "%GDWORD%"
acute puppet help "%GDWORD%"
acute -f "^Unknown type" puppet describe "%GDWORD%"
acute man "%GDWORD%"
acute apt-cache show "%GDWORD%"
acute grep -C 2 "%GDWORD%" /home/tero/botbook-commands.txt

Acute 0.2.2 – run command, discard output if it fails

Yes, you can almost nail it in a one-liner. Almost. After edge cases, help, proper argument parsing… it’s a program.

"""acute - run command, discard output if it fails
Copyright 2017 Tero Karvinen GPL 3 or later
Use for querying multiple external sources, without error messages
cluttering output. For example, GoldenDict: Dictionaries: Programs.
$ acute -d man bash		# prints manpage of bash
This prints nothing:
$ acute -v --fail-string '^No Python documentation found' pydoc3 asdf
This prints Python documentation for re.sub:
$ acute -v --fail-string '^No Python documentation found' pydoc3 re.sub
More examples:
$ acute -d -f '^Unknown type' puppet describe file
__copyright__ = "Copyright 2017 Tero Karvinen"
__license__ = "GNU General Public License, version 3 or later"
__version__ = "0.2.2"
import argparse
import textwrap
from logging import basicConfig, info, debug, warning, error, INFO, DEBUG, WARNING
import subprocess
import os
import sys
import re
def parseArgs():
	parser = argparse.ArgumentParser(fromfile_prefix_chars="@",
		description=__doc__, epilog="acute "+__version__+"\n"+__copyright__,
	parser.add_argument("command", nargs=argparse.REMAINDER)
	parser.add_argument("-f", "--fail-string",
		help="Discard output and consider command failed if output\n"
			"contains FAIL_STRING. Regular expressions allowed, and \n"
			"it's commont to start with line start mark '^'. ")
	parser.add_argument("-v", "--verbose", action="store_const",
		dest="log_level", const=INFO, default=WARNING)
	parser.add_argument("-d", "--debug", action="store_const",
		dest="log_level", const=DEBUG)
	args = parser.parse_args()
	args.command = " ".join(args.command)
	if "" == args.command:
		parser.error("External command can't be empty.")
	return args
def main():
	args = parseArgs()
	logformat = "%(funcName)s():%(lineno)i: %(message)s %(levelname)s"
	basicConfig(level=args.log_level, format=logformat)
	info("Running: '%s'", args.command)
	(status, out) = subprocess.getstatusoutput(args.command)
	debug("Status: %i, Output start: %s" % (status, out[:20].replace('\n', '\\n')))
	if status != os.EX_OK:
		info("Failed status returned by external command. Exiting...")
	if args.fail_string and re.match(args.fail_string, out):
		info("Fail string in command output. Exiting...")
	except (BrokenPipeError):
		info("Broken pipe caused error to acute, e.g. 'head' terminated reading of output. ")
	except (IOError):
		info("External command '%s' had IO error because of broken pipe, e.g. 'head'. ", args.command)
if __name__ == "__main__":
Posted in Uncategorized | Comments Off on Acute 0.2.2 – Integrate Help Commands to Single Interface – pydoc3, puppet describe and man in GoldenDict

Comments are closed.