priv-kweihmann / oelint-parser

alternative parser for bitbake recipes
BSD 2-Clause "Simplified" License
14 stars 10 forks source link

Can the parser write the parsed Bitbake file? #47

Open jetm opened 2 years ago

jetm commented 2 years ago

Is supported by the parser to change the parsed content and write it to the same conf file?

Something like https://docs.python.org/3/library/configparser.html does but for Bitbake files. I have read the documentation and source code without luck.

I have been using Shell scripting to change Bitbake configuration files, but it's a hacky and ugly way to do it.

priv-kweihmann commented 2 years ago

In theory that should be possible. The property you are looking for is https://github.com/priv-kweihmann/oelint-parser/blob/main/docs/api-documentation.md#oelint_parser.cls_item.Item.RealRaw, it should be available for every parsed item.

An example how to do it can be seen here https://github.com/priv-kweihmann/oelint-adv/blob/b9f8c5c8f02cb91909b97f40753343bdb176afdb/oelint_adv/rule_base/rule_var_section_lowercase.py#L29.

The difficult part might be reassembling the items in the correct order - oelint-adv does that here https://github.com/priv-kweihmann/oelint-adv/blob/b9f8c5c8f02cb91909b97f40753343bdb176afdb/oelint_adv/__main__.py#L319.

TBF I never tested the parser on conf files (their syntax seems to be a subset of the overall bitbake syntax), but I think that should be doable

priv-kweihmann commented 2 years ago

In case you succeed with that, I would welcome a tiny piece of documentation, as I guess other users would have the same question. So feel free to open a PR