summaryrefslogtreecommitdiffstatshomepage
path: root/scripts/minimaws/lib/dbaccess.py
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2017-08-02 00:41:09 +1000
committer Vas Crabb <vas@vastheman.com>2017-08-02 00:41:09 +1000
commit14642adc5aff91f10f74f997ed2edf22ba58f29a (patch)
treea7cf242c8354b82c25ffb5ca14a4eef06cffeedb /scripts/minimaws/lib/dbaccess.py
parent46a221b95e22aa8fa0c9aa9a7774f72c5c3aebad (diff)
minimaws web mode enhancements:
* Support serving static assets, use for stylesheet, script and images * Better error pages, reject unsupported HTTP methods * Replace lists with sortable tables with more detail (click headings to sort) * Add pages for exploring source files, link from machine pages - Can start from full source file list at http://localhost:8080/sourcefile/ (nw) JavaScript performance can drop when sorting really big tables, e.g. the list of all source files, or the list of machines in some of the fruit machine drivers. This update doesn't expose machine/device information, just consolidating what's there. The wsgiref server is adding headers to prevent caching, I'll look for a workaround.
Diffstat (limited to 'scripts/minimaws/lib/dbaccess.py')
-rw-r--r--scripts/minimaws/lib/dbaccess.py44
1 files changed, 36 insertions, 8 deletions
diff --git a/scripts/minimaws/lib/dbaccess.py b/scripts/minimaws/lib/dbaccess.py
index 3358b538b3c..e6ff07261fe 100644
--- a/scripts/minimaws/lib/dbaccess.py
+++ b/scripts/minimaws/lib/dbaccess.py
@@ -167,20 +167,48 @@ class QueryCursor(object):
def get_devices_referenced(self, machine):
return self.dbcurs.execute(
- 'SELECT devicereference.device AS shortname, machine.description AS description ' \
- 'FROM devicereference LEFT JOIN machine ON devicereference.device = machine.shortname ' \
- 'WHERE devicereference.machine = ? ' \
- 'ORDER BY machine.description ASC, devicereference.device ASC',
+ 'SELECT devicereference.device AS shortname, machine.description AS description, sourcefile.filename AS sourcefile ' \
+ 'FROM devicereference LEFT JOIN machine ON devicereference.device = machine.shortname LEFT JOIN sourcefile ON machine.sourcefile = sourcefile.id ' \
+ 'WHERE devicereference.machine = ?',
(machine, ))
def get_device_references(self, shortname):
return self.dbcurs.execute(
- 'SELECT shortname, description ' \
- 'FROM machine ' \
- 'WHERE id IN (SELECT machine FROM devicereference WHERE device = ?) ' \
- 'ORDER BY description ASC',
+ 'SELECT machine.shortname AS shortname, machine.description AS description, sourcefile.filename AS sourcefile ' \
+ 'FROM machine JOIN sourcefile ON machine.sourcefile = sourcefile.id ' \
+ 'WHERE machine.id IN (SELECT machine FROM devicereference WHERE device = ?)',
(shortname, ))
+ def get_sourcefile_id(self, filename):
+ return (self.dbcurs.execute('SELECT id FROM sourcefile WHERE filename = ?', (filename, )).fetchone() or (None, ))[0]
+
+ def get_sourcefile_machines(self, id):
+ return self.dbcurs.execute(
+ 'SELECT machine.shortname AS shortname, machine.description AS description, machine.isdevice AS isdevice, machine.runnable AS runnable, sourcefile.filename AS sourcefile, system.year AS year, system.manufacturer AS manufacturer, cloneof.parent AS cloneof, romof.parent AS romof ' \
+ 'FROM machine JOIN sourcefile ON machine.sourcefile = sourcefile.id LEFT JOIN system ON machine.id = system.id LEFT JOIN cloneof ON system.id = cloneof.id LEFT JOIN romof ON system.id = romof.id ' \
+ 'WHERE machine.sourcefile = ?',
+ (id, ))
+
+ def get_sourcefiles(self, pattern):
+ if pattern is not None:
+ return self.dbcurs.execute(
+ 'SELECT sourcefile.filename AS filename, COUNT(machine.id) AS machines ' \
+ 'FROM sourcefile LEFT JOIN machine ON sourcefile.id = machine.sourcefile ' \
+ 'WHERE sourcefile.filename GLOB ?' \
+ 'GROUP BY sourcefile.id ',
+ (pattern, ))
+ else:
+ return self.dbcurs.execute(
+ 'SELECT sourcefile.filename AS filename, COUNT(machine.id) AS machines ' \
+ 'FROM sourcefile LEFT JOIN machine ON sourcefile.id = machine.sourcefile ' \
+ 'GROUP BY sourcefile.id')
+
+ def count_sourcefiles(self, pattern):
+ if pattern is not None:
+ return self.dbcurs.execute('SELECT COUNT(*) FROM sourcefile WHERE filename GLOB ?', (pattern, )).fetchone()[0]
+ else:
+ return self.dbcurs.execute('SELECT COUNT(*) FROM sourcefile').fetchone()[0]
+
class UpdateCursor(object):
def __init__(self, dbconn, **kwargs):