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>
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>
Add support for adding children of type StringTree. If a StringTree
argument is passed to .add(), this should do the right thing. It
makes use of the newly added .__add_children() method and involves
quite a bit of hairy case distinctions.
Signed-off-by: Jan Lindemann <jan@janware.com>
parse() and read() up to present automatically set the root content
of a StringTree object to "root". This can now be optionally defined
by the "root_content" keyword argument.
Signed-off-by: Jan Lindemann <jan@janware.com>
- Add functions: append_to_prefix(),
remove_from_prefix() set_filename_length()
- Make slog_m() log one list item per line
- Add console_color_chars(prio)
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>
Add leading underscore to variables that should not be visible
outside of log.py. Also do some indentation beautification.
Signed-off-by: Jan Lindemann <jan@janware.com>
object_builtin_name() is meant to derive an object name from its
class name. Doesn't work well, but adding the code nonetheless for
improving it later.
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit flips some more switches from Python 2 to Python 3 in makefiles and
Python code. Build runs through, but it's still likely to break things.
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit tries to add support for the
[section]
first line
second line
syntax, i.e. non-assignments, without equal sign. Half-baked, but
still better than before. Also support some more Python 3, i.e.
dict.items() instead of iteritems()
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>
This replaces the mechanism to always construct lists with a leading
empty rule. This leads to many RR-conflicts, so this empty rule is omitted
and later added conditionally by grammar_fix_list_recursion(). Sadly,
the condition is bollocks, since it's always true.
Signed-off-by: Jan Lindemann <jan@janware.com>
- unroll_lists() sometimes introduced identical lists into a rule set
- unroll_options() sometimes chopped off a production's last rule
Signed-off-by: Jan Lindemann <jan@janware.com>
Add function grammar_add_configured_types() and keep configured types as
symbols as part of the grammar like all the others
Signed-off-by: Jan Lindemann <jan@janware.com>
Line numbers of parsed input are now automatically maintained. More
needed data structures are now automatically created in the API header
file.
Signed-off-by: Jan Lindemann <jan@janware.com>
First time parsing doesn't error out with a syntax error. No usable AST
is produced, strings are not returned from lexer, and AST lists aren't
lists, really.
TEXT:="Hello world!"; had to be excluded from the example, because I
don't get how this could be parsed with the given syntax. There's a
special sequence "all visible characters", but any lexer regex I could
think of will also match the types defining "alphabetic character" and
return the respective tokens (e.g. T_A) or vice-versa, depending on the
order in the lexer input file. I suppose, the only sensible way to
handle this, is to define "all visible characters" by defining the
tokens for the missing characters, and then use them along T_A ... T_Z
or their derived types.
Signed-off-by: Jan Lindemann <jan@janware.com>