cambalache-db: add gtk type extra data

Add common Gtk type extra data.
This commit is contained in:
Juan Pablo Ugarte 2021-06-15 19:11:17 -03:00
parent 13807c69ac
commit e3125d79a7
3 changed files with 125 additions and 10 deletions

20
TODO.md
View File

@ -36,22 +36,22 @@
- GtkWidget
- <style> <class name="css-class"/> </style>
- <action-widgets>
<action-widget response="cancel">cancel_info_dialog</action-widget>
</action-widgets>
- <action-widgets>
<action-widget response="">value</action-widget>
</action-widgets>
- GtkListStore
- <columns> <column type=""/> </columns>
- <data> <row> <col id="0">value</col> </row> </data>
- <columns> <column type="gtype"/> </columns>
- <data> <row> <col id="int">value</col> </row> </data>
- GtkTreeStore
- <columns> <column type=""/> </columns>
- <columns> <column type="gtype"/> </columns>
- GtkCellRendererText
- <attributes> <attribute name="text">0</attribute> </attributes>
- GtkLabel
- <attributes> <attribute name="gchararray" value="red" start="5" end="10">int</attribute> </attributes>
- GtkLevelBar
- <offsets> <offset name="low" value="1"/> </offsets>
- <offsets> <offset name="gchararray" value="1"/> </offsets>
- GtkScale
- <marks> <mark value="0" position="bottom"> </mark>
@ -60,4 +60,4 @@
- <items> <item>1</item> </items>
- GtkSizeGroup
- <widgets> <widget name="listboxrow1"/> </widgets>
- <widgets> <widget name="gchararray"/> </widgets>

67
tools/Gtk.xml Normal file
View File

@ -0,0 +1,67 @@
<!--
CambalacheDB - Data Model for Cambalache
Copyright (C) 2021 Juan Pablo Ugarte - All Rights Reserved
Unauthorized copying of this file, via any medium is strictly prohibited.
-->
<types>
<GtkWidget>
<style>
<class name="gchararray"/>
</style>
</GtkWidget>
<GtkDialog>
<action-widgets>
<action-widget response="gint">GtkWidget</action-widget>
</action-widgets>
</GtkDialog>
<GtkListStore>
<columns>
<column type="type"/>
</columns>
<data>
<row>
<col id="gint">gchararray</col>
</row>
</data>
</GtkListStore>
<GtkTreeStore>
<columns>
<column type="type"/>
</columns>
</GtkTreeStore>
<GtkLabel>
<attributes>
<attribute name="gchararray" value="gchararray" start="gint" end="gint"/>
</attributes>
</GtkLabel>
<GtkLevelBar>
<offsets>
<offset name="gchararray" value="gdouble"/>
</offsets>
</GtkLevelBar>
<GtkScale>
<marks>
<mark value="gdouble" position="GtkPositionType">gchararray</mark>
</marks>
</GtkScale>
<GtkComboBoxText>
<items>
<item id="gchararray">gchararray</item>
</items>
</GtkComboBoxText>
<GtkSizeGroup>
<widgets>
<widget name="GtkWidget"/>
</widgets>
</GtkSizeGroup>
</types>

View File

@ -9,6 +9,7 @@
import os
import sys
import sqlite3
from lxml import etree
from utils import gir
@ -89,6 +90,47 @@ class CambalacheDb:
self.conn.commit()
return lib
def _import_tag(self, c, node, owner_id, parent_id):
key = node.tag
if node.text:
text = node.text.strip()
type_id = None if text == '' else text
else:
type_id = None
c.execute("SELECT coalesce((SELECT data_id FROM type_data WHERE owner_id=? ORDER BY data_id DESC LIMIT 1), 0) + 1;",
(owner_id, ))
data_id = c.fetchone()[0]
c.execute("INSERT INTO type_data (owner_id, data_id, parent_id, key, type_id) VALUES (?, ?, ?, ?, ?);",
(owner_id, data_id, parent_id, key, type_id))
for attr in node.keys():
c.execute("INSERT INTO type_data_arg (owner_id, data_id, key, type_id) VALUES (?, ?, ?, ?);",
(owner_id, data_id, attr, node.get(attr)))
# Iterate children tags
for child in node:
self._import_tag(c, child, owner_id, data_id)
def populate_extra_data_from_xml(self, filename):
if not os.path.exists(filename):
return
tree = etree.parse(filename)
root = tree.getroot()
c = self.conn.cursor()
for klass in root:
owner_id = klass.tag
for child in klass:
self._import_tag(c, child, owner_id, None)
c.close()
self.conn.commit()
if __name__ == "__main__":
nargs = len(sys.argv)
if nargs < 3:
@ -96,5 +138,11 @@ if __name__ == "__main__":
exit()
db = CambalacheDb()
lib = db.populate_from_gir(sys.argv[1])
# Load custom type data from json file
db.populate_extra_data_from_xml(f'{lib.name}.xml')
db.populate_extra_data_from_xml(f'{lib.name}-{lib.version}.xml')
db.dump(sys.argv[2])