diff --git a/vcsserver/config/settings_maker.py b/vcsserver/config/settings_maker.py --- a/vcsserver/config/settings_maker.py +++ b/vcsserver/config/settings_maker.py @@ -25,6 +25,9 @@ import functools import logging import tempfile import logging.config + +from vcsserver.type_utils import str2bool, aslist + log = logging.getLogger(__name__) # skip keys, that are set here, so we don't double process those @@ -33,47 +36,6 @@ set_keys = { } -def str2bool(_str): - """ - returns True/False value from given string, it tries to translate the - string into boolean - - :param _str: string value to translate into boolean - :rtype: boolean - :returns: boolean from given string - """ - if _str is None: - return False - if _str in (True, False): - return _str - _str = str(_str).strip().lower() - return _str in ('t', 'true', 'y', 'yes', 'on', '1') - - -def aslist(obj, sep=None, strip=True): - """ - Returns given string separated by sep as list - - :param obj: - :param sep: - :param strip: - """ - if isinstance(obj, str): - if obj in ['', ""]: - return [] - - lst = obj.split(sep) - if strip: - lst = [v.strip() for v in lst] - return lst - elif isinstance(obj, (list, tuple)): - return obj - elif obj is None: - return [] - else: - return [obj] - - class SettingsMaker(object): def __init__(self, app_settings): diff --git a/vcsserver/type_utils.py b/vcsserver/type_utils.py new file mode 100644 --- /dev/null +++ b/vcsserver/type_utils.py @@ -0,0 +1,62 @@ +# RhodeCode VCSServer provides access to different vcs backends via network. +# Copyright (C) 2014-2020 RhodeCode GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + +import logging + +log = logging.getLogger(__name__) + + +def str2bool(str_): + """ + returns True/False value from given string, it tries to translate the + string into boolean + + :param str_: string value to translate into boolean + :rtype: boolean + :returns: boolean from given string + """ + if str_ is None: + return False + if str_ in (True, False): + return str_ + str_ = str(str_).strip().lower() + return str_ in ('t', 'true', 'y', 'yes', 'on', '1') + + +def aslist(obj, sep=None, strip=True) -> list: + """ + Returns given string separated by sep as list + + :param obj: + :param sep: + :param strip: + """ + if isinstance(obj, str): + if obj in ['', ""]: + return [] + + lst = obj.split(sep) + if strip: + lst = [v.strip() for v in lst] + return lst + elif isinstance(obj, (list, tuple)): + return obj + elif obj is None: + return [] + else: + return [obj] \ No newline at end of file