/org.osbuild.systemd.unit*: Don't use interpolation with ConfigParser

Its not uncommon for systemd unit key values to contain things like
"%t", as these are magic values expanded by systemd. We need to
disable the ConfigParser default interpolation that treats '%' as
meaning interpolation.

Otherwise you will get errors like:

```
  File "/run/osbuild/bin/org.osbuild.systemd.unit.create", line 66, in <module>
    r = main(args["tree"], args["options"])
  File "/run/osbuild/bin/org.osbuild.systemd.unit.create", line 46, in main
    config.set(section, option, str(value))
  File "/usr/lib64/python3.9/configparser.py", line 1204, in set
    super().set(section, option, value)
  File "/usr/lib64/python3.9/configparser.py", line 894, in set
    value = self._interpolation.before_set(self, section, option,
  File "/usr/lib64/python3.9/configparser.py", line 402, in before_set
    raise ValueError("invalid interpolation syntax in %r at "
ValueError: invalid interpolation syntax in '%t/asil-ipc-demo/asil_ipc.socket' at position 0
```
This commit is contained in:
Alexander Larsson 2024-09-17 11:41:49 +02:00 committed by Simon de Vlieger
parent 657c42bb0d
commit af3c70fb40
2 changed files with 2 additions and 2 deletions

View file

@ -24,7 +24,7 @@ def main(tree, options):
# We trick configparser into letting us write multiple instances of the same option by writing them as keys with no
# value, so we enable allow_no_value
config = configparser.ConfigParser(allow_no_value=True)
config = configparser.ConfigParser(allow_no_value=True, interpolation=None)
# prevent conversion of the option name to lowercase
config.optionxform = lambda option: option

View file

@ -28,7 +28,7 @@ def main(tree, options):
# We trick configparser into letting us write multiple instances of the same option by writing them as keys with no
# value, so we enable allow_no_value
config = configparser.ConfigParser(allow_no_value=True)
config = configparser.ConfigParser(allow_no_value=True, interpolation=None)
# prevent conversion of the option name to lowercase
config.optionxform = lambda option: option