Commit graph

31 commits

Author SHA1 Message Date
bfd0544ff8 Fix errors reported by mypy
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-10-13 12:45:51 +02:00
428692ea3a Streamline Python file headers somewhat
- 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>
2025-07-10 05:14:06 +02:00
b464f20e6c stree.StringTree.find(): Add method
StringTree.find(key, val) (and Config.find(), for that matter)
returns a list of paths with sections containing children matching
key / val pairs. One of them can be None, which acts as a wildcard.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-05-29 12:05:10 +02:00
a9fa274bb1 stree.StringTree: Add property path
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-05-29 12:04:52 +02:00
18117e4590 stree.StringTree: Add .parent and .root
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-05-20 13:09:58 +02:00
2bad14a891 stree.StringTree: Fix logging typo
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-05-16 06:52:22 +02:00
d30c41b03d stree.StringTree.py.__set(): Disable assert self.content != str(content)
There's an assertion in StringTree.py.__set(), assert self.content !=
str(content), which often triggers. Not sure what the idea behind the
assertion was, disable it.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-05-12 18:57:16 +02:00
64ce94b142 String Tree: Fix order of overwrites
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-01-28 07:18:50 +01:00
126ecbb411 StringTree: Beautify debug logging
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-01-28 05:08:50 +01:00
84a4053157 Add class Config
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-01-20 11:39:56 +01:00
24bfa0f806 stree/serdes: Support -include lines
Signed-off-by: Jan Lindemann <jan@janware.com>
2025-01-16 13:44:09 +01:00
57ff96608b StringTree.value(): Add keyword-argument default
Add argument default to StringTree.value(), defaulting to None, doing
the obvious.

Signed-off-by: Jan Lindemann <jan@janware.com>
2025-01-16 10:53:09 +01:00
3a7fb50979 Apply monkeytype traces
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>
2024-12-15 15:35:29 +01:00
3cd7926693 stree.parse(): Beautify debug logging
Signed-off-by: Jan Lindemann <jan@janware.com>
2024-10-06 17:13:41 +02:00
08045442e2 StringTree: Fix exception in child_list()
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>
2024-10-06 17:04:25 +02:00
85672d6cf3 StringTree.value(): Add optional path argument
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>
2020-04-18 08:38:34 +02:00
77d43aebad Add type annotations from monkeytype + jw-devops/test
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>
2020-04-10 17:55:36 +02:00
952bf4a4e1 Fix Python errors reported by mypy
This commit fixes Python errors and warnings reported by static type checking
with mypy.

Signed-off-by: Jan Lindemann <jan@janware.com>
2020-04-10 14:17:15 +02:00
fb6b205440 StringTree.__getitem__(): Return value child
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>
2020-04-05 14:23:59 +02:00
dc532704d0 StringTree: Add support for adding StringTree children
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>
2020-04-04 11:35:26 +02:00
dead9d9561 StringTree: add child_list()
Signed-off-by: Jan Lindemann <jan@janware.com>
2020-04-04 11:31:25 +02:00
160667b6a9 StringTree: Re-implement __str__()
Signed-off-by: Jan Lindemann <jan@janware.com>
2020-04-04 11:29:14 +02:00
020bb970bd stree/serdes.py: Add support for kwarg "root_content"
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>
2020-04-04 11:14:33 +02:00
1f122fae82 Rename the MODDIR makefile variable to JWBDIR
Rename the omnipresent MODDIR variable to JWBDIR, since that's more to the
point.

Signed-off-by: Jan Lindemann <jan@janware.com>
2019-06-29 23:32:20 +02:00
1c0c5ab884 Attempt to support parsing full lines into StringTree
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>
2019-05-19 13:15:27 +00:00
838ac06ebb Fix: StringTree misparsed key = "val # blah"
Signed-off-by: Jan Lindemann <jan@janware.com>
2017-11-26 21:25:01 +01:00
3d93d534db StringTree: Respect quoted quotes
Signed-off-by: Jan Lindemann <jan@janware.com>
2017-11-22 09:34:26 +01:00
5a87040e10 stree/serdes.py: Allow quoted = in rhs of assignment
Signed-off-by: Jan Lindemann <jan@janware.com>
2017-11-12 16:08:34 +01:00
7007c894b8 StringTree fix: Comments were not ignored in quotes
Signed-off-by: Jan Lindemann <jan@janware.com>
2017-11-05 16:35:41 +01:00
6ca2eeef61 StringTree parser: Add support for comments
Signed-off-by: Jan Lindemann <jan@janware.com>
2017-11-02 11:47:04 +01:00
214c222002 Add StringTree and friends
Signed-off-by: Jan Lindemann <jan@janware.com>
2017-11-01 13:26:10 +01:00