|
| 1 | +#! /usr/bin/env python |
| 2 | +""" |
| 3 | +mbed SDK |
| 4 | +Copyright (c) 2019 ARM Limited |
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License. |
| 14 | +LIBRARIES BUILD |
| 15 | +""" |
| 16 | + |
| 17 | +# Script to automatically update the configuration parameters list in |
| 18 | +# each configuration doc page with the output from `mbed compile --config -v` |
| 19 | +# for the page's appropriate prefix. |
| 20 | +# |
| 21 | +# By default, when run from the check_tools directory, the script runs |
| 22 | +# through each Markdown file in `docs/reference/configuration/`. An |
| 23 | +# 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. |
| 25 | +# |
| 26 | +# Note that you need to run this with a local copy of whichever version of |
| 27 | +# Mbed OS you wish to update the configuration parameters with. |
| 28 | +# |
| 29 | +# You can run this script with: |
| 30 | +# python config-update.py <OPTIONAL FILE/DIR PATH> |
| 31 | + |
1 | 32 | import sys, os
|
2 | 33 | import re
|
3 | 34 | import subprocess
|
4 | 35 |
|
5 | 36 | def split_into_pairs(l):
|
| 37 | + """ Split the provided list into a, b pairs. |
| 38 | + [1, 2, 3, 4] -> [[1, 2], [3, 4]] |
| 39 | + Args: |
| 40 | + l - list of values to be split |
| 41 | +
|
| 42 | + Returns: |
| 43 | + List of split pairs |
| 44 | + """ |
6 | 45 | for i in range(0, len(l), 2):
|
7 | 46 | yield l[i:i + 2]
|
8 | 47 |
|
9 | 48 | def main(file):
|
10 | 49 | file_h = open(file, 'r+')
|
11 | 50 | file = file_h.read()
|
| 51 | + |
| 52 | + # Collect indices of markdown code block ticks, split into start,end pairs |
| 53 | + # with `split_into_pairs` below. Collect the config parameter prefix used in |
| 54 | + # the current block if viable and replace the contents with the output of |
| 55 | + # the Mbed CLI config verbose list command. |
12 | 56 | snippet_indices = [m.start() for m in re.finditer('```', file)]
|
13 | 57 |
|
14 | 58 | blocks = {}
|
|
0 commit comments