debian-forge/osbuild
Achilleas Koutsou 94cdcecafb util: add new module for reading and writing toml
The toml module situation in Python is a bit of a mess.  Different
distro versions have different modules packaged or built-in, sometimes
with different capabilities (no writing).  Since we need to support
reading and writing toml files both on the host (osbuild internals,
sources, inputs) and in the build root (stages), let's centralise the
import decision making in an internal utility module that covers all
cases.

Two of the modules we might import (tomli and tomllib) don't support
writing, so we need to either import a separate module (tomli_w) or
raise an exception when dump() is called without a write-capable module.

The tomli and tomllib modules require files be opened in binary mode
(not text) while the others require text mode.  So we can't wrap the
toml.load() and toml.dump() functions directly; the caller doesn't know
which module it will be using.  Let's keep track of the mode based on
which import succeeded and have our functions open the files as needed.

The wrapper functions are named load_from_file() and dump_to_file() to
avoid confusion with the load() and dump() functions that take a file
object.

See also #1847
2024-08-21 19:26:31 +02:00
..
formats format/v2: add new "partition" field to "describe_mount" 2023-12-22 10:18:29 -05:00
solver solver/dnf5.py: fix depsolve MarkingErrors 2024-08-08 09:58:41 +02:00
testutil test: add new https_serve_directory() and test certs 2024-07-29 16:51:48 +02:00
util util: add new module for reading and writing toml 2024-08-21 19:26:31 +02:00
__init__.py Post release version bump 2024-08-21 17:07:31 +00:00
__main__.py osbuild: run isort on all files 2022-09-12 13:32:51 +02:00
api.py Fix errors reported by new version of mypy 2023-04-12 11:57:18 +02:00
buildroot.py osbuild: make the entire /etc/selinux avaialble for the buildroot 2024-03-22 11:24:35 +01:00
devices.py osbuild: error when {Device,Mount} is modified after creation 2024-01-19 02:54:26 +01:00
host.py tox: add tox 2023-08-01 15:01:13 +02:00
inputs.py osbuild: make inputs map() function use fd for reply as well 2024-08-13 13:13:24 +02:00
loop.py Revert "osbuild: ensure loop.Loop() has the required device node" 2024-03-13 22:16:51 +02:00
main_cli.py main,monitor: fix total steps in progress reporting 2024-07-31 23:00:33 +02:00
meta.py meta: automatically allow devices as input in the stages schemas 2024-04-16 08:04:43 +02:00
mixins.py osbuild: error when {Device,Mount} is modified after creation 2024-01-19 02:54:26 +01:00
monitor.py main,monitor: fix total steps in progress reporting 2024-07-31 23:00:33 +02:00
mounts.py mounts/ostree.deployment: support deployments on mount 2024-01-31 16:46:01 -05:00
objectstore.py objectstore: add new skip_preserve_owner to Object.export() 2023-12-20 09:28:39 +01:00
pipeline.py osbuild: add workaround to integrate sources into progress reporting 2024-03-12 16:44:12 +01:00
remoteloop.py osbuild: reuse loop_for_fd() in LoopServer 2024-03-11 10:56:49 +01:00
sources.py sources: transform() is only used in the curl sources, remove from ABC 2024-03-19 14:21:57 +01:00