mirror of https://github.com/tLDP/LDP
Lintadas now updates the document's format and DTD based on its files.
This commit is contained in:
parent
b27ac0f58e
commit
d80976ee92
|
@ -193,6 +193,9 @@ class ClassI18n:
|
|||
|
||||
class Config(LampadasCollection):
|
||||
|
||||
def __call__(self, key):
|
||||
return self[key]
|
||||
|
||||
def Load(self):
|
||||
self.sql = "SELECT name, value FROM config"
|
||||
self.cursor = DB.Select(self.sql)
|
||||
|
@ -277,7 +280,7 @@ class Doc:
|
|||
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)
|
||||
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=" + dbint(self.Rating) + ", lang=" + wsq(self.LanguageCode) + ", sk_seriesid=" + wsq(self.SeriesID) + " WHERE doc_id=" + str(self.ID)
|
||||
DB.Exec(self.sql)
|
||||
DB.Commit()
|
||||
|
||||
|
@ -553,6 +556,13 @@ def wsq(astring):
|
|||
else:
|
||||
return "'" + astring.replace("'", "''") + "'"
|
||||
|
||||
def dbint(anint):
|
||||
if anint == None:
|
||||
temp = 'NULL'
|
||||
else:
|
||||
temp = str(anint)
|
||||
return temp
|
||||
|
||||
def bool2tf(bool):
|
||||
if bool == 1:
|
||||
return 't'
|
||||
|
@ -572,6 +582,7 @@ def trim(astring):
|
|||
temp = str(astring)
|
||||
return strip(temp)
|
||||
|
||||
|
||||
# main
|
||||
if __name__ == '__main__' :
|
||||
print "Running unit tests..."
|
||||
|
|
|
@ -11,7 +11,7 @@ document_error table.
|
|||
# Modules ##################################################################
|
||||
|
||||
import DataLayer
|
||||
|
||||
import os
|
||||
|
||||
# Constants
|
||||
|
||||
|
@ -20,6 +20,7 @@ import DataLayer
|
|||
|
||||
L = DataLayer.Lampadas()
|
||||
|
||||
cvs_root = L.Config('cvs_root')
|
||||
|
||||
# Lintadas
|
||||
|
||||
|
@ -28,9 +29,9 @@ class Lintadas:
|
|||
def CheckAllDocs(self):
|
||||
keys = L.Docs.keys()
|
||||
for key in keys:
|
||||
self.CheckDocument(key)
|
||||
self.CheckDoc(key)
|
||||
|
||||
def CheckDocument(self, DocID):
|
||||
def CheckDoc(self, DocID):
|
||||
Doc = L.Docs[DocID]
|
||||
Doc.Errors.Clear()
|
||||
|
||||
|
@ -38,20 +39,50 @@ class Lintadas:
|
|||
keys = Doc.Files.keys()
|
||||
for key in keys:
|
||||
|
||||
File = Doc.Files[key]
|
||||
|
||||
# Determine file format
|
||||
ext = Doc.Files[key].Filename[-5:]
|
||||
ext = File.Filename[-5:]
|
||||
ext = ext.upper()
|
||||
if ext == '.SGML':
|
||||
Doc.Files[key].Format = "SGML"
|
||||
File.Format = "SGML"
|
||||
Doc.Format = 'SGML'
|
||||
elif ext[-4:] == '.XML':
|
||||
Doc.Files[key].Format = "XML"
|
||||
File.Format = "XML"
|
||||
Doc.Format = 'XML'
|
||||
elif ext[-3:] == '.WT':
|
||||
Doc.Files[key].Format = 'WIKI'
|
||||
File.Format = 'WIKI'
|
||||
Doc.Format = 'WIKI'
|
||||
else:
|
||||
Doc.Files[key].Format = ''
|
||||
Doc.Files[key].Save()
|
||||
File.Format = ''
|
||||
Doc.Format = ''
|
||||
|
||||
# Determine DTD for SGML and XML files
|
||||
if File.Format == 'XML' or File.Format == 'SGML':
|
||||
DTDVersion = ''
|
||||
try:
|
||||
command = 'grep -i DOCTYPE ' + cvs_root + File.Filename + ' | head -n 1'
|
||||
grep = os.popen(command, 'r')
|
||||
DTDVersion = grep.read()
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
DTDVersion = DTDVersion.upper()
|
||||
if DTDVersion.count('DOCBOOK') > 0:
|
||||
Doc.DTD = 'DocBook'
|
||||
elif DTDVersion.count('LINUXDOC') > 0:
|
||||
Doc.DTD = 'LinuxDoc'
|
||||
else:
|
||||
Doc.DTD = ''
|
||||
|
||||
|
||||
Doc.Save()
|
||||
File.Save()
|
||||
|
||||
|
||||
# When run at the command line, all checks are performed on all documents.
|
||||
|
||||
if __name__ == "__main__":
|
||||
Lintadas = Lintadas()
|
||||
Lintadas.CheckAllDocs()
|
||||
# Lintadas.CheckDoc(469)
|
||||
|
|
Loading…
Reference in New Issue