Skip to content

Commit 5ac7a6f

Browse files
committed
Add tag feature to allow splitting of parameter lists
1 parent 3fdcf92 commit 5ac7a6f

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

check_tools/config-update.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# By default, when run from the check_tools directory, the script runs
2222
# through each Markdown file in `docs/reference/configuration/`. An
2323
# optional file or directory path may be passed in a parameter to run the
24-
# script on a specific file or directroy outside the default path.
24+
# script on a specific file or directroy outside the default path.
2525
#
2626
# Note that you need to run this with a local copy of whichever version of
2727
# Mbed OS you wish to update the configuration parameters with.
@@ -45,6 +45,21 @@ def split_into_pairs(l):
4545
for i in range(0, len(l), 2):
4646
yield l[i:i + 2]
4747

48+
def is_string(line):
49+
""" Determine if the provided string contains
50+
alphabetical characters (case insensitive)
51+
Args:
52+
line - string to scan
53+
54+
Returns:
55+
True if the string contains [a-z], else False
56+
"""
57+
regexp = re.compile(r'[a-z]', re.IGNORECASE)
58+
if regexp.search(line):
59+
return True
60+
else:
61+
return False
62+
4863
def main(file):
4964
file_h = open(file, 'r+')
5065
file = file_h.read()
@@ -69,7 +84,44 @@ def main(file):
6984
lib = blocks[i].split('Name: ')[1].split('.')[0]
7085
print("================= %s =================" % lib)
7186
out = str(subprocess.check_output(["mbed", "compile", "--config", "-v", "--prefix", lib]))
72-
file = file[:start+4] + out[:out.index("Macros") - 1] + file[end:]
87+
88+
# Some APIs break config optioins into logical blocks in their config files.
89+
# If a tag is applied to a parameter block, only display parameter names that contains that tag
90+
# For example:
91+
# ```heap
92+
# mbed-mesh-api.heap-size
93+
# ...
94+
# mbed-mesh-api.heap-stat-info
95+
# ..
96+
# ......
97+
# ```
98+
#
99+
# On encountering a block with tag, collect the common parameter token
100+
# and split the configuration list output into its components.
101+
# Collect tag (if present), split <TAG> from ```<TAG> at current index
102+
# Check with regex for string to cover for potential trailing whitespaces
103+
tag = file[start : file.find('\n', start)].split('`')[-1]
104+
if is_string(tag):
105+
print("\t------- Tag: %s -------" % tag)
106+
107+
start_of_config_block = file.find('Name:', start)
108+
updated_config = str(file[ : start_of_config_block]) # + "Configuration parameters\n------------------------\n")
109+
for line in out.splitlines():
110+
if 'Name' in line and tag in line:
111+
updated_config += line
112+
113+
# Collect all text until next parameter name. If there's no following 'Name:' token, its the last
114+
# config option, match to 'Macros' instead to termiante the block
115+
if out.find('Name:', out.find(line) + 4) > 0:
116+
updated_config += out[out.find('\n', out.find(line)) : out.find('Name:', out.find(line) + 4)]
117+
else:
118+
updated_config += out[out.find('\n', out.find(line)) : out.find('Macros', out.find(line) + 4)]
119+
120+
updated_config += str(file[end:])
121+
else:
122+
updated_config = str(file[:start+4] + out[:out.index("Macros") - 1] + file[end:])
123+
124+
file = updated_config
73125

74126
# Originally added for debugging purposes, catch and display exceptions before
75127
# continuing without exiting to provide a complete list of errors found

0 commit comments

Comments
 (0)