2 from xml.etree import cElementTree as ET
8 # map XML attributes/elements to SQL rows
9 # --POC: iterate through the children and attributes of the memberdef element
10 # and search it in doxygen_sqlite3.db
14 def print_unprocessed_attributes(node):
15 for key in node.attrib:
16 print("WARNING: '%s' has unprocessed attr '%s'" % (node.tag,key))
18 def extract_attribute(node,attribute,pnl):
19 if not attribute in node.attrib:
21 pnl.append("%s = ?" % attribute)
22 val.append(node.attrib[attribute])
23 node.attrib.pop(attribute)
25 def extract_element(node,chld,pnl):
28 if len(chld.attrib)==0:
34 pnl.append("%s =?" % chld.tag)
35 val.append(chld.text.strip())
37 pnl.append("%s IS NULL OR %s = ''" % (chld.tag,chld.tag))
40 def process_memberdef(node):
42 for chld in node.getchildren():
43 if chld.tag == "referencedby":
45 if chld.tag == "references":
47 if chld.tag == "param":
49 if chld.tag == "type":
51 if chld.tag == "location":
52 extract_attribute(chld,"line",q)
53 extract_attribute(chld,"column",q)
54 extract_attribute(chld,"bodystart",q)
55 extract_attribute(chld,"bodyend",q)
57 q.append("id_bodyfile=(select id from files where name=?)")
58 val.append(chld.attrib["bodyfile"])
59 chld.attrib.pop("bodyfile")
61 q.append("id_file=(select id from files where name=?)")
62 val.append(chld.attrib["file"])
63 chld.attrib.pop("file")
65 print_unprocessed_attributes(chld)
66 if len(chld.attrib) == 0:
69 extract_element(node,chld,q)
71 for chld in node.getchildren():
72 print("WARNING: '%s' has unprocessed child elem '%s'" % (node.tag,chld.tag))
74 extract_attribute(node,"kind",q)
75 extract_attribute(node,"prot",q)
76 extract_attribute(node,"static",q)
77 extract_attribute(node,"mutable",q)
78 extract_attribute(node,"const",q)
79 extract_attribute(node,"virt",q)
80 extract_attribute(node,"explicit",q)
81 extract_attribute(node,"inline",q)
84 val.append(node.attrib['id'])
87 print_unprocessed_attributes(node)
89 query="SELECT * FROM memberdef WHERE %s" % " AND ".join(q)
92 r = g_conn.execute(query,val).fetchall()
93 except(sqlite3.OperationalError,e):
94 print("SQL_ERROR:%s"%e)
98 print("TEST_ERROR: Member not found in SQL DB")
102 context = ET.iterparse(name, events=("start", "end"))
103 event, root = context.next()
104 for event, elem in context:
105 if event == "end" and elem.tag == "memberdef":
106 process_memberdef(elem)
107 print("\n== Unprocessed XML ==")
115 dbname = "doxygen_sqlite3.db"
117 if not os.path.isfile(dbname):
118 raise BaseException("No such file %s" % dbname )
120 g_conn = sqlite3.connect(dbname)
121 g_conn.execute('PRAGMA temp_store = MEMORY;')
122 g_conn.row_factory = sqlite3.Row
126 opts, args = getopt.getopt(argv, "hd:x:",["help"])
127 except getopt.GetoptError:
134 if a in ('-h', '--help'):
145 if __name__ == '__main__':