comparison contrib/check-config.py @ 32848:485b8e87e244

check-config: use named groups in regexp In preparation for making this regexp a bit more complicated.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 15 Jun 2017 10:38:19 -0700
parents e5a6a540ae63
children e9fc5550be46
comparison
equal deleted inserted replaced
32847:e5a6a540ae63 32848:485b8e87e244
14 foundopts = {} 14 foundopts = {}
15 documented = {} 15 documented = {}
16 16
17 configre = re.compile(r''' 17 configre = re.compile(r'''
18 # Function call 18 # Function call
19 ui\.config(|int|bool|list)\( 19 ui\.config(?P<ctype>|int|bool|list)\(
20 # First argument. 20 # First argument.
21 ['"](\S+)['"],\s* 21 ['"](?P<section>\S+)['"],\s*
22 # Second argument 22 # Second argument
23 ['"](\S+)['"](,\s+ 23 ['"](?P<option>\S+)['"](,\s+
24 (?:default=)?(\S+?))? 24 (?:default=)?(?P<default>\S+?))?
25 \)''', re.VERBOSE | re.MULTILINE) 25 \)''', re.VERBOSE | re.MULTILINE)
26 26
27 configpartialre = (r"""ui\.config""") 27 configpartialre = (r"""ui\.config""")
28 28
29 def main(args): 29 def main(args):
79 79
80 # look for code-like bits 80 # look for code-like bits
81 line = carryover + l 81 line = carryover + l
82 m = configre.search(line) 82 m = configre.search(line)
83 if m: 83 if m:
84 ctype = m.group(1) 84 ctype = m.group('ctype')
85 if not ctype: 85 if not ctype:
86 ctype = 'str' 86 ctype = 'str'
87 name = m.group(2) + "." + m.group(3) 87 name = m.group('section') + "." + m.group('option')
88 default = m.group(5) 88 default = m.group('default')
89 if default in (None, 'False', 'None', '0', '[]', '""', "''"): 89 if default in (None, 'False', 'None', '0', '[]', '""', "''"):
90 default = '' 90 default = ''
91 if re.match('[a-z.]+$', default): 91 if re.match('[a-z.]+$', default):
92 default = '<variable>' 92 default = '<variable>'
93 if name in foundopts and (ctype, default) != foundopts[name]: 93 if name in foundopts and (ctype, default) != foundopts[name]: