| 1 |
# -*- coding: UTF-8 -*- |
| 2 |
# |
| 3 |
# Bacula(R) - The Network Backup Solution |
| 4 |
# |
| 5 |
# Copyright (C) 2000-2022 Kern Sibbald |
| 6 |
# |
| 7 |
# The original author of Bacula is Kern Sibbald, with contributions |
| 8 |
# from many others, a complete list can be found in the file AUTHORS. |
| 9 |
# |
| 10 |
# You may use this file and others of this release according to the |
| 11 |
# license defined in the LICENSE file, which includes the Affero General |
| 12 |
# Public License, v3.0 ("AGPLv3") and some additional permissions and |
| 13 |
# terms pursuant to its AGPLv3 Section 7. |
| 14 |
# |
| 15 |
# This notice must be preserved when any source code is |
| 16 |
# conveyed and/or propagated. |
| 17 |
# |
| 18 |
# Bacula(R) is a registered trademark of Kern Sibbald. |
| 19 |
# |
| 20 |
# Copyright (c) 2020 by Inteos sp. z o.o. |
| 21 |
# All rights reserved. IP transfered to Bacula Systems according to agreement. |
| 22 |
# Author: Radosław Korzeniewski, [email protected], Inteos Sp. z o.o. |
| 23 |
# |
| 24 |
|
| 25 |
class BoolParam(object): |
| 26 |
|
| 27 |
@staticmethod |
| 28 |
def handleParam(param, _default = False): |
| 29 |
""" Function handles configuration bool parameter expressed in any known value. |
| 30 |
It handles string values like '1', 'Yes', etc. as True and '0', 'No', etc as False. |
| 31 |
|
| 32 |
Args: |
| 33 |
param (any): parameter value to process |
| 34 |
_default (bool, optional): use this value when parameter handling fail. Defaults to False. |
| 35 |
|
| 36 |
Returns: |
| 37 |
bool: return processed value |
| 38 |
""" |
| 39 |
if not isinstance(_default, bool): |
| 40 |
_default = False |
| 41 |
if param is not None: |
| 42 |
if isinstance(param, str): |
| 43 |
if param.lower() in ('1', 'yes', 'true'): |
| 44 |
return True |
| 45 |
if param.lower() in ('0', 'no', 'false'): |
| 46 |
return False |
| 47 |
if isinstance(param, int) or isinstance(param, bool) or isinstance(param, float): |
| 48 |
if param: |
| 49 |
return True |
| 50 |
else: |
| 51 |
return False |
| 52 |
# finally return default |
| 53 |
return _default |