[ambctl] removed build realic that should never have been added
[profile/ivi/automotive-message-broker.git] / tools / genmapping.py
1 #!/usr/bin/python
2
3 import os
4 import argparse
5
6 parser = argparse.ArgumentParser(description='Process DBus mappings.')
7 parser.add_argument('mappingFiles', metavar='N', nargs='+',
8                         help='dbus headers to find mappings in')
9 parser.add_argument('--output', dest='output',
10                         help='output file to write idl to')
11 args = parser.parse_args()
12 print "parsing"
13 print args.mappingFiles
14
15 interfaces = []
16
17 class Member:
18                 ambName = ""
19                 memberName = ""
20                 interfaceName = ""
21                 def __init__(self, ifaceName):
22                         self.interfaceName = ifaceName
23                 def __repr__(self):
24                         return "Member"
25                 def toString(self):
26                         return "{" + self.ambName + " => " + self.memberName + "}"
27                 def toIdl(self):
28                         idl = []
29                         idl.append('')
30                         idl.append('\t/*!')
31                         idl.append('\t * \\brief corresponds with DBus property ' + self.memberName + ' for interface org.automotive.' + self.interfaceName)
32                         idl.append('\t * AMB fulfills this member with VehicleProperty::' + self.ambName)
33                         idl.append('\t */')
34                         idl.append('\tconst DOMString ' + self.ambName + ' = "' + self.memberName + '";\n')
35                         return '\n'.join(idl)
36
37 class Interface:
38                 def __init__(self):
39                         self.name = ""
40                         self.members = []
41                 def __repr__(self):
42                         return "Interface('" + name + "')"
43                 def toString(self):
44                         output = self.name + ":"
45                         for member in self.members:
46                                 output += member.toString() + ","
47                         return output
48                 def toIdl(self):
49                         output = "/*! \n * \\brief Corresponds with DBus Interface org.automotive." + self.name + "\n */\ninterface " + self.name + " {\n"
50                         for member in self.members:
51                                 output += member.toIdl()
52                         output += "\n};\n"
53                         return output
54
55 for input in args.mappingFiles:
56         try: file = open(input)
57         except IOError:
58                         print "Failed to open " + input
59         with file:
60                         for line in file:
61                                         i = line.find("DBusSink(\"");
62                                         if i != -1:
63                                                         interface = Interface()
64                                                         ifaceNameBeg = line.find('("')
65                                                         ifaceNameEnd = line.find('",')
66                                                         interface.name = line[ifaceNameBeg+2 : ifaceNameEnd]
67                                                         interfaces.append(interface)
68                                         wantPropertyVariant = 'wantPropertyVariant('
69                                         i = line.find(wantPropertyVariant)
70                                         if i!= -1:
71                                                         member = Member(interfaces[-1].name)
72                                                         ambNameEnd = line.find(', "')-2
73                                                         member.ambName = line[i+len(wantPropertyVariant) : i + ambNameEnd].replace("VehicleProperty::", "")
74                                                         memberNameBeg = line.find(', "')+3
75                                                         memberNameEnd = line.find('",')
76                                                         member.memberName = line[memberNameBeg : memberNameEnd]
77                                                         interfaces[-1].members.append(member)
78                         file.close()
79
80 try: outputFile = open(args.output, 'w')
81 except IOError:
82                 print "Error could not open output file: " + args.output
83 with outputFile:
84         header =("/*!\n"
85                 " * \\name AMB to AMB-DBus Mapping Tables\n"
86                 " * \\file " + os.path.basename(args.output) + "\n"
87                 " * \\brief This describes the AMB internal property names to AMB DBus interface property names\n"
88                 " * AMB internal property names are designed to be flat variable names (ie, 'ConvertableRoofStatus').  The DBus\n"
89                 " * properties however follow the naming scheme defined in the W3C automotive business group vehicle <a href='http://w3c.github.io/automotive-bg/data_spec.html'>data specification</a>\n"
90                 " * The pattern each interface is 'const DOMString AMBProperty = DBusProperty' where 'AMBProperty' is the internal name and 'DBusProperty' is the DBus property name.\n"
91                 " *\n"
92                 " * For documentation on the interface and members, please see the \ref dbus_api.\n")
93         header += " */\n\n"
94         outputFile.write(header)
95         for iface in interfaces:
96                 outputFile.write(iface.toIdl())
97                 outputFile.write("\n")
98         outputFile.close()
99
100
101