1
1
import argparse
2
+ import json
2
3
from pathlib import Path
3
4
4
5
7
8
core_path = script_path .parent .parent
8
9
variant_path = core_path / "variants"
9
10
boards_entry_filename = "boards_entry.txt"
10
- output_filemane = script_path / "generic_boards_to_skip.json"
11
+ # Config files
12
+ conf_path = script_path / "conf"
13
+ cores_file = conf_path / "cores_config.json"
14
+ ci_file = conf_path / "cores_config_ci.json"
11
15
12
16
# Parser
13
17
parser = argparse .ArgumentParser (
14
18
description = "Generate list of generic boards to skip for ci core config"
15
19
)
16
20
17
21
22
+ def update_config (config_file , boards_list ):
23
+ if not config_file .is_file ():
24
+ print (f"{ config_file } not found!" )
25
+ exit (1 )
26
+ try :
27
+ config = open (config_file , "r" )
28
+ json_data = json .load (config )
29
+ config .close ()
30
+ # Update the values for generic boards
31
+ # First search correct value
32
+ core_index = - 1
33
+ sketch_index = - 1
34
+ for index , core in enumerate (json_data ["cores" ]):
35
+ if core ["architecture" ] == "stm32" :
36
+ core_index = index
37
+ for index2 , sketch in enumerate (core ["sketches" ]):
38
+ if sketch ["pattern" ] == "^.*$" :
39
+ sketch_index = index2
40
+ old_boards_list = json_data ["cores" ][core_index ]["sketches" ][sketch_index ][
41
+ "boards"
42
+ ]
43
+ old_boards_list = [x for x in old_boards_list if not x .startswith ("GENERIC_" )]
44
+ new_boards_list = old_boards_list + boards_list
45
+ new_boards_list .sort ()
46
+ json_data ["cores" ][core_index ]["sketches" ][index ]["boards" ] = new_boards_list
47
+ config = open (config_file , "w" )
48
+ config .write (json .dumps (json_data , indent = 2 ))
49
+ config .close ()
50
+ except IOError :
51
+ print (f"Failed to open { config_file } !" )
52
+
53
+
18
54
def main ():
19
55
# Get mcu_family directories
20
56
mcu_families = sorted (variant_path .glob ("STM32*/" ))
@@ -31,18 +67,12 @@ def main():
31
67
boards_list .append (line .partition ("=" )[- 1 ].strip ())
32
68
# Remove last board of the boards_entry to not skip it
33
69
boards_list .pop ()
34
- # Create file
35
- try :
36
- output_file = open (output_filemane , "w" , newline = "\n " )
37
- for count , board in enumerate (sorted (boards_list ), start = 1 ):
38
- if count % 4 == 0 :
39
- output_file .write (f'"{ board } ",\n ' )
40
- else :
41
- output_file .write (f'"{ board } ", ' )
42
- output_file .close ()
43
- except IOError :
44
- print (f"Failed to open { output_filemane } " )
45
- exit (1 )
70
+ boards_list .sort ()
71
+
72
+ # Update each config files
73
+ update_config (ci_file , boards_list )
74
+ update_config (cores_file , boards_list )
75
+
46
76
exit (0 )
47
77
48
78
0 commit comments