Show More
@@ -23,6 +23,7 b' import functools' | |||||
23 | import logging |
|
23 | import logging | |
24 | import tempfile |
|
24 | import tempfile | |
25 | import logging.config |
|
25 | import logging.config | |
|
26 | ||||
26 | from rhodecode.lib.type_utils import str2bool, aslist |
|
27 | from rhodecode.lib.type_utils import str2bool, aslist | |
27 |
|
28 | |||
28 | log = logging.getLogger(__name__) |
|
29 | log = logging.getLogger(__name__) | |
@@ -34,13 +35,16 b' set_keys = {' | |||||
34 | } |
|
35 | } | |
35 |
|
36 | |||
36 |
|
37 | |||
37 |
class SettingsMaker |
|
38 | class SettingsMaker: | |
38 |
|
39 | |||
39 | def __init__(self, app_settings): |
|
40 | def __init__(self, app_settings): | |
40 | self.settings = app_settings |
|
41 | self.settings = app_settings | |
41 |
|
42 | |||
42 | @classmethod |
|
43 | @classmethod | |
43 | def _bool_func(cls, input_val): |
|
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 | return str2bool(input_val) |
|
48 | return str2bool(input_val) | |
45 |
|
49 | |||
46 | @classmethod |
|
50 | @classmethod | |
@@ -62,11 +66,24 b' class SettingsMaker(object):' | |||||
62 | return input_val |
|
66 | return input_val | |
63 |
|
67 | |||
64 | @classmethod |
|
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 | def _dir_func(cls, input_val, ensure_dir=False, mode=0o755): |
|
82 | def _dir_func(cls, input_val, ensure_dir=False, mode=0o755): | |
66 |
|
83 | |||
67 | # ensure we have our dir created |
|
84 | # ensure we have our dir created | |
68 | if not os.path.isdir(input_val) and ensure_dir: |
|
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 | if not os.path.isdir(input_val): |
|
88 | if not os.path.isdir(input_val): | |
72 | raise Exception(f'Dir at {input_val} does not exist') |
|
89 | raise Exception(f'Dir at {input_val} does not exist') | |
@@ -150,6 +167,7 b' class SettingsMaker(object):' | |||||
150 | 'list:newline': functools.partial(self._list_func, sep='/n'), |
|
167 | 'list:newline': functools.partial(self._list_func, sep='/n'), | |
151 | 'list:spacesep': functools.partial(self._list_func, sep=' '), |
|
168 | 'list:spacesep': functools.partial(self._list_func, sep=' '), | |
152 | 'string': functools.partial(self._string_func, lower=lower), |
|
169 | 'string': functools.partial(self._string_func, lower=lower), | |
|
170 | 'string:noquote': functools.partial(self._string_no_quote_func, lower=lower), | |||
153 | 'dir': self._dir_func, |
|
171 | 'dir': self._dir_func, | |
154 | 'dir:ensured': functools.partial(self._dir_func, ensure_dir=True), |
|
172 | 'dir:ensured': functools.partial(self._dir_func, ensure_dir=True), | |
155 | 'file': self._file_path_func, |
|
173 | 'file': self._file_path_func, |
@@ -167,3 +167,17 b' def convert_special_chars(str_) -> str:' | |||||
167 | value = safe_str(str_) |
|
167 | value = safe_str(str_) | |
168 | converted_value = unidecode(value) |
|
168 | converted_value = unidecode(value) | |
169 | return converted_value |
|
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