arg_bool.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # coding:utf-8
  2. #!/usr/bin/python
  3. #
  4. # Copyright (c) Contributors to the Open 3D Engine Project.
  5. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. #
  7. # SPDX-License-Identifier: Apache-2.0 OR MIT
  8. #
  9. #
  10. # -------------------------------------------------------------------------
  11. """! @brief
  12. Module Documentation:
  13. <DCCsi>/azpy/shared/utils/arg_bool.py
  14. Contains a util for working with bools in argparse cli modules.
  15. """
  16. # -------------------------------------------------------------------------
  17. # standard imports
  18. import logging as _logging
  19. # -------------------------------------------------------------------------
  20. # -------------------------------------------------------------------------
  21. # global scope
  22. _MODULENAME = 'azpy.shared.utils.arg_bool'
  23. _LOGGER = _logging.getLogger(_MODULENAME)
  24. _LOGGER.debug(f'Initializing: {_MODULENAME}')
  25. # -------------------------------------------------------------------------
  26. # -------------------------------------------------------------------------
  27. def arg_bool(bool_arg, desc='arg desc not set'):
  28. """cast a arg bool to a python bool"""
  29. _LOGGER.debug(f"Checking '{desc}': {bool_arg}")
  30. if bool_arg in ('True', 'true', '1'):
  31. return True
  32. elif bool_arg in ('False', 'false', '0'):
  33. return False
  34. else:
  35. return bool_arg
  36. # -------------------------------------------------------------------------