summaryrefslogtreecommitdiffstatshomepage
path: root/scripts/minimaws/lib/lxparse.py
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2017-08-02 20:00:12 +1000
committer Vas Crabb <vas@vastheman.com>2017-08-02 20:13:13 +1000
commitc85c7c4c15fb85b98e06667b72edda2c93cf1a92 (patch)
tree7b89d1e96a7a17249fa7d5af6f698e76535f7bd8 /scripts/minimaws/lib/lxparse.py
parentbcef3c04451c7e8884691bcb99eb129c5073e4c8 (diff)
Load slot info in minimaws (not exposed yet), fix up some problems with
slots uncovered (nw) It seems at some point someone didn't realise that choosing the same option from a SLOT_INTERFACE in multiple slots creates multiple instances of the same device type, and this got copy/pasted everywhere.
Diffstat (limited to 'scripts/minimaws/lib/lxparse.py')
-rw-r--r--scripts/minimaws/lib/lxparse.py45
1 files changed, 38 insertions, 7 deletions
diff --git a/scripts/minimaws/lib/lxparse.py b/scripts/minimaws/lib/lxparse.py
index f9061bcb798..cf194128708 100644
--- a/scripts/minimaws/lib/lxparse.py
+++ b/scripts/minimaws/lib/lxparse.py
@@ -134,7 +134,32 @@ class DipSwitchHandler(ElementHandler):
self.setChildHandler(name, attrs, self.IGNORE)
+class SlotHandler(ElementHandler):
+ def __init__(self, parent, **kwargs):
+ super(SlotHandler, self).__init__(parent=parent, **kwargs)
+ self.dbcurs = parent.dbcurs
+ self.machine = parent.id
+
+ def startMainElement(self, name, attrs):
+ self.id = self.dbcurs.add_slot(self.machine, attrs['name'])
+
+ def startChildElement(self, name, attrs):
+ if name == 'slotoption':
+ option = self.dbcurs.add_slotoption(self.id, attrs['devname'], attrs['name'])
+ if attrs.get('default') == 'yes':
+ self.dbcurs.add_slotdefault(self.id, option)
+ self.setChildHandler(name, attrs, self.IGNORE)
+
+
class MachineHandler(ElementHandler):
+ CHILD_HANDLERS = {
+ 'description': TextAccumulator,
+ 'year': TextAccumulator,
+ 'manufacturer': TextAccumulator,
+ 'dipswitch': DipSwitchHandler,
+ 'configuration': DipSwitchHandler,
+ 'slot': SlotHandler }
+
def __init__(self, parent, **kwargs):
super(MachineHandler, self).__init__(parent=parent, **kwargs)
self.dbcurs = self.dbconn.cursor()
@@ -149,10 +174,8 @@ class MachineHandler(ElementHandler):
self.dbcurs.add_sourcefile(self.sourcefile)
def startChildElement(self, name, attrs):
- if (name == 'description') or (name == 'year') or (name == 'manufacturer'):
- self.setChildHandler(name, attrs, TextAccumulator(self))
- elif (name == 'dipswitch') or (name == 'configuration'):
- self.setChildHandler(name, attrs, DipSwitchHandler(self))
+ if name in self.CHILD_HANDLERS:
+ self.setChildHandler(name, attrs, self.CHILD_HANDLERS[name](self))
else:
if name == 'device_ref':
self.dbcurs.add_devicereference(self.id, attrs['name'])
@@ -178,7 +201,6 @@ class MachineHandler(ElementHandler):
self.dbcurs.add_system(self.id, self.year, self.manufacturer)
def endMainElement(self, name):
- self.dbconn.commit()
self.dbcurs.close()
@@ -199,11 +221,12 @@ class ListXmlHandler(ElementHandler):
msg=('Expected "mame" element but found "%s"' % (name, )),
exception=None,
locator=self.locator)
- self.dbconn.drop_indexes()
+ self.dbconn.prepare_for_load()
+ self.machines = 0
def endMainElement(self, name):
# TODO: build index by first letter or whatever
- self.dbconn.create_indexes()
+ self.dbconn.finalise_load()
def startChildElement(self, name, attrs):
if name != 'machine':
@@ -213,6 +236,14 @@ class ListXmlHandler(ElementHandler):
locator=self.locator)
self.setChildHandler(name, attrs, MachineHandler(self))
+ def endChildHandler(self, name, handler):
+ if name == 'machine':
+ if self.machines >= 1023:
+ self.dbconn.commit()
+ self.machines = 0
+ else:
+ self.machines += 1
+
def processingInstruction(self, target, data):
pass