An application based on Cmds will now try to read StringTree
formatted config data from a file $HOME/.<name>rc, and make the data
available via the newly added conf_value() method.
Signed-off-by: Jan Lindemann <jan@janware.com>
argcomplete takes the arguments added to argparse, and builds bash
completion with it. Add it to all Cmds based executables.
Signed-off-by: Jan Lindemann <jan@janware.com>
- Add coding statement
- Import all modules in one line where possible
- Order: __future__, typing, plain imports, from imports,
janware modules
Signed-off-by: Jan Lindemann <jan@janware.com>
WSGI doesn't like sys.exit() being called, so avoid it. Two cases
need to be taken into consideration:
1. No exception thrown by self.args.func()
The variable exit_status is zero, we can check that and _not_
call sys.exit()
2. Exception thrown by self.args.func()
In that case, the exception should be raised, to be caught by
WSGI / ASGI whatever to do what they want with it. The code
calling sys.exit() is never reached. Hence, we need to add
--backtrace to the invocation options.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add an option which makes the program write profiling statistics in pstats
format to a specified file.
Visualize e.g. with:
gprof2dot -f pstats <filename> -o <dotfile>
dot -Tpng | display <dotfile>
Signed-off-by: Jan Lindemann <jan@janware.com>
Wrap all execution in try-block, don't raise in except block unless
--backtrace is passed to the command line.
Signed-off-by: Jan Lindemann <jan@janware.com>
The parsed args container is passed to the run() function and friends
for convenient use. Sometimes, though, the base classes or umbrella
commands need to make use of it, too, even more so as they may define
command line arguments via add_arguments(). However, run() or _run()
or whatever is never called on them, neither any other callback, so
make args available to them as a member variable.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add type annotations as generated by monkeytype and jw-devops/test, plus some
hand editing to satisfy both monkeytype and mypy.
Signed-off-by: Jan Lindemann <jan@janware.com>
jwutils.Cmd.add_subcommands() had two issues. First, it failed for
more than one command, and with that fixed, it only added the first
command of a list of commands passed as an argument. This commit
fixes both issues and leaves some logging and cleanup in place, which
was used during debugging.
Signed-off-by: Jan Lindemann <jan@janware.com>
Cmds.cmds was sometimes empty, so fix that and make sure it points to
the Cmds instance it was crated by. Actually the name of the Cmds
class is a bad pick, should have been App or something, so to add
.app, too, as a path for future compatibility.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add method jwutils.Cmd.add_subcommands(). cmd.add_subcommands(C) will
parse and invoke C as a subcommand of cmd, if C is of type jwutils.cmd.
Signed-off-by: Jan Lindemann <jan@janware.com>
jwutils.log.set_flags() and .set_level() is not set until after all
commands are loaded. This can make debugging complicated. OTOH,
command-line parsing is also not done until all commands are loaded,
because they define the command line options. This commit adds some
poor man's command line parsing for fetching --log-level and
--log-flags only, and applying them before the commands are all
loaded.
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit makee Cmds run all sub-commands in an asyncio event loop.
The event loop is currently passed to the commands, which seems
unnecessary and looks like it's using a feature which is bound to be
deprecated in the future.
Signed-off-by: Jan Lindemann <jan@janware.com>
Changes in Python 3 that made the code choke:
o basestring is merged into str
o print() needs parentesis
o Class inheritance syntax changed
o Abstract baseclass (ABCMeta) syntax changed
o map.iteritems() is replaced by map.items()
o Inconsistent use of tabs and spaces are no longer tolerated
Signed-off-by: Jan Lindemann <jan@janware.com>
run_sub_commands() was the only way to access subcommands up to now,
Cmds.run() adds another interface, an object as a place to add
customizations affecting all commands, e.g. global command line
options.
Signed-off-by: Jan Lindemann <jan@janware.com>