[cli/models/utils] Move strtobool into legendary utils

Fixes deprecation warning on Python 3.10+
This commit is contained in:
derrod 2021-12-28 17:37:26 +01:00
parent 1fd8acdee4
commit b6cb31df8b
3 changed files with 21 additions and 3 deletions

View file

@ -12,7 +12,6 @@ import time
import webbrowser import webbrowser
from collections import defaultdict, namedtuple from collections import defaultdict, namedtuple
from distutils.util import strtobool
from logging.handlers import QueueListener from logging.handlers import QueueListener
from multiprocessing import freeze_support, Queue as MPQueue from multiprocessing import freeze_support, Queue as MPQueue
from platform import platform from platform import platform
@ -22,7 +21,7 @@ from legendary import __version__, __codename__
from legendary.core import LegendaryCore from legendary.core import LegendaryCore
from legendary.models.exceptions import InvalidCredentialsError from legendary.models.exceptions import InvalidCredentialsError
from legendary.models.game import SaveGameStatus, VerifyResult, Game from legendary.models.game import SaveGameStatus, VerifyResult, Game
from legendary.utils.cli import get_boolean_choice, sdl_prompt from legendary.utils.cli import get_boolean_choice, sdl_prompt, strtobool
from legendary.utils.custom_parser import AliasedSubParsersAction from legendary.utils.custom_parser import AliasedSubParsersAction
from legendary.utils.env import is_windows_mac_or_pyi from legendary.utils.env import is_windows_mac_or_pyi
from legendary.utils.lfs import validate_files from legendary.utils.lfs import validate_files

View file

@ -1,7 +1,7 @@
from copy import deepcopy from copy import deepcopy
from distutils.util import strtobool
from legendary.models.game import InstalledGame, Game from legendary.models.game import InstalledGame, Game
from legendary.utils.cli import strtobool
_template = { _template = {

View file

@ -40,3 +40,22 @@ def sdl_prompt(sdl_data, title):
print('Invalid tag:', c) print('Invalid tag:', c)
return tags return tags
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
'val' is anything else.
Copied from python standard library as distutils.util.strtobool is deprecated.
"""
val = val.lower()
if val in ('y', 'yes', 't', 'true', 'on', '1'):
return 1
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
return 0
else:
raise ValueError("invalid truth value %r" % (val,))