diff options
author | 2021-10-05 19:16:42 +0200 | |
---|---|---|
committer | 2021-10-05 19:16:42 +0200 | |
commit | eae75824d3c8d697216a9782b9f7ca6494ef431d (patch) | |
tree | eb98e1e99941c8843fe2196480927eefb00e2784 /scripts/minimaws/lib | |
parent | 716c9f4c863ca150ff519429b24168df9890f1b1 (diff) |
softlist.cpp: Add support for a 'notes' field to store information ab… (#8482)
* softlist.cpp: Add support for a 'notes' field to store information about a software list or software list item. [Wilbert Pol]
* Add software list and software notes to minimaws
Diffstat (limited to 'scripts/minimaws/lib')
-rw-r--r-- | scripts/minimaws/lib/dbaccess.py | 18 | ||||
-rw-r--r-- | scripts/minimaws/lib/htmltmpl.py | 8 | ||||
-rw-r--r-- | scripts/minimaws/lib/lxparse.py | 20 | ||||
-rw-r--r-- | scripts/minimaws/lib/wsgiserve.py | 6 |
4 files changed, 45 insertions, 7 deletions
diff --git a/scripts/minimaws/lib/dbaccess.py b/scripts/minimaws/lib/dbaccess.py index c22b7c318fa..208b22a02c7 100644 --- a/scripts/minimaws/lib/dbaccess.py +++ b/scripts/minimaws/lib/dbaccess.py @@ -32,6 +32,7 @@ class SchemaQueries(object): ' id INTEGER PRIMARY KEY,\n' \ ' shortname TEXT NOT NULL,\n' \ ' description TEXT NOT NULL,\n' \ + ' notes TEXT NULL,\n' \ ' UNIQUE (shortname ASC))' CREATE_SOFTWARE = \ 'CREATE TABLE software (\n' \ @@ -42,6 +43,7 @@ class SchemaQueries(object): ' description TEXT NOT NULL,\n' \ ' year TEXT NOT NULL,\n' \ ' publisher TEXT NOT NULL,\n' \ + ' notes TEXT NULL,\n' \ ' UNIQUE (softwarelist ASC, shortname ASC),\n' \ ' FOREIGN KEY (softwarelist) REFERENCES softwarelist (id))' CREATE_SOFTWARECLONEOF = \ @@ -505,6 +507,8 @@ class UpdateQueries(object): ADD_SOFTWARESHAREDFEAT = 'INSERT INTO softwaresharedfeat (software, sharedfeattype, value) SELECT ?, id, ? FROM softwaresharedfeattype WHERE name = ?' ADD_SOFTWAREPART = 'INSERT INTO softwarepart (software, shortname, interface) VALUES (?, ?, ?)' ADD_SOFTWAREPARTFEATURE = 'INSERT INTO softwarepartfeature (part, featuretype, value) SELECT ?, id, ? FROM softwarepartfeaturetype WHERE name = ?' + UPDATE_SOFTWARELIST_NOTES = 'UPDATE softwarelist SET notes = ? WHERE id = ?' + UPDATE_SOFTWARE_NOTES = 'UPDATE software SET notes = ? WHERE id = ?' # machines ADD_FEATURETYPE = 'INSERT OR IGNORE INTO featuretype (name) VALUES (?)' @@ -773,7 +777,7 @@ class QueryCursor(object): def get_machine_softwarelists(self, machine): return self.dbcurs.execute( - 'SELECT machinesoftwarelist.tag AS tag, machinesoftwareliststatustype.value AS status, softwarelist.shortname AS shortname, softwarelist.description AS description, COUNT(software.id) AS total, COUNT(CASE software.supported WHEN 0 THEN 1 ELSE NULL END) AS supported, COUNT(CASE software.supported WHEN 1 THEN 1 ELSE NULL END) AS partiallysupported, COUNT(CASE software.supported WHEN 2 THEN 1 ELSE NULL END) AS unsupported ' \ + 'SELECT machinesoftwarelist.tag AS tag, machinesoftwareliststatustype.value AS status, softwarelist.shortname AS shortname, softwarelist.description AS description, softwarelist.notes AS notes, COUNT(software.id) AS total, COUNT(CASE software.supported WHEN 0 THEN 1 ELSE NULL END) AS supported, COUNT(CASE software.supported WHEN 1 THEN 1 ELSE NULL END) AS partiallysupported, COUNT(CASE software.supported WHEN 2 THEN 1 ELSE NULL END) AS unsupported ' \ 'FROM machinesoftwarelist LEFT JOIN machinesoftwareliststatustype ON machinesoftwarelist.status = machinesoftwareliststatustype.id LEFT JOIN softwarelist ON machinesoftwarelist.softwarelist = softwarelist.id LEFT JOIN software ON softwarelist.id = software.softwarelist ' \ 'WHERE machinesoftwarelist.machine = ? ' \ 'GROUP BY machinesoftwarelist.id', @@ -785,14 +789,14 @@ class QueryCursor(object): def get_softwarelist_details(self, shortname, pattern): if pattern is not None: return self.dbcurs.execute( - 'SELECT softwarelist.id AS id, softwarelist.shortname AS shortname, softwarelist.description AS description, COUNT(software.id) AS total, COUNT(CASE software.supported WHEN 0 THEN 1 ELSE NULL END) AS supported, COUNT(CASE software.supported WHEN 1 THEN 1 ELSE NULL END) AS partiallysupported, COUNT(CASE software.supported WHEN 2 THEN 1 ELSE NULL END) AS unsupported ' \ + 'SELECT softwarelist.id AS id, softwarelist.shortname AS shortname, softwarelist.description AS description, softwarelist.notes AS notes, COUNT(software.id) AS total, COUNT(CASE software.supported WHEN 0 THEN 1 ELSE NULL END) AS supported, COUNT(CASE software.supported WHEN 1 THEN 1 ELSE NULL END) AS partiallysupported, COUNT(CASE software.supported WHEN 2 THEN 1 ELSE NULL END) AS unsupported ' \ 'FROM softwarelist LEFT JOIN software ON softwarelist.id = software.softwarelist ' \ 'WHERE softwarelist.shortname = ? AND software.shortname GLOB ? ' \ 'GROUP BY softwarelist.id', (shortname, pattern)) else: return self.dbcurs.execute( - 'SELECT softwarelist.id AS id, softwarelist.shortname AS shortname, softwarelist.description AS description, COUNT(software.id) AS total, COUNT(CASE software.supported WHEN 0 THEN 1 ELSE NULL END) AS supported, COUNT(CASE software.supported WHEN 1 THEN 1 ELSE NULL END) AS partiallysupported, COUNT(CASE software.supported WHEN 2 THEN 1 ELSE NULL END) AS unsupported ' \ + 'SELECT softwarelist.id AS id, softwarelist.shortname AS shortname, softwarelist.description AS description, softwarelist.notes AS notes, COUNT(software.id) AS total, COUNT(CASE software.supported WHEN 0 THEN 1 ELSE NULL END) AS supported, COUNT(CASE software.supported WHEN 1 THEN 1 ELSE NULL END) AS partiallysupported, COUNT(CASE software.supported WHEN 2 THEN 1 ELSE NULL END) AS unsupported ' \ 'FROM softwarelist LEFT JOIN software ON softwarelist.id = software.softwarelist ' \ 'WHERE softwarelist.shortname = ? ' \ 'GROUP BY softwarelist.id', @@ -836,7 +840,7 @@ class QueryCursor(object): def get_software_details(self, softwarelist, software): return self.dbcurs.execute( - 'SELECT software.id AS id, software.shortname AS shortname, software.supported AS supported, software.description AS description, software.year AS year, software.publisher AS publisher, softwarelist.shortname AS softwarelist, softwarelist.description AS softwarelistdescription, parent.shortname AS parent, parent.description AS parentdescription, parentsoftwarelist.shortname AS parentsoftwarelist, parentsoftwarelist.description AS parentsoftwarelistdescription ' \ + 'SELECT software.id AS id, software.shortname AS shortname, software.supported AS supported, software.description AS description, software.year AS year, software.publisher AS publisher, software.notes AS notes, softwarelist.shortname AS softwarelist, softwarelist.description AS softwarelistdescription, parent.shortname AS parent, parent.description AS parentdescription, parentsoftwarelist.shortname AS parentsoftwarelist, parentsoftwarelist.description AS parentsoftwarelistdescription ' \ 'FROM software LEFT JOIN softwarelist ON software.softwarelist = softwarelist.id LEFT JOIN softwarecloneof ON software.id = softwarecloneof.id LEFT JOIN software AS parent ON softwarecloneof.parent = parent.id LEFT JOIN softwarelist AS parentsoftwarelist ON parent.softwarelist = parentsoftwarelist.id ' \ 'WHERE software.softwarelist = (SELECT id FROM softwarelist WHERE shortname = ?) AND software.shortname = ?', (softwarelist, software)) @@ -912,6 +916,9 @@ class UpdateCursor(object): self.dbcurs.execute(UpdateQueries.ADD_SOFTWARELIST, (shortname, description)) return self.dbcurs.lastrowid + def update_softwarelist_notes(self, id, notes): + self.dbcurs.execute(UpdateQueries.UPDATE_SOFTWARELIST_NOTES, (notes, id)) + def add_softwareinfotype(self, name): self.dbcurs.execute(UpdateQueries.ADD_SOFTWAREINFOTYPE, (name, )) @@ -925,6 +932,9 @@ class UpdateCursor(object): self.dbcurs.execute(UpdateQueries.ADD_SOFTWARE, (softwarelist, shortname, supported, description, year, publisher)) return self.dbcurs.lastrowid + def update_software_notes(self, id, notes): + self.dbcurs.execute(UpdateQueries.UPDATE_SOFTWARE_NOTES, (notes, id)) + def add_softwarecloneof(self, software, parent): self.dbcurs.execute(UpdateQueries.ADD_TEMPORARY_SOFTWARECLONEOF, (software, parent)) return self.dbcurs.lastrowid diff --git a/scripts/minimaws/lib/htmltmpl.py b/scripts/minimaws/lib/htmltmpl.py index a80b4099787..4f3bf12bb46 100644 --- a/scripts/minimaws/lib/htmltmpl.py +++ b/scripts/minimaws/lib/htmltmpl.py @@ -258,6 +258,10 @@ SOFTWARE_PROLOGUE = string.Template( ' <tr><th>Year:</th><td>${year}</td></tr>\n' \ ' <tr><th>Publisher:</th><td>${publisher}</td></tr>\n'); +SOFTWARE_EPILOGUE = string.Template( + '<h2>Notes</h2>\n' \ + '<p><pre>${notes}<p></pre>\n'); + SOFTWARE_CLONES_PROLOGUE = string.Template( '<h2 id="heading-clones">Clones</h2>\n' \ '<table id="tbl-clones">\n' \ @@ -328,6 +332,10 @@ SOFTWARELIST_PROLOGUE = string.Template( ' </tr>\n' \ '</table>\n') +SOFTWARELIST_EPILOGUE = string.Template( + '<h2>Notes</h2>\n' \ + '<p><pre>${notes}<p></pre>\n') + SOFTWARELIST_MACHINE_TABLE_HEADER = string.Template( '<h2 id="heading-machines">Machines</h2>\n' \ '<table id="tbl-machines">\n' \ diff --git a/scripts/minimaws/lib/lxparse.py b/scripts/minimaws/lib/lxparse.py index 46737ef438a..699695577fc 100644 --- a/scripts/minimaws/lib/lxparse.py +++ b/scripts/minimaws/lib/lxparse.py @@ -352,6 +352,7 @@ class SoftwareHandler(ElementHandler): 'description': TextAccumulator, 'year': TextAccumulator, 'publisher': TextAccumulator, + 'notes': TextAccumulator, 'part': SoftwarePartHandler } def __init__(self, parent, **kwargs): @@ -389,6 +390,9 @@ class SoftwareHandler(ElementHandler): self.id = self.dbcurs.add_software(self.softwarelist, self.shortname, self.supported, self.description, self.year, self.publisher) if self.cloneof is not None: self.dbcurs.add_softwarecloneof(self.id, self.cloneof) + elif name == 'notes': + self.notes = handler.text + self.dbcurs.update_software_notes(self.id, self.notes) class SoftwareListHandler(ElementHandler): @@ -410,24 +414,34 @@ class SoftwareListHandler(ElementHandler): locator=self.locator) self.shortname = attrs['name'] self.description = attrs['description'] + self.notes = None self.entries = 0 dbcurs = self.dbconn.cursor() self.id = dbcurs.add_softwarelist(self.shortname, self.description) dbcurs.close() def endMainElement(self, name): + if self.notes: + dbcurs = self.dbconn.cursor() + dbcurs.update_softwarelist_notes(self.id, self.notes) + dbcurs.close() self.dbconn.commit() def startChildElement(self, name, attrs): - if name != 'software': + if name == 'notes': + self.setChildHandler(name, attrs, TextAccumulator(self)) + elif name == 'software': + self.setChildHandler(name, attrs, SoftwareHandler(self)) + else: raise xml.sax.SAXParseException( msg=('Expected "software" element but found "%s"' % (name, )), exception=None, locator=self.locator) - self.setChildHandler(name, attrs, SoftwareHandler(self)) def endChildHandler(self, name, handler): - if name == 'software': + if name == 'notes': + self.notes = handler.text + elif name == 'software': if self.entries >= 1023: self.dbconn.commit() self.entries = 0 diff --git a/scripts/minimaws/lib/wsgiserve.py b/scripts/minimaws/lib/wsgiserve.py index 43d5dbc1253..3b92f08110d 100644 --- a/scripts/minimaws/lib/wsgiserve.py +++ b/scripts/minimaws/lib/wsgiserve.py @@ -689,6 +689,9 @@ class SoftwareListHandler(QueryPageHandler): yield htmltmpl.SORTABLE_TABLE_EPILOGUE.substitute(id='tbl-software').encode('utf-8') yield '<script>make_collapsible(document.getElementById("heading-software"), document.getElementById("tbl-software"));</script>\n'.encode('utf-8') + if (softwarelist_info['notes']): + yield htmltmpl.SOFTWARELIST_EPILOGUE.substitute(notes=htmlescape(softwarelist_info['notes'])).encode('utf-8') + yield '</body>\n</html>\n'.encode('utf-8') def software_page(self, software_info): @@ -733,6 +736,9 @@ class SoftwareListHandler(QueryPageHandler): yield (' <tr><th>%s:</th><td>%s</td>\n' % (htmlescape(name), htmlescape(value))).encode('utf-8') yield '</table>\n\n'.encode('utf-8') + if (software_info['notes']): + yield htmltmpl.SOFTWARE_EPILOGUE.substitute(notes=htmlescape(software_info['notes'])).encode('utf-8') + yield '</body>\n</html>\n'.encode('utf-8') def software_row(self, software_info): |