6
6
# Returns a list of unique firmware configurations for a given confname
7
7
# Call: list-used-firmwares.py <firmwares|platforms> confdir confname
8
8
9
+ # Returns the platform for a specific firmware:
10
+ # Call: list-used-firmwares.py platform-for <firmware>
11
+
12
+ # Map firmwares to platforms
13
+ pmap = {
14
+ "esp32-generic" : "esp32" ,
15
+ "lora-feather-m0" : "arm_none" ,
16
+ "lopy4-uart" : "esp32" ,
17
+ "lopy4" : "esp32" ,
18
+ "t-beam-uart" : "esp32" ,
19
+ "native-raspi" : "arm_linux" ,
20
+ }
21
+
9
22
def conf_path_to_obj (d ):
10
23
"""
11
24
Read configuration files from an input directory d into an object
@@ -18,43 +31,42 @@ def conf_path_to_obj(d):
18
31
configs [cfgname ] = c
19
32
return configs
20
33
21
- if sys .argv [1 ] not in ["firmwares" , "platforms" ]:
22
- print ("First parameter must be \" firmwares\" or \" platforms\" " )
23
- exit (1 )
34
+ if sys .argv [1 ] in ["firmwares" , "platforms" ]:
35
+
36
+ confdir = pathlib .Path (sys .argv [2 ])
37
+ hostconf = conf_path_to_obj (confdir / "hostconf" )[pathlib .Path (sys .argv [3 ]).stem ]
38
+ nodeconfs = conf_path_to_obj (confdir / "nodeconf" )
24
39
25
- confdir = pathlib .Path (sys .argv [2 ])
26
- hostconf = conf_path_to_obj (confdir / "hostconf" )[pathlib .Path (sys .argv [3 ]).stem ]
27
- nodeconfs = conf_path_to_obj (confdir / "nodeconf" )
28
-
29
- # Find all configs that are used
30
- used_nodeconfs = set ()
31
- for sec in hostconf .sections ():
32
- if "conf" in hostconf [sec ]:
33
- used_nodeconfs .add (hostconf [sec ]["conf" ])
34
- used_confs = map (lambda confname : nodeconfs [confname ],
35
- [pathlib .Path (c ).stem for c in used_nodeconfs ])
36
-
37
- # Find all firmwares
38
- used_firmwares = set ()
39
- for conf in used_confs :
40
- for sec in conf .sections ():
41
- if "firmware" in conf [sec ]:
42
- used_firmwares .add (conf [sec ]["firmware" ])
43
-
44
- if sys .argv [1 ] == "firmwares" :
45
- print (" " .join (used_firmwares ))
40
+ # Find all configs that are used
41
+ used_nodeconfs = set ()
42
+ for sec in hostconf .sections ():
43
+ if "conf" in hostconf [sec ]:
44
+ used_nodeconfs .add (hostconf [sec ]["conf" ])
45
+ used_confs = map (lambda confname : nodeconfs [confname ],
46
+ [pathlib .Path (c ).stem for c in used_nodeconfs ])
47
+
48
+ # Find all firmwares
49
+ used_firmwares = set ()
50
+ for conf in used_confs :
51
+ for sec in conf .sections ():
52
+ if "firmware" in conf [sec ]:
53
+ used_firmwares .add (conf [sec ]["firmware" ])
54
+
55
+ if sys .argv [1 ] == "firmwares" :
56
+ print (" " .join (used_firmwares ))
57
+ else :
58
+ used_platforms = set ()
59
+ for fw in used_firmwares :
60
+ if fw in pmap :
61
+ used_platforms .add (pmap [fw ])
62
+ print (" " .join (used_platforms ))
63
+ elif sys .argv [1 ] == "platform-for" :
64
+ if sys .argv [2 ] in pmap :
65
+ print (pmap [sys .argv [2 ]])
66
+ exit (0 )
67
+ else :
68
+ print ("unknown firmware:" , sys .argv [2 ], file = sys .stderr )
69
+ exit (1 )
46
70
else :
47
- # Map firmwares to platforms
48
- pmap = {
49
- "esp32-generic" : "esp32" ,
50
- "lora-feather-m0" : "arm_none" ,
51
- "lopy4-uart" : "esp32" ,
52
- "lopy4" : "esp32" ,
53
- "t-beam-uart" : "esp32" ,
54
- "native-raspi" : "arm_linux" ,
55
- }
56
- used_platforms = set ()
57
- for fw in used_firmwares :
58
- if fw in pmap :
59
- used_platforms .add (pmap [fw ])
60
- print (" " .join (used_platforms ))
71
+ print ("First parameter must be \" firmwares\" , \" platforms\" or \" platform-for\" ." )
72
+ exit (1 )
0 commit comments