##// END OF EJS Templates
chore(sync-up): synced libs/settings maker from vcsserver
super-admin -
r5337:363e5238 default
parent child Browse files
Show More
@@ -23,6 +23,7 b' import functools'
23 23 import logging
24 24 import tempfile
25 25 import logging.config
26
26 27 from rhodecode.lib.type_utils import str2bool, aslist
27 28
28 29 log = logging.getLogger(__name__)
@@ -34,13 +35,16 b' set_keys = {'
34 35 }
35 36
36 37
37 class SettingsMaker(object):
38 class SettingsMaker:
38 39
39 40 def __init__(self, app_settings):
40 41 self.settings = app_settings
41 42
42 43 @classmethod
43 44 def _bool_func(cls, input_val):
45 if isinstance(input_val, bytes):
46 # decode to str
47 input_val = input_val.decode('utf8')
44 48 return str2bool(input_val)
45 49
46 50 @classmethod
@@ -62,11 +66,24 b' class SettingsMaker(object):'
62 66 return input_val
63 67
64 68 @classmethod
69 def _string_no_quote_func(cls, input_val, lower=True):
70 """
71 Special case string function that detects if value is set to empty quote string
72 e.g.
73
74 core.binar_dir = ""
75 """
76
77 input_val = cls._string_func(input_val, lower=lower)
78 if input_val in ['""', "''"]:
79 return ''
80
81 @classmethod
65 82 def _dir_func(cls, input_val, ensure_dir=False, mode=0o755):
66 83
67 84 # ensure we have our dir created
68 85 if not os.path.isdir(input_val) and ensure_dir:
69 os.makedirs(input_val, mode=mode)
86 os.makedirs(input_val, mode=mode, exist_ok=True)
70 87
71 88 if not os.path.isdir(input_val):
72 89 raise Exception(f'Dir at {input_val} does not exist')
@@ -150,6 +167,7 b' class SettingsMaker(object):'
150 167 'list:newline': functools.partial(self._list_func, sep='/n'),
151 168 'list:spacesep': functools.partial(self._list_func, sep=' '),
152 169 'string': functools.partial(self._string_func, lower=lower),
170 'string:noquote': functools.partial(self._string_no_quote_func, lower=lower),
153 171 'dir': self._dir_func,
154 172 'dir:ensured': functools.partial(self._dir_func, ensure_dir=True),
155 173 'file': self._file_path_func,
@@ -167,3 +167,17 b' def convert_special_chars(str_) -> str:'
167 167 value = safe_str(str_)
168 168 converted_value = unidecode(value)
169 169 return converted_value
170
171
172 def splitnewlines(text: bytes):
173 """
174 like splitlines, but only split on newlines.
175 """
176
177 lines = [_l + b'\n' for _l in text.split(b'\n')]
178 if lines:
179 if lines[-1] == b'\n':
180 lines.pop()
181 else:
182 lines[-1] = lines[-1][:-1]
183 return lines
General Comments 0
You need to be logged in to leave comments. Login now