Statistics
| Branch: | Tag: | Revision:

root / scripts / generate-layouts-menu.py @ 5d47c801

History | View | Annotate | Download (3.34 KB)

1
#!/usr/bin/env python3
2
from os import makedirs
3
from subprocess import Popen, PIPE
4
import yaml
5
import hardware_description
6

    
7
def spawn(arg):
8
        p = Popen(arg, shell=True, stdout=PIPE, stderr=PIPE)
9
        return p.communicate()[0]
10

    
11
def find(param):
12
        return spawn("find " + param).decode("utf-8").strip().split("\n")
13

    
14
makedirs("generated/hardware", exist_ok=True)
15

    
16
hwConfigIn = open("generated/hardware/Config.in.hardware", 'wt')
17
layoutConfigIn = open("generated/hardware/Config.in.layouts", 'wt')
18

    
19
hwConfigIn.write("choice\n")
20
hwConfigIn.write("\tprompt \"Hardware\"\n")
21
hwConfigIn.write("\thelp\n")
22
hwConfigIn.write("\t\tSelect your hardware here.\n\n\n")
23

    
24
hw_description_files = find("hardware -name hw.yaml")
25

    
26
for hw_file in hw_description_files:
27
        try:
28
                hwd = yaml.load(open(hw_file, 'r'))
29
        except yaml.YAMLError as exc:
30
                print("Error in HardwareDescription file: ") + exc
31

    
32
        hwConfigIn.write("config " + str.upper(hwd.name) + "\n")
33
        hwConfigIn.write("\tbool \"" + hwd.name + "\"\n")
34
        hwConfigIn.write("\thelp\n")
35
        for line in hwd.helptext.strip().split("\n"):
36
                hwConfigIn.write("\t\t" + line + "\n")
37

    
38
        # add deps:
39
        # FIXME check the deps names
40
        for dep in hwd.depends:
41
                hwConfigIn.write("\tselect " + str.upper(dep) + "\n")
42
        hwConfigIn.write("\n\n")
43
        
44
        hwConfigIn.write("config HEADER_PATH\n")
45

    
46
        hwConfigIn.write("\tdefault \"" + hw_file.rstrip("hw.yaml") + "hw.h\" if " + str.upper(hwd.name) + "\n")
47
        hwConfigIn.write("\n")
48

    
49
        # generate layout / mix menu for the hardware entry
50
        layoutConfigIn.write("if " + str.upper(hwd.name) + "\n")
51
        for i in range(0,len(hwd.layouts)):
52
                layoutConfigIn.write("config " + str.upper(hwd.name + "_LAYOUT_" + str(i)) + "\n")
53
                layoutConfigIn.write("\tstring\n\n")
54

    
55
                layoutConfigIn.write("config " + str.upper(hwd.name + "_LAYOUT_" + str(i) + "_SET") + "\n")
56
                layoutConfigIn.write("\tbool\n")
57
                layoutConfigIn.write("\tdefault n\n\n")
58

    
59
                if i > 0:
60
                        layoutConfigIn.write("if " + str.upper(hwd.name + "_LAYOUT_" + str(i-1) + "_SET") + "\n")
61
                layoutConfigIn.write("choice\n")
62
                layoutConfigIn.write("\tprompt \"Layout " + str(i) + "\"\n\n")
63
                
64
                # add "none" entry
65
                layoutConfigIn.write("config " + str.upper(hwd.name + "_LAYOUT_NONE_" + str(i)) + "\n")
66
                layoutConfigIn.write("\tbool \"none\"\n")
67

    
68
                for layout in hwd.layouts:
69
                        layoutname, layers = next(iter(layout.items()))
70
#                        # block already choosen layouts FIXME it's broken
71
#                        layoutConfigIn.write("if !(")
72
#                        for j in range(0,len(hwd.layouts)):
73
#                                if j != i:
74
#                                        layoutConfigIn.write(str.upper(hwd.name + "_LAYOUT_" + layoutname + "_" + str(j)) + " ")
75
#                                if ((j != len(hwd.layouts)-1) and (j != 0)):
76
#                                        layoutConfigIn.write("||")
77
#                        layoutConfigIn.write(")\n");
78
                        layoutConfigIn.write("config " + str.upper(hwd.name + "_LAYOUT_" + layoutname + "_" + str(i)) + "\n")
79
                        layoutConfigIn.write("\tbool \"" + layoutname + "\"\n")
80
                        layoutConfigIn.write("\tselect " + str.upper(hwd.name + "_LAYOUT_" + str(i) + "_SET") + "\n")
81
                        layoutConfigIn.write("config " + str.upper(hwd.name + "_LAYOUT_" + str(i)) + "\n")
82
                        layoutConfigIn.write("\tdefault \"" + layoutname + "\" if " + str.upper(hwd.name + "_LAYOUT_" + layoutname + "_" + str(i)) + "\n")
83
#                        layoutConfigIn.write("endif\n") # belongs to block already choosen layouts
84
                
85
                # FIXME add mixer
86
                layoutConfigIn.write("endchoice\n\n")
87
                if i > 0:
88
                        layoutConfigIn.write("endif\n")
89
        layoutConfigIn.write("endif\n")
90
hwConfigIn.write("endchoice\n")
91
hwConfigIn.close()