mirror of
https://github.com/nchevsky/systemrescue-zfs.git
synced 2026-04-04 22:07:30 +00:00
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.
This commit is contained in:
parent
53f49d8a33
commit
36dc530a50
2 changed files with 8 additions and 8 deletions
|
|
@ -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,))
|
||||
|
|
|
|||
|
|
@ -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,))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue