comparison configmix/__init__.py @ 273:9733aaa261ac

FIX: for PY2: test with the Unicode string variant when checking for "<dir>" prefixes
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 03 Oct 2020 10:52:15 +0200
parents e73884fe060b
children 90bbade12d8e
comparison
equal deleted inserted replaced
272:fc4c38f931cb 273:9733aaa261ac
11 """ 11 """
12 12
13 from __future__ import division, print_function, absolute_import 13 from __future__ import division, print_function, absolute_import
14 14
15 15
16 __version__ = "0.10" 16 __version__ = "0.10.1.dev1"
17 17
18 __revision__ = "|VCSRevision|" 18 __revision__ = "|VCSRevision|"
19 __date__ = "|VCSJustDate|" 19 __date__ = "|VCSJustDate|"
20 20
21 __all__ = ["load", "safe_load", 21 __all__ = ["load", "safe_load",
39 u("__comment"), 39 u("__comment"),
40 u("__doc"), 40 u("__doc"),
41 ] 41 ]
42 """Prefixes for comment configuration keys that are to be handled as 42 """Prefixes for comment configuration keys that are to be handled as
43 comments 43 comments
44
45 """
46
47 DIR_PREFIX = u("<dir>")
48 """Prefix for configuration values to read other configuration files from
49 given directory
44 50
45 """ 51 """
46 52
47 53
48 def load(*files, **kwargs): 54 def load(*files, **kwargs):
72 if defaults is None: 78 if defaults is None:
73 ex = Configuration() 79 ex = Configuration()
74 else: 80 else:
75 ex = merge(None, Configuration(defaults)) 81 ex = merge(None, Configuration(defaults))
76 for f in files: 82 for f in files:
77 if f.startswith("<dir>"): 83 if f.startswith(DIR_PREFIX):
78 for f2 in _get_configuration_files_from_dir(f[5:]): 84 for f2 in _get_configuration_files_from_dir(f[5:]):
79 nx = _load_cfg_from_file(f2, ignore_unknown=True) 85 nx = _load_cfg_from_file(f2, ignore_unknown=True)
80 if nx is not None: 86 if nx is not None:
81 ex = merge(nx, ex) 87 ex = merge(nx, ex)
82 else: 88 else:
98 if defaults is None: 104 if defaults is None:
99 ex = Configuration() 105 ex = Configuration()
100 else: 106 else:
101 ex = safe_merge(None, Configuration(defaults)) 107 ex = safe_merge(None, Configuration(defaults))
102 for f in files: 108 for f in files:
103 if f.startswith("<dir>"): 109 if f.startswith(DIR_PREFIX):
104 for f2 in _get_configuration_files_from_dir(f[5:]): 110 for f2 in _get_configuration_files_from_dir(f[5:]):
105 nx = _load_cfg_from_file(f2, ignore_unknown=True) 111 nx = _load_cfg_from_file(f2, ignore_unknown=True)
106 if nx is not None: 112 if nx is not None:
107 ex = safe_merge(nx, ex) 113 ex = safe_merge(nx, ex)
108 else: 114 else: