refuse_mode_mask can be passed to the constructor and determines
which permission bits need to be absent from config file modes if
they smell like they contain secrets.
Signed-off-by: Jan Lindemann <jan@janware.com>
Make Config's ctor accept strings as values for glob_paths, as
opposed to lists. This covers the canonical case of one configuration
file being passed.
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>
Initializing Config from a StringTree object doesn't stop it from
looking for config files to read. Stop that.
Signed-off-by: Jan Lindemann <jan@janware.com>
Run
monkeytype run jw-acc.py --log-level debug db import --format mdb-json-dir dbs
monkeytype list-modules | grep ^jw | while read m; do
monkeytype apply $m
done
and fix the fallout.
Signed-off-by: Jan Lindemann <jan@janware.com>
child_list() throws an exception saying that <str> has no to_list()
method. No, it hasn't. No idea how this has even worked at all, ever.
Signed-off-by: Jan Lindemann <jan@janware.com>
Fix mypy warning
jwutils/log.py:209: error: Incompatible types in assignment
(expression has type int, variable has type Literal[5])
Signed-off-by: Jan Lindemann <jan@janware.com>
Add only_printable keyword argument to slog(). It defaults to False.
If it's true, non-printable characters are not logged but replaced
with a printable character.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add misc.dump(), which takes an iterable, assumes all elements have a
dump() method, and calls it on all of them.
Signed-off-by: Jan Lindemann <jan@janware.com>
In addition to an integer, a string can now be passed, which allows
prefix = ' | '
append_to_prefix(prefix)
slog(INFO, "something")
remove_from_prefix(prefx)
Signed-off-by: Jan Lindemann <jan@janware.com>
As opposed to the C++ variant, StringTree.value() doesn't take a path
argument, but only returns the value of the node it's called on.
Change this. Returns None if the path is not found.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add multi_key_dict.py from https://github.com/formiaczek/multi_key_dict
It uses an MIT license, the Copyright notice should be added to this
project's documentation.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add a kwargs keyword argument. This should allow a kwargs containing
a "caller=" argument to be passed to the function and just do the
right thing. Badly tested.
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>
commit_tmpfile() is a better os.rename which doesn't do anything if
source and target files are equal, and logs if does something.
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>
get_derived_classes(mod, baseclass) returns a list of class
definitions from a module which are subclasses of baseclass.
Signed-off-by: Jan Lindemann <jan@janware.com>
StringTree.__getitem__() returned the node, now return its value
child instead. That's nicer and closer to the expected behaviour, as
it supports StringTree usage as a key-value store for configuration
or so. It breaks the existing API, but I think I have fixed the only
pace where it was used: jw-grammar/grammar.py.
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>