From 36dc530a50cc82e8378f8baa032198d44d160a0b Mon Sep 17 00:00:00 2001 From: "Gerd v. Egidy" Date: Sun, 22 May 2022 21:14:01 +0200 Subject: [PATCH] Properly cast floats to booleans in sysrescue-autorun and sysrescue-initialize.py When the lua script parses the YAML config, it converts a `1` to `1.0` because in lua all numbers are floats. So it writes out `1.0`, which is then loaded by the python scripts later. Make the type conversion for booleans aware of this. This allows to write something like `ar_disable: 1` in the YAML and have it acted upon as expected. --- airootfs/etc/systemd/scripts/sysrescue-autorun | 8 ++++---- airootfs/etc/systemd/scripts/sysrescue-initialize.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/airootfs/etc/systemd/scripts/sysrescue-autorun b/airootfs/etc/systemd/scripts/sysrescue-autorun index 960d0af..f9ee613 100755 --- a/airootfs/etc/systemd/scripts/sysrescue-autorun +++ b/airootfs/etc/systemd/scripts/sysrescue-autorun @@ -127,17 +127,17 @@ def search_autoruns(dirname, suffixes, copyfilefct): def strtobool (val): """Convert a string representation of truth to true (1) or false (0). - True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values - are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if + True values are 'y', 'yes', 't', 'true', 'on', '1', '1.0'; false values + are 'n', 'no', 'f', 'false', 'off', '0', '0.0'. Raises ValueError if 'val' is anything else. Function adapted from Pythons distutils.util.py because it will be deprecated soon Copyright (c) Python Software Foundation; All Rights Reserved """ val = str(val).lower() - if val in ('y', 'yes', 't', 'true', 'on', '1'): + if val in ('y', 'yes', 't', 'true', 'on', '1', '1.0'): return True - elif val in ('n', 'no', 'f', 'false', 'off', '0'): + elif val in ('n', 'no', 'f', 'false', 'off', '0', '0.0'): return False else: raise ValueError("invalid truth value %r" % (val,)) diff --git a/airootfs/etc/systemd/scripts/sysrescue-initialize.py b/airootfs/etc/systemd/scripts/sysrescue-initialize.py index cba4984..4941ea9 100755 --- a/airootfs/etc/systemd/scripts/sysrescue-initialize.py +++ b/airootfs/etc/systemd/scripts/sysrescue-initialize.py @@ -34,17 +34,17 @@ def symlink_overwrite(target, link_file): def strtobool (val): """Convert a string representation of truth to true (1) or false (0). - True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values - are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if + True values are 'y', 'yes', 't', 'true', 'on', '1', '1.0'; false values + are 'n', 'no', 'f', 'false', 'off', '0', '0.0'. Raises ValueError if 'val' is anything else. Function adapted from Pythons distutils.util.py because it will be deprecated soon Copyright (c) Python Software Foundation; All Rights Reserved """ val = str(val).lower() - if val in ('y', 'yes', 't', 'true', 'on', '1'): + if val in ('y', 'yes', 't', 'true', 'on', '1', '1.0'): return True - elif val in ('n', 'no', 'f', 'false', 'off', '0'): + elif val in ('n', 'no', 'f', 'false', 'off', '0', '0.0'): return False else: raise ValueError("invalid truth value %r" % (val,))