sample Lintadas module, very preliminary, plus HTML updates and some more

classes (DocFiles, DocErrors).
This commit is contained in:
david 2002-05-17 18:02:54 +00:00
parent 2211b31b13
commit b27ac0f58e
5 changed files with 213 additions and 4 deletions

View File

@ -273,12 +273,101 @@ class Doc:
self.LanguageCode = trim(row[20])
self.SeriesID = trim(row[21])
self.Files = DocFiles(self.ID)
self.Errors = DocErrors(self.ID)
def Save(self):
self.sql = "UPDATE document SET title=" + wsq(self.Title) + ", class_id=" + str(self.ClassID) + ", format=" + wsq(self.Format) + ", dtd=" + wsq(self.DTD) + ", dtd_version=" + wsq(self.DTDVersion) + ", version=" + wsq(self.Version) + ", last_update=" + wsq(self.LastUpdate) + ", url=" + wsq(self.URL) + ", isbn=" + wsq(self.ISBN) + ", pub_status=" + wsq(self.PubStatus) + ", review_status=" + wsq(self.ReviewStatus) + ", tickle_date=" + wsq(self.TickleDate) + ", pub_date=" + wsq(self.PubDate) + ", ref_url=" + wsq(self.HomeURL) + ", tech_review_status=" + wsq(self.TechReviewStatus) + ", maintained=" + wsq(bool2tf(self.Maintained)) + ", license=" + wsq(self.License) + ", abstract=" + wsq(self.Abstract) + ", rating=" + wsq(self.Rating) + ", lang=" + wsq(self.LanguageCode) + ", sk_seriesid=" + wsq(self.SeriesID) + " WHERE doc_id=" + str(self.ID)
DB.Exec(self.sql)
DB.Commit()
# DocFiles
class DocFiles(LampadasCollection):
"""
A collection object providing access to all document source files.
"""
def __init__(self, DocID):
self.data = {}
assert not DocID == None
self.DocID = DocID
self.sql = "SELECT filename, format FROM document_file WHERE doc_id=" + str(DocID)
self.cursor = DB.Select(self.sql)
while (1):
row = self.cursor.fetchone()
if row == None: break
newDocFile = DocFile()
newDocFile.Load(DocID, row)
self.data[newDocFile.Filename] = newDocFile
class DocFile:
"""
An association between a document and a file.
"""
def Load(self, DocID, row):
assert not DocID == None
assert not row == None
self.DocID = DocID
self.Filename = trim(row[0])
self.Format = trim(row[1])
def Save(self):
self.sql = "UPDATE document_file SET format=" + wsq(self.Format) + " WHERE doc_id=" + str(self.DocID) + " AND filename=" + wsq(self.Filename)
assert DB.Exec(self.sql) == 1
DB.Commit()
# DocErrors
class DocErrors(LampadasList):
"""
A collection object providing access to all document errors, as identified by the
Lintadas subsystem.
"""
def __init__(self, DocID):
assert not DocID == None
self.DocID = DocID
self.sql = "SELECT error FROM document_error WHERE doc_id=" + str(DocID)
self.cursor = DB.Select(self.sql)
while (1):
row = self.cursor.fetchone()
if row == None: break
newDocError = DocError()
newDocError.Load(DocID, row)
self.list = self.list + [newDocError]
def Clear(self):
self.sql = "DELETE FROM document_error WHERE doc_id=" + str(self.DocID)
DB.Exec(self.sql)
self.list = []
def Add(self, Error):
self.sql = "INSERT INTO document_error(doc_id, error) VALUES (" + str(self.DocID) + ", " + wsq(Error)
assert DB.Exec(self.sql) == 1
newDocError = DocError()
newDocError.DocID = self.DocID
newDocError.Error = Error
self.list = self.list + [newDocError]
class DocError:
"""
An error filed against a document by the Lintadas subsystem.
"""
def Load(self, DocID, row):
assert not DocID == None
assert not row == None
self.DocID = DocID
self.Error = trim(row[0])
# String
class Strings(LampadasCollection):

View File

@ -34,10 +34,24 @@ class HTMLFactory:
class PageFactory:
def __call__(self, key, lang):
page = L.Strings['template_default'].I18n[lang].Text
page = L.Strings['tpl-default'].I18n[lang].Text
page = page.replace('|header|', L.Strings['header'].I18n[lang].Text)
page = page.replace('|body|', L.Strings[key].I18n[lang].Text)
page = page.replace('|footer|', L.Strings['footer'].I18n[lang].Text)
if key[:4] == 'doc/':
docid = int(key[4:])
print "DOC " + str(docid) + " requested"
Doc = L.Docs[docid]
assert not Doc == None
Files = Doc.Files
keys = Files.keys()
for key in keys:
File = Files[key]
print "filename: " + File.Filename
print "format: " + File.Format
else:
page = page.replace('|body|', L.Strings[key].I18n[lang].Text)
return page
@ -84,7 +98,10 @@ Factory = HTMLFactory()
#output = Factory.Combo.Classes(2,'EN')
#print output
output = Factory.Page('pg_about', 'EN')
print output
#output = Factory.Page('pg-about', 'EN')
#print output
output = Factory.Page('doc/1', 'EN')
#print output
#if __name__ == "__main__":

57
LDP/lampadas/pylib/Lintadas.py Executable file
View File

@ -0,0 +1,57 @@
#!/usr/bin/python
"""
Lampadas Error Checking Module
This module performs all kinds of automatic checks on data in the database
and the source files it points to. Errors are logged in the
document_error table.
"""
# Modules ##################################################################
import DataLayer
# Constants
# Globals
L = DataLayer.Lampadas()
# Lintadas
class Lintadas:
def CheckAllDocs(self):
keys = L.Docs.keys()
for key in keys:
self.CheckDocument(key)
def CheckDocument(self, DocID):
Doc = L.Docs[DocID]
Doc.Errors.Clear()
# Test document files
keys = Doc.Files.keys()
for key in keys:
# Determine file format
ext = Doc.Files[key].Filename[-5:]
ext = ext.upper()
if ext == '.SGML':
Doc.Files[key].Format = "SGML"
elif ext[-4:] == '.XML':
Doc.Files[key].Format = "XML"
elif ext[-3:] == '.WT':
Doc.Files[key].Format = 'WIKI'
else:
Doc.Files[key].Format = ''
Doc.Files[key].Save()
if __name__ == "__main__":
Lintadas = Lintadas()
Lintadas.CheckAllDocs()

View File

@ -109,6 +109,33 @@ class testDocs(unittest.TestCase):
self.Doc2 = L.Docs[1]
assert self.Doc2.Title == self.Title
class testDocFiles(unittest.TestCase):
def testDocFiles(self):
Doc = L.Docs[1]
assert not Doc == None
assert Doc.Files.Count() > 0
keys = Doc.Files.keys()
for key in keys:
File = Doc.Files[key]
if File == None: break
assert File.DocID == Doc.ID
assert File.Filename > ''
class testDocErrors(unittest.TestCase):
def testDocErrors(self):
keys = L.Docs.keys()
for key in keys:
Doc = L.Docs[key]
assert not Doc == None
if Doc.Errors.Count() > 0:
print "found a doc with errors"
for Error in Doc.Errors:
assert not Error == None
assert Error.DocID == Doc.ID
assert Error.Error > ''
class testStrings(unittest.TestCase):
def testStrings(self):

View File

@ -135,3 +135,22 @@ string the parent object needs. For example, for Class object has the following
Class['HOWTO'].I18n['EN'].Name = 'HOWTO'
Class['HOWTO'].I18n['EN'].Description = 'HOWTO do something in Linux'
=Strings=
The string and string_i18n tables hold localized strings that are displayed on the web
page and elsewhere. Each string is named with a short text name, and the names use the
following conventions:
tpl-* a page template
pg-* a page for the website
mi-* a menu item
We may need to go with something more sophisticated, i.e., a separate table for pages
and templates, but we'll see about that as development goes along.
When a string contains a string delimited with pipe characters, like "|header|", it
replaces that string with the named string. This is how pages are build from page templates.
Nesting can be to any arbitrary depth, but cannot be recursive for obvious reasons.
If you need to use an actual pipe character, escape it like this: "\|".