lowercase methods and attributes

This commit is contained in:
david 2002-07-05 03:54:50 +00:00
parent 29d5242659
commit 2e4e048e4e
16 changed files with 460 additions and 482 deletions

View File

@ -6,9 +6,14 @@
TODO:
The various boxes really should be editable, as the pages are.
Then site administrators can remove fields they do not use as part of
their workflow practices.
their workflow practices. And it should be faster w/o concatenation.
Update what concatenation there is left to use the WOStringIO routine
from Nicolas (in Globals.py).
Add "primary" field to document_file to know which is the topmost file.

View File

@ -5,7 +5,7 @@ CREATE TABLE document
title TEXT NOT NULL,
type_code CHAR(20) NOT NULL REFERENCES type(type_code),
format_code CHAR(20) REFERENCES format(format_code),
dtd CHAR(12) REFERENCES dtd(dtd),
dtd_code CHAR(12) REFERENCES dtd(dtd_code),
dtd_version CHAR(12),
version CHAR(12),
last_update DATE,

View File

@ -1,5 +1,5 @@
m4_define(insert, [INSERT INTO document(doc_id, lang, title, version, isbn,
type_code, format_code, dtd, dtd_version,
type_code, format_code, dtd_code, dtd_version,
license_code, abstract,
url, ref_url,
pub_status, review_status, tech_review_status,

View File

@ -1,6 +1,6 @@
CREATE TABLE dtd
(
dtd CHAR(12) NOT NULL,
dtd_code CHAR(12) NOT NULL,
PRIMARY KEY (dtd)
PRIMARY KEY (dtd_code)
);

View File

@ -1,2 +1,2 @@
m4_define(insert, [INSERT INTO dtd(dtd)
m4_define(insert, [INSERT INTO dtd(dtd_code)
VALUES ('$1');])m4_dnl

View File

@ -23,45 +23,6 @@ These base classes are subclassed by other Lampadas objects,
but are never instantiated directly.
"""
class LampadasList:
"""
Base class for Lampadas list objects.
Classes based on this one emulate lists, with additional methods.
FIXME: I don't think this class is needed. Why not just using a list ?
-- nico
"""
def __init__(self):
self.list = []
def __len__(self):
return len(self.list)
def __getitem__(self, key):
try:
item = self.list[key]
except KeyError:
item = None
return item
def __setitem__(self, key, value):
self.list[key] = value
def __delitem__(self, key):
del self.list[key]
def items(self):
return self.list.items()
def append(self, item):
self.list.append(item)
def count(self):
return len(self.list)
class LampadasCollection:
"""
Base class for Lampadas dictionaries or collection objects.

View File

@ -55,26 +55,23 @@ class Lampadas:
"""
def __init__(self):
self.types = Types()
self.types = Types()
self.types.load()
self.Docs = Docs()
self.Docs.Load()
self.licenses = Licenses()
self.DTDs = DTDs()
self.Formats = Formats()
self.languages = Languages()
self.PubStatuses = PubStatuses()
self.ReviewStatuses = ReviewStatuses()
self.topics = Topics()
self.subtopics = Subtopics()
self.users = Users()
self.docs = Docs()
self.docs.load()
self.licenses = Licenses()
self.dtds = DTDs()
self.formats = Formats()
self.languages = Languages()
self.pub_statuses = PubStatuses()
self.review_statuses = ReviewStatuses()
self.topics = Topics()
self.subtopics = Subtopics()
self.users = Users()
def user(self, username):
return User(username)
def Doc(self, DocID):
return Doc(DocID)
# Class
@ -89,9 +86,9 @@ class Types(LampadasCollection):
while (1):
row = cursor.fetchone()
if row==None: break
newType = Type()
newType.Load(row)
self.data[newType.code] = newType
type = Type()
type.load(row)
self.data[type.code] = type
class Type:
"""
@ -105,7 +102,7 @@ class Type:
if type_code==None: return
self.code = type_code
def Load(self, row):
def load(self, row):
self.code = trim(row[0])
self.sort_order = row[1]
@ -126,28 +123,28 @@ class Docs(LampadasCollection):
A collection object providing access to all documents.
"""
def Load(self):
sql = "SELECT doc_id, title, type_code, format_code, dtd, dtd_version, version, last_update, url, isbn, pub_status, review_status, tickle_date, pub_date, ref_url, tech_review_status, maintained, maintainer_wanted, license_code, abstract, rating, lang, sk_seriesid FROM document"
def load(self):
sql = "SELECT doc_id, title, type_code, format_code, dtd_code, dtd_version, version, last_update, url, isbn, pub_status, review_status, tickle_date, pub_date, ref_url, tech_review_status, maintained, maintainer_wanted, license_code, abstract, rating, lang, sk_seriesid FROM document"
cursor = db.select(sql)
while (1):
row = cursor.fetchone()
if row==None: break
newDoc = Doc()
newDoc.LoadRow(row)
self[newDoc.ID] = newDoc
doc = Doc()
doc.load_row(row)
self[doc.id] = doc
# FIXME: try instantiating a new document, then adding *it* to the collection,
# rather than passing in all these parameters.
def add(self, Title, type_code, format_code, DTD, DTDVersion, Version, LastUpdate, URL, ISBN, PubStatusCode, ReviewStatus, TickleDate, PubDate, HomeURL, TechReviewStatusCode, license_code, Abstract, Lang, sk_seriesid):
def add(self, title, type_code, format_code, dtd_code, dtd_version, version, last_update, url, isbn, pub_status_code, review_status_code, tickle_date, pub_date, home_url, tech_review_status_code, license_code, abstract, lang, sk_seriesid):
self.id = db.read_value('SELECT max(doc_id) from document') + 1
sql = "INSERT INTO document(doc_id, title, type_code, format_code, dtd, dtd_version, version, last_update, url, isbn, pub_status, review_status, tickle_date, pub_date, ref_url, tech_review_status, license_code, abstract, lang, sk_seriesid) VALUES (" + str(self.id) + ", " + wsq(Title) + ", " + wsq(type_code) + ", " + wsq(format_code) + ", " + wsq(DTD) + ", " + wsq(DTDVersion) + ", " + wsq(Version) + ", " + wsq(LastUpdate) + ", " + wsq(URL) + ", " + wsq(ISBN) + ", " + wsq(PubStatusCode) + ", " + wsq(ReviewStatus) + ", " + wsq(TickleDate) + ", " + wsq(PubDate) + ", " + wsq(HomeURL) + ", " + wsq(TechReviewStatusCode) + ", " + wsq(license_code) + ", " + wsq(Abstract) + ", " + wsq(Lang) + ", " + wsq(sk_seriesid) + ")"
sql = "INSERT INTO document(doc_id, title, type_code, format_code, dtd_code, dtd_version, version, last_update, url, isbn, pub_status, review_status, tickle_date, pub_date, ref_url, tech_review_status, license_code, abstract, lang, sk_seriesid) VALUES (" + str(self.id) + ", " + wsq(title) + ", " + wsq(type_code) + ", " + wsq(format_code) + ", " + wsq(dtd_code) + ", " + wsq(dtd_version) + ", " + wsq(version) + ", " + wsq(last_update) + ", " + wsq(url) + ", " + wsq(isbn) + ", " + wsq(pub_status_code) + ", " + wsq(review_status_code) + ", " + wsq(tickle_date) + ", " + wsq(pub_date) + ", " + wsq(home_url) + ", " + wsq(tech_review_status_code) + ", " + wsq(license_code) + ", " + wsq(abstract) + ", " + wsq(lang) + ", " + wsq(sk_seriesid) + ")"
assert db.runsql(sql)==1
db.commit()
self.NewID = db.read_value('SELECT MAX(doc_id) from document')
newDoc = Doc(self.NewID)
self[self.NewID] = newDoc
return self.NewID
doc_id = db.read_value('SELECT MAX(doc_id) from document')
doc = Doc(doc_id)
self[doc_id] = doc
return doc_id
def delete(self, id):
sql = ('DELETE from document WHERE doc_id=' + str(id))
@ -162,87 +159,86 @@ class Doc:
def __init__(self, id=None):
if id==None: return
self.Load(id)
self.load(id)
def Load(self, id):
sql = "SELECT doc_id, title, type_code, format_code, dtd, dtd_version, version, last_update, url, isbn, pub_status, review_status, tickle_date, pub_date, ref_url, tech_review_status, maintained, maintainer_wanted, license_code, abstract, rating, lang, sk_seriesid FROM document WHERE doc_id=" + str(id)
def load(self, id):
sql = "SELECT doc_id, title, type_code, format_code, dtd_code, dtd_version, version, last_update, url, isbn, pub_status, review_status, tickle_date, pub_date, ref_url, tech_review_status, maintained, maintainer_wanted, license_code, abstract, rating, lang, sk_seriesid FROM document WHERE doc_id=" + str(id)
cursor = db.select(sql)
row = cursor.fetchone()
self.LoadRow(row)
self.load_row(row)
def LoadRow(self, row):
self.ID = row[0]
self.Title = trim(row[1])
self.type_code = trim(row[2])
self.format_code = trim(row[3])
self.DTD = trim(row[4])
self.DTDVersion = trim(row[5])
self.Version = trim(row[6])
self.LastUpdate = date2str(row[7])
self.URL = trim(row[8])
self.ISBN = trim(row[9])
self.PubStatusCode = trim(row[10])
self.ReviewStatusCode = trim(row[11])
self.TickleDate = date2str(row[12])
self.PubDate = date2str(row[13])
self.HomeURL = trim(row[14])
self.TechReviewStatusCode = trim(row[15])
self.Maintained = tf2bool(row[16])
self.maintainer_wanted = tf2bool(row[17])
self.license_code = trim(row[18])
self.Abstract = trim(row[19])
self.Rating = safeint(row[20])
self.Lang = trim(row[21])
self.sk_seriesid = trim(row[22])
self.Errs = DocErrs(self.ID)
self.Files = DocFiles(self.ID)
self.Ratings = DocRatings(self.ID)
self.Ratings.Parent = self
self.Versions = DocVersions(self.ID)
def load_row(self, row):
self.id = row[0]
self.title = trim(row[1])
self.type_code = trim(row[2])
self.format_code = trim(row[3])
self.dtd_code = trim(row[4])
self.dtd_version = trim(row[5])
self.version = trim(row[6])
self.last_update = date2str(row[7])
self.url = trim(row[8])
self.isbn = trim(row[9])
self.pub_status_code = trim(row[10])
self.review_status_code = trim(row[11])
self.tickle_date = date2str(row[12])
self.pub_date = date2str(row[13])
self.home_url = trim(row[14])
self.tech_review_status_code = trim(row[15])
self.maintained = tf2bool(row[16])
self.maintainer_wanted = tf2bool(row[17])
self.license_code = trim(row[18])
self.abstract = trim(row[19])
self.rating = safeint(row[20])
self.lang = trim(row[21])
self.sk_seriesid = trim(row[22])
self.errs = DocErrs(self.id)
self.files = DocFiles(self.id)
self.ratings = Docratings(self.id)
self.ratings.parent = self
self.versions = DocVersions(self.id)
def Save(self):
sql = "UPDATE document SET title=" + wsq(self.Title) + ", type_code=" + wsq(self.type_code) + ", format_code=" + wsq(self.format_code) + ", 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.PubStatusCode) + ", review_status=" + wsq(self.ReviewStatusCode) + ", tickle_date=" + wsq(self.TickleDate) + ", pub_date=" + wsq(self.PubDate) + ", ref_url=" + wsq(self.HomeURL) + ", tech_review_status=" + wsq(self.TechReviewStatusCode) + ", maintained=" + wsq(bool2tf(self.Maintained)) + ', maintainer_wanted=' + wsq(bool2tf(self.maintainer_wanted)) + ", license_code=" + wsq(self.license_code) + ", abstract=" + wsq(self.Abstract) + ", rating=" + dbint(self.Rating) + ", lang=" + wsq(self.Lang) + ", sk_seriesid=" + wsq(self.sk_seriesid) + " WHERE doc_id=" + str(self.ID)
def save(self):
sql = "UPDATE document SET title=" + wsq(self.title) + ", type_code=" + wsq(self.type_code) + ", format_code=" + wsq(self.format_code) + ", dtd_code=" + wsq(self.dtd_code) + ", dtd_version=" + wsq(self.dtd_version) + ", version=" + wsq(self.version) + ", last_update=" + wsq(self.last_update) + ", url=" + wsq(self.url) + ", isbn=" + wsq(self.isbn) + ", pub_status=" + wsq(self.pub_status_code) + ", review_status=" + wsq(self.review_status_code) + ", tickle_date=" + wsq(self.tickle_date) + ", pub_date=" + wsq(self.pub_date) + ", ref_url=" + wsq(self.home_url) + ", tech_review_status=" + wsq(self.tech_review_status_code) + ", maintained=" + wsq(bool2tf(self.maintained)) + ', maintainer_wanted=' + wsq(bool2tf(self.maintainer_wanted)) + ", license_code=" + wsq(self.license_code) + ", abstract=" + wsq(self.abstract) + ", rating=" + dbint(self.rating) + ", lang=" + wsq(self.lang) + ", sk_seriesid=" + wsq(self.sk_seriesid) + " WHERE doc_id=" + str(self.id)
db.runsql(sql)
db.commit()
# DocErrs
class DocErrs(LampadasList):
class DocErrs(LampadasCollection):
"""
A collection object providing access to all document errors, as identified by the
Lintadas subsystem.
"""
def __init__(self, DocID):
LampadasList.__init__(self)
assert not DocID==None
self.DocID = DocID
sql = "SELECT err_id FROM document_error WHERE doc_id=" + str(DocID)
def __init__(self, doc_id):
self.data = {}
self.doc_id = doc_id
sql = "SELECT doc_id, err_id FROM document_error WHERE doc_id=" + str(doc_id)
cursor = db.select(sql)
while (1):
row = cursor.fetchone()
if row==None: break
newDocErr = DocErr()
newDocErr.Load(DocID, row)
self.list = self.list + [newDocErr]
doc_err = DocErr()
doc_err.load(doc_id, row)
self.data[doc_err.id] = doc_err
def Clear(self):
sql = "DELETE FROM document_error WHERE doc_id=" + str(self.DocID)
def clear(self):
sql = "DELETE FROM document_error WHERE doc_id=" + str(self.doc_id)
db.runsql(sql)
db.commit()
self.list = []
self.data = {}
# FIXME: Try instantiating a DocErr object, then adding it to the *document*
# rather than passing all these parameters here.
def add(self, ErrID):
sql = "INSERT INTO document_error(doc_id, err_id) VALUES (" + str(self.DocID) + ", " + wsq(ErrID)
def add(self, error_id):
sql = "INSERT INTO document_error(doc_id, err_id) VALUES (" + str(self.doc_id) + ", " + wsq(error_id)
assert db.runsql(sql)==1
newDocErr = DocErr()
newDocErr.DocID = self.DocID
newDocErr.ErrID = ErrID
self.list = self.list + [newDocErr]
doc_err = DocErr()
doc_err.doc_id = self.doc_id
doc_err.error_id = error_id
self.data[doc_err.id] = doc_err
db.commit()
class DocErr:
@ -250,11 +246,9 @@ class DocErr:
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.ErrID = safeint(row[0])
def load(self, row):
self.doc_id = row[0]
self.error_id = safeint(row[1])
# DocFiles
@ -264,30 +258,30 @@ class DocFiles(LampadasCollection):
A collection object providing access to all document source files.
"""
def __init__(self, DocID):
def __init__(self, doc_id):
self.data = {}
assert not DocID==None
self.DocID = DocID
sql = "SELECT filename, format_code FROM document_file WHERE doc_id=" + str(DocID)
assert not doc_id==None
self.doc_id = doc_id
sql = "SELECT filename, format_code FROM document_file WHERE doc_id=" + str(doc_id)
cursor = db.select(sql)
while (1):
row = cursor.fetchone()
if row==None: break
newDocFile = DocFile()
newDocFile.Load(DocID, row)
newDocFile.load(doc_id, row)
self.data[newDocFile.Filename] = newDocFile
def add(self, DocID, Filename, format_code=None):
sql = 'INSERT INTO document_file (doc_id, filename, format_code) VALUES (' + str(DocID) + ', ' + wsq(Filename) + ', ' + wsq(format_code) + ')'
def add(self, doc_id, Filename, format_code=None):
sql = 'INSERT INTO document_file (doc_id, filename, format_code) VALUES (' + str(doc_id) + ', ' + wsq(Filename) + ', ' + wsq(format_code) + ')'
assert db.runsql(sql)==1
db.commit()
newDocFile = DocFile()
newDocFile.DocID = DocID
newDocFile.doc_id = doc_id
newDocFile.Filename = Filename
newDocFile.format_code = format_code
def Clear(self):
sql = "DELETE FROM document_file WHERE doc_id=" + str(self.DocID)
sql = "DELETE FROM document_file WHERE doc_id=" + str(self.doc_id)
db.runsql(sql)
db.commit()
self.data = {}
@ -299,10 +293,10 @@ class DocFile:
import os.path
def Load(self, DocID, row):
assert not DocID==None
def load(self, doc_id, row):
assert not doc_id==None
assert not row==None
self.DocID = DocID
self.doc_id = doc_id
self.Filename = trim(row[0])
self.format_code = trim(row[1])
if self.Filename[:5]=='http:' or self.Filename[:4]=='ftp:':
@ -316,20 +310,20 @@ class DocFile:
self.is_primary = self.IsLocal
def Save(self):
sql = "UPDATE document_file SET format_code=" + wsq(self.format_code) + " WHERE doc_id=" + str(self.DocID) + " AND filename=" + wsq(self.Filename)
def save(self):
sql = "UPDATE document_file SET format_code=" + wsq(self.format_code) + " WHERE doc_id=" + str(self.doc_id) + " AND filename=" + wsq(self.Filename)
db.runsql(sql)
db.commit()
def delete(self):
sql = "DELETE FROM document_file WHERE doc_id=" + str(self.DocID) + " AND filename=" + wsq(self.Filename)
sql = "DELETE FROM document_file WHERE doc_id=" + str(self.doc_id) + " AND filename=" + wsq(self.Filename)
db.runsql(sql)
db.commit()
# DocRatings
# Docratings
class DocRatings(LampadasCollection):
class Docratings(LampadasCollection):
"""
A collection object providing access to all ratings placed on documents by users.
"""
@ -344,18 +338,18 @@ class DocRatings(LampadasCollection):
while (1):
row = cursor.fetchone()
if row==None: break
newDocRating = DocRating()
newDocRating.load(row)
self.data[newDocRating.username] = newDocRating
newDocrating = Docrating()
newDocrating.load(row)
self.data[newDocrating.username] = newDocrating
self.calc_average()
def add(self, username, rating):
newDocRating = DocRating()
newDocRating.doc_id = self.doc_id
newDocRating.username = username
newDocRating.rating = rating
newDocRating.save()
self.data[newDocRating.username] = newDocRating
newDocrating = Docrating()
newDocrating.doc_id = self.doc_id
newDocrating.username = username
newDocrating.rating = rating
newDocrating.save()
self.data[newDocrating.username] = newDocrating
self.calc_average()
def delete(self, username):
@ -382,7 +376,7 @@ class DocRatings(LampadasCollection):
if not self.parent==None:
self.parent.pating = self.average
class DocRating:
class Docrating:
"""
A rating of a document, assigned by a registered user.
"""
@ -409,36 +403,36 @@ class DocVersions(LampadasCollection):
A collection object providing access to document revisions.
"""
def __init__(self, DocID):
def __init__(self, doc_id):
LampadasCollection.__init__(self)
assert not DocID==None
self.DocID = DocID
sql = "SELECT rev_id, version, pub_date, initials, notes FROM document_rev WHERE doc_id=" + str(DocID)
assert not doc_id==None
self.doc_id = doc_id
sql = "SELECT rev_id, version, pub_date, initials, notes FROM document_rev WHERE doc_id=" + str(doc_id)
cursor = db.select(sql)
while (1):
row = cursor.fetchone()
if row==None: break
newDocVersion = DocVersion()
newDocVersion.Load(DocID, row)
self.data[newDocVersion.ID] = newDocVersion
doc_version = DocVersion()
doc_version.load(doc_id, row)
self.data[doc_version.id] = doc_version
class DocVersion:
"""
A release of the document.
"""
def Load(self, DocID, row):
assert not DocID==None
def load(self, doc_id, row):
assert not doc_id==None
assert not row==None
self.DocID = DocID
self.ID = row[0]
self.Version = trim(row[1])
self.PubDate = date2str(row[2])
self.doc_id = doc_id
self.id = row[0]
self.version = trim(row[1])
self.pub_date = date2str(row[2])
self.Initials = trim(row[3])
self.Notes = trim(row[4])
def Save(self):
sql = "UPDATE document_rev SET version=" + wsq(self.Version) + ", pub_date=" + wsq(self.PubDate) + ", initials=" + wsq(self.Initials) + ", notes=" + wsq(self.Notes) + "WHERE doc_id=" + str(self.DocID) + " AND rev_id" + wsq(self.ID)
def save(self):
sql = "UPDATE document_rev SET version=" + wsq(self.version) + ", pub_date=" + wsq(self.pub_date) + ", initials=" + wsq(self.Initials) + ", notes=" + wsq(self.Notes) + "WHERE doc_id=" + str(self.doc_id) + " AND rev_id" + wsq(self.id)
assert db.runsql(sql)==1
db.commit()
@ -499,26 +493,26 @@ class DTDs(LampadasCollection):
def __init__(self):
self.data = {}
sql = "SELECT dtd from dtd"
sql = "SELECT dtd_code from dtd"
cursor = db.select(sql)
while (1):
row = cursor.fetchone()
if row==None: break
newDTD = DTD()
newDTD.Load(row)
self.data[newDTD.DTD] = newDTD
newDTD.load(row)
self.data[newDTD.dtd_code] = newDTD
class DTD:
"""
A Data Type Definition, for SGML and XML documents.
"""
def __init__(self, DTD=None):
if DTD==None: return
self.DTD = DTD
def __init__(self, dtd_code=None):
if dtd_code==None: return
self.dtd_code = dtd_code
def Load(self, row):
self.DTD = trim(row[0])
def load(self, row):
self.dtd_code = trim(row[0])
# Errs
@ -536,23 +530,23 @@ class Errs(LampadasCollection):
row = cursor.fetchone()
if row==None: break
newErr = Err()
newErr.Load(row)
self.data[newErr.ErrID] = newErr
newErr.load(row)
self.data[newErr.err_id] = newErr
class Err:
"""
An error that can be filed against a document.
"""
def __init__(self, ErrID=None):
def __init__(self, err_id=None):
self.name = LampadasCollection()
self.description = LampadasCollection()
if Err==None: return
self.ErrID = ErrID
self.err_id = err_id
def Load(self, row):
self.ErrID = trim(row[0])
sql = "SELECT lang, err_name, err_desc FROM error_i18n WHERE err_id=" + wsq(self.ErrID)
def load(self, row):
self.err_id = trim(row[0])
sql = "SELECT lang, err_name, err_desc FROM error_i18n WHERE err_id=" + wsq(self.err_id)
cursor = db.select(sql)
while (1):
row = cursor.fetchone()
@ -577,7 +571,7 @@ class Formats(LampadasCollection):
row = cursor.fetchone()
if row==None: break
newFormat = Format()
newFormat.Load(row)
newFormat.load(row)
self.data[newFormat.code] = newFormat
class Format:
@ -591,7 +585,7 @@ class Format:
if format_code==None: return
self.code = format_code
def Load(self, row):
def load(self, row):
self.code = trim(row[0])
sql = "SELECT lang, format_name, format_desc FROM format_i18n WHERE format_code=" + wsq(self.code)
cursor = db.select(sql)
@ -663,8 +657,8 @@ class PubStatuses(LampadasCollection):
row = cursor.fetchone()
if row==None: break
newPubStatus = PubStatus()
newPubStatus.Load(row)
self.data[newPubStatus.Code] = newPubStatus
newPubStatus.load(row)
self.data[newPubStatus.code] = newPubStatus
class PubStatus:
"""
@ -672,16 +666,16 @@ class PubStatus:
document is.
"""
def __init__(self, PubStatusCode=None):
def __init__(self, pub_status_code=None):
self.name = LampadasCollection()
self.description = LampadasCollection()
if PubStatusCode==None: return
self.Code = PubStatusCode
if pub_status_code==None: return
self.code = pub_status_code
def Load(self, row):
self.Code = trim(row[0])
def load(self, row):
self.code = trim(row[0])
self.sort_order = row[1]
sql = "SELECT lang, pub_status_name, pub_status_desc FROM pub_status_i18n WHERE pub_status=" + wsq(self.Code)
sql = "SELECT lang, pub_status_name, pub_status_desc FROM pub_status_i18n WHERE pub_status=" + wsq(self.code)
cursor = db.select(sql)
while (1):
row = cursor.fetchone()
@ -705,26 +699,26 @@ class ReviewStatuses(LampadasCollection):
while (1):
row = cursor.fetchone()
if row==None: break
newReviewStatus = ReviewStatus()
newReviewStatus.Load(row)
self.data[newReviewStatus.Code] = newReviewStatus
review_status = ReviewStatus()
review_status.load(row)
self.data[review_status.code] = review_status
class ReviewStatus:
"""
The Reviewlication Status defines where in the publication process a
The Review Status defines where in the review process a
document is.
"""
def __init__(self, ReviewStatusCode=None):
def __init__(self, review_status_code=None):
self.name = LampadasCollection()
self.description = LampadasCollection()
if ReviewStatusCode==None: return
self.Code = ReviewStatusCode
if review_status_code==None: return
self.code = review_status_code
def Load(self, row):
self.Code = trim(row[0])
def load(self, row):
self.code = trim(row[0])
self.sort_order = row[1]
sql = "SELECT lang, review_status_name, review_status_desc FROM review_status_i18n WHERE review_status=" + wsq(self.Code)
sql = "SELECT lang, review_status_name, review_status_desc FROM review_status_i18n WHERE review_status=" + wsq(self.code)
cursor = db.select(sql)
while (1):
row = cursor.fetchone()
@ -749,7 +743,7 @@ class Topics(LampadasCollection):
row = cursor.fetchone()
if row==None: break
newTopic = Topic()
newTopic.Load(row)
newTopic.load(row)
self.data[newTopic.code] = newTopic
class Topic:
@ -759,14 +753,14 @@ class Topic:
to help them find a document on the subject in which they are interested.
"""
def __init__(self, TopicCode=None, TopicNum=None):
def __init__(self, topic_code=None, TopicNum=None):
self.name = LampadasCollection()
self.description = LampadasCollection()
if TopicCode==None: return
self.code = TopicCode
if topic_code==None: return
self.code = topic_code
self.num = TopicNum
def Load(self, row):
def load(self, row):
self.code = trim(row[0])
self.num = safeint(row[1])
sql = "SELECT lang, topic_name, topic_desc FROM topic_i18n WHERE topic_code=" + wsq(self.code)

View File

@ -125,3 +125,28 @@ def trim(astring):
return temp.strip()
class WOStringIO:
"""
Write-Only pure python extra fast buffer.
String concatenation is kinda slow. Use class WOStringIO instead:
buf = WOStringIO()
buf.write('some piece of <HTML>')
buf.write('some other %s' % 'variable-value')
buf.get_value()
N.B: same interface as StringIO.
--nico
"""
def __init__(self,s='') :
self.data = [s]
def write(self,s) :
self.data.append(s)
def get_value(self) :
return ''.join(self.data)

View File

@ -23,32 +23,8 @@ Lampadas HTML Primitives Module
This module generates HTML primitives and web pages for the WWW front-end
to the Lampadas system.
FIXME: string concatenation is kinda slow. Use class WOStringIO instead.
As in
buf = WOStringIO()
buf.write('some piece of <HTML>')
buf.write('some other %s' % 'variable-value')
buf.get_value()
N.B: same interface as StringIO.
--nico
"""
class WOStringIO :
"Write-Only pure python extra fast buffer"
def __init__(self,s='') :
self.data = [s]
def write(self,s) :
self.data.append(s)
def get_value(self) :
return ''.join(self.data)
# Modules ##################################################################
from Globals import *
@ -111,61 +87,61 @@ class ComboFactory:
def doc(self, value, lang):
combo = "<select name='doc'>\n"
keys = lampadas.Docs.sort_by_lang('Title', lang)
keys = lampadas.docs.sort_by_lang('title', lang)
for key in keys:
doc = lampadas.Docs[key]
doc = lampadas.docs[key]
assert not doc==None
if doc.Lang==lang or lang==None:
if doc.lang==lang or lang==None:
combo = combo + "<option "
if doc.ID==value:
if doc.id==value:
combo = combo + "selected "
combo = combo + "value='" + str(doc.ID) + "'>"
combo = combo + doc.Title
combo = combo + "value='" + str(doc.id) + "'>"
combo = combo + doc.title
combo = combo + "</option>\n"
combo = combo + "</select>"
return combo
def sk_seriesid(self, value, lang):
combo = "<select name='sk_seriesid'>\n"
keys = lampadas.Docs.sort_by_lang('Title', lang)
keys = lampadas.docs.sort_by_lang('title', lang)
for key in keys:
doc = lampadas.Docs[key]
doc = lampadas.docs[key]
assert not doc==None
if doc.Lang==lang or lang==None:
if doc.lang==lang or lang==None:
combo = combo + "<option "
if doc.sk_seriesid==value:
combo = combo + "selected "
combo = combo + "value='" + str(doc.sk_seriesid) + "'>"
combo = combo + doc.Title
combo = combo + doc.title
combo = combo + "</option>\n"
combo = combo + "</select>"
return combo
def dtd(self, value, lang):
combo = "<select name='dtd'>\n"
keys = lampadas.DTDs.sort_by_lang('DTD', lang)
keys = lampadas.dtds.sort_by_lang('DTD', lang)
for key in keys:
dtd = lampadas.DTDs[key]
dtd = lampadas.dtds[key]
assert not dtd==None
combo = combo + "<option "
if dtd.DTD==value:
if dtd.dtd_code==value:
combo = combo + "selected "
combo = combo + "value='" + dtd.DTD + "'>"
combo = combo + dtd.DTD
combo = combo + "value='" + dtd.dtd_code + "'>"
combo = combo + dtd.dtd_code
combo = combo + "</option>\n"
combo = combo + "</select>"
return combo
def format(self, value, lang):
combo = "<select name='format'>\n"
keys = lampadas.Formats.sort_by_lang('name', lang)
keys = lampadas.formats.sort_by_lang('name', lang)
for key in keys:
format = lampadas.Formats[key]
format = lampadas.formats[key]
assert not format==None
combo = combo + "<option "
if format.ID==value:
if format.id==value:
combo = combo + "selected "
combo = combo + "value='" + str(format.ID) + "'>"
combo = combo + "value='" + str(format.id) + "'>"
combo = combo + format.name[lang]
combo = combo + "</option>\n"
combo = combo + "</select>"
@ -208,9 +184,9 @@ class ComboFactory:
page = lampadasweb.pages[key]
assert not page==None
combo = combo + "<option "
if Page.Code==value:
if Page.code==value:
combo = combo + "selected "
combo = combo + "value='" + str(page.Code) + "'>"
combo = combo + "value='" + str(page.code) + "'>"
combo = combo + page.title[lang]
combo = combo + "</option>\n"
combo = combo + "</select>"
@ -218,14 +194,14 @@ class ComboFactory:
def pub_status(self, value, lang):
combo = "<select name='pub_status_code'>\n"
keys = lampadas.PubStatuses.sort_by('sort_order')
keys = lampadas.pub_statuses.sort_by('sort_order')
for key in keys:
PubStatus = lampadas.PubStatuses[key]
PubStatus = lampadas.pub_statuses[key]
assert not PubStatus==None
combo = combo + "<option "
if PubStatus.Code==value:
if PubStatus.code==value:
combo = combo + "selected "
combo = combo + "value='" + str(PubStatus.Code) + "'>"
combo = combo + "value='" + str(PubStatus.code) + "'>"
combo = combo + PubStatus.name[lang]
combo = combo + "</option>\n"
combo = combo + "</select>"
@ -233,30 +209,30 @@ class ComboFactory:
def review_status(self, value, lang):
combo = "<select name='review_status_code'>\n"
keys = lampadas.ReviewStatuses.sort_by('sort_order')
keys = lampadas.review_statuses.sort_by('sort_order')
for key in keys:
ReviewStatus = lampadas.ReviewStatuses[key]
assert not ReviewStatus==None
review_status = lampadas.review_statuses[key]
assert not review_status==None
combo = combo + "<option "
if ReviewStatus.Code==value:
if review_status.code==value:
combo = combo + "selected "
combo = combo + "value='" + str(ReviewStatus.Code) + "'>"
combo = combo + ReviewStatus.name[lang]
combo = combo + "value='" + str(review_status.code) + "'>"
combo = combo + review_status.name[lang]
combo = combo + "</option>\n"
combo = combo + "</select>"
return combo
def tech_review_status(self, value, lang):
combo = "<select name='tech_review_status_code'>\n"
keys = lampadas.ReviewStatuses.sort_by('sort_order')
keys = lampadas.review_statuses.sort_by('sort_order')
for key in keys:
ReviewStatus = lampadas.ReviewStatuses[key]
assert not ReviewStatus==None
review_status = lampadas.review_statuses[key]
assert not review_status==None
combo = combo + "<option "
if ReviewStatus.Code==value:
if review_status.code==value:
combo = combo + "selected "
combo = combo + "value='" + str(ReviewStatus.Code) + "'>"
combo = combo + ReviewStatus.name[lang]
combo = combo + "value='" + str(review_status.code) + "'>"
combo = combo + review_status.name[lang]
combo = combo + "</option>\n"
combo = combo + "</select>"
return combo
@ -284,82 +260,82 @@ class TableFactory:
def doc(self, uri):
if uri.id:
doc = lampadas.Docs[uri.id]
doc = lampadas.docs[uri.id]
box = '<form method=GET action="data/save/document" name="document">'
else:
doc = Doc()
box = '<form method=GET action="data/save/newdocument" name="document">'
box = box + '<input name="doc_id" type=hidden value=' + str(doc.ID) + '>\n'
box = box + '<input name="doc_id" type=hidden value=' + str(doc.id) + '>\n'
box = box + '<table class="box"><tr><th colspan="6">|strdocdetails|</th></tr>'
box = box + '<tr>\n'
box = box + '<th class="label">|strtitle|</th><td colspan=5><input type=text name="title" size=60 style="width:100%" value="' + doc.Title + '"></td>\n'
box = box + '<th class="label">|strtitle|</th><td colspan=5><input type=text name="title" size=60 style="width:100%" value="' + doc.title + '"></td>\n'
box = box + '</tr>\n'
box = box + '<tr>\n'
box = box + '<th class="label">'
if doc.URL:
box = box + '<a href="' + doc.URL + '">|strurl|</a>'
if doc.url:
box = box + '<a href="' + doc.url + '">|strurl|</a>'
else:
box = box + '|strurl|'
box = box + '</th><td colspan=5><input type=text name="url" size=60 style="width:100%" value="' + doc.URL + '"></td>'
box = box + '</th><td colspan=5><input type=text name="url" size=60 style="width:100%" value="' + doc.url + '"></td>'
box = box + '</tr>\n<tr>\n'
box = box + '<th class="label">'
if doc.HomeURL:
box = box + '<a href="' + doc.HomeURL + '">|strhome_url|</a>'
if doc.home_url:
box = box + '<a href="' + doc.home_url + '">|strhome_url|</a>'
else:
box = box + '|strhome_url|'
box = box + '</th><td colspan=5><input type=text name="ref_url" size=60 style="width:100%" value="' + doc.HomeURL + '"></td>'
box = box + '</th><td colspan=5><input type=text name="ref_url" size=60 style="width:100%" value="' + doc.home_url + '"></td>'
box = box + '</tr>\n<tr>\n'
box = box + '<th class="label">|strstatus|</th><td>'
box = box + combo_factory.pub_status(doc.PubStatusCode, uri.lang)
box = box + combo_factory.pub_status(doc.pub_status_code, uri.lang)
box = box + '</td>\n'
box = box + '<th class="label">|strtype|</th><td>\n'
box = box + combo_factory.type(doc.type_code, uri.lang)
box = box + '</td>\n'
box = box + '<th class="label">|strmaintained|</th><td>\n'
if doc.Maintained:
if doc.maintained:
box = box + '|stryes|'
else:
box = box + '|strno|'
box = box + '</td>'
box = box + '</tr>\n<tr>\n'
box = box + '<th class="label">|strwriting|</th><td>'
box = box + combo_factory.review_status(doc.ReviewStatusCode, uri.lang)
box = box + combo_factory.review_status(doc.review_status_code, uri.lang)
box = box + '</td>\n'
box = box + '<th class="label">|straccuracy|</th><td>'
box = box + combo_factory.tech_review_status(doc.TechReviewStatusCode, uri.lang)
box = box + combo_factory.tech_review_status(doc.tech_review_status_code, uri.lang)
box = box + '</td>\n'
box = box + '<th class="label">|strlicense|</th><td>'
box = box + combo_factory.license(doc.license_code, uri.lang)
box = box + '</td>'
box = box + '</tr>\n<tr>\n'
box = box + '<th class="label">|strpub_date|</th><td><input type=text name="pub_date" size=10 value="' + doc.PubDate + '"></td>'
box = box + '<th class="label">|strupdated|</th><td><input type=text name="last_update" size=10 value="' + doc.LastUpdate + '"></td>'
box = box + '<th class="label">|strversion|</th><td><input type=text name="version" size=10 value="' + doc.Version + '"></td>'
box = box + '<th class="label">|strpub_date|</th><td><input type=text name="pub_date" size=10 value="' + doc.pub_date + '"></td>'
box = box + '<th class="label">|strupdated|</th><td><input type=text name="last_update" size=10 value="' + doc.last_update + '"></td>'
box = box + '<th class="label">|strversion|</th><td><input type=text name="version" size=10 value="' + doc.version + '"></td>'
box = box + '</tr>\n<tr>\n'
box = box + '<th class="label">|strtickle_date|</th><td><input type=text name="tickle_date" size=10 value="' + doc.TickleDate + '"></td>'
box = box + '<th class="label">|strisbn|</th><td><input type=text name="isbn" size=14 value="' + doc.ISBN + '"></td>'
box = box + '<th class="label">|strtickle_date|</th><td><input type=text name="tickle_date" size=10 value="' + doc.tickle_date + '"></td>'
box = box + '<th class="label">|strisbn|</th><td><input type=text name="isbn" size=14 value="' + doc.isbn + '"></td>'
box = box + '<th class="label">|strrating|</th>\n'
box = box + '<td>'
box = box + self.bar_graph(doc.Rating, 10, uri.lang)
box = box + self.bar_graph(doc.rating, 10, uri.lang)
box = box + '</td>\n'
box = box + '</tr>\n<tr>\n'
box = box + '<th class="label">|strformat|</th><td>'
box = box + lampadas.Formats[doc.format_code].name[uri.lang]
box = box + lampadas.formats[doc.format_code].name[uri.lang]
box = box + '</td>'
box = box + '<th class="label">|strdtd|</th><td>'
box = box + doc.DTD + ' ' + doc.DTDVersion
box = box + doc.dtd_code + ' ' + doc.dtd_version
box = box + '</td>'
box = box + '<th class="label">|strlanguage|</th><td>'
box = box + combo_factory.language(doc.Lang, uri.lang)
box = box + combo_factory.language(doc.lang, uri.lang)
box = box + '</td>'
box = box + '</tr>\n<tr>\n'
box = box + '<th class="label">|strmaintainer_wanted|</th><td>' + combo_factory.tf('maintainer_wanted', doc.maintainer_wanted, uri.lang) + '</td>\n'
box = box + '<th class="label">|strmaint_wanted|</th><td>' + combo_factory.tf('maintainer_wanted', doc.maintainer_wanted, uri.lang) + '</td>\n'
box = box + '<td></td><td></td>'
box = box + '</tr>\n<tr>\n'
box = box + '<th class="label">|strabstract|</th>'
box = box + '<td colspan=5><textarea name="abstract" rows=6 cols=40 style="width:100%" wrap>' + doc.Abstract + '</textarea></td>\n'
box = box + '<td colspan=5><textarea name="abstract" rows=6 cols=40 style="width:100%" wrap>' + doc.abstract + '</textarea></td>\n'
box = box + '</tr>\n'
box = box + '<tr><td></td><td><input type=submit name="save" value="|strsave|"></td></tr>\n'
box = box + '</table>\n'
@ -368,7 +344,7 @@ class TableFactory:
return box
def cvslog(self, uri):
doc = lampadas.Docs[uri.id]
doc = lampadas.docs[uri.id]
box = '<table class="box">\n'
box = box + '<tr><th>|strcvslog|</th></tr>\n'
box = box + '<tr><td>\n'
@ -400,7 +376,7 @@ class TableFactory:
box = box + '<tr><th class="label">|strnewpassword|</th><td><input type=text name=password></input></td></tr>\n'
box = box + '<tr><th class="label">|stradmin|</th><td>' + combo_factory.tf('admin', user.admin, uri.lang) + '</td></tr>\n'
box = box + '<tr><th class="label">|strsysadmin|</th><td>' + combo_factory.tf('sysadmin', user.sysadmin, uri.lang) + '</td></tr>\n'
box = box + '<tr><td></td><td><input type=submit name=save value=Save></td></tr>\n'
box = box + '<tr><td></td><td><input type=submit name=save value=|strsave|></td></tr>\n'
box = box + '</form>\n'
box = box + '</table>\n'
return box
@ -408,23 +384,23 @@ class TableFactory:
def doctable(self, uri, user, type_code=None, subtopic_code=None):
log(3, "Creating doctable")
box = '<table class="box"><tr><th colspan="2">|strtitle|</th></tr>'
keys = lampadas.Docs.sort_by("Title")
keys = lampadas.docs.sort_by("title")
for key in keys:
doc = lampadas.Docs[key]
if doc.Lang==uri.lang:
doc = lampadas.docs[key]
if doc.lang==uri.lang:
ok = 1
if type_code and doc.type_code <> type_code:
ok = 0
if subtopic_code:
subtopic = lampadas.subtopics[subtopic_code]
if subtopic.docs[doc.ID]==None:
if subtopic.docs[doc.id]==None:
ok = 0
if ok > 0:
box = box + '<tr><td>'
if user and user.can_edit(doc_id=doc.ID):
box = box + '<a href="editdoc/' + str(doc.ID) + '/">' + EDIT_ICON + '</a>'
if user and user.can_edit(doc_id=doc.id):
box = box + '<a href="editdoc/' + str(doc.id) + '/">' + EDIT_ICON + '</a>'
box = box + '</td>\n'
box = box + '<td style="width:100%"><a href="doc/' + str(doc.ID) + '/">' + doc.Title + '</a></td>'
box = box + '<td style="width:100%"><a href="doc/' + str(doc.id) + '/">' + doc.title + '</a></td>'
box = box + '</tr>\n'
box = box + '</table>'
return box
@ -518,12 +494,12 @@ class TableFactory:
box = '<table class="navbox"><tr><th>' + subtopic.name[uri.lang] + '</th></tr>\n'
box = box + '<tr><td>' + subtopic.description[uri.lang] + '</td></tr>\n'
box = box + '<tr><td><ol>\n'
keys = subtopic.docs.sort_by('Title')
keys = subtopic.docs.sort_by('title')
for key in keys:
doc = subtopic.docs[key]
if doc.subtopic.topic_code==uri.code and doc.Lang==uri.lang:
box = box + '<li><a href="/doc/' + str(doc.ID) + '">\n'
box = box + doc.Title + '</a>\n'
if doc.subtopic.topic_code==uri.code and doc.lang==uri.lang:
box = box + '<li><a href="/doc/' + str(doc.id) + '">\n'
box = box + doc.title + '</a>\n'
box = box + '</ol></td></tr>\n'
box = box + '</table>\n'
return box
@ -598,11 +574,11 @@ class TableFactory:
def user_docs(self, uri, user):
log(3, 'Creating user_docs table')
box = '<table class="navbox"><tr><th>|session_name|</th></tr>\n'
keys = user.docs.sort_by_lang('Title', uri.lang)
keys = user.docs.sort_by_lang('title', uri.lang)
for key in keys:
box = box + '<tr><td>\n'
userdoc = user.docs[key]
box = box + '<a href="/doc/' + userdoc.ID + '">' + usrdoc.title[uri.lang] + '</a>\n'
box = box + '<a href="/doc/' + userdoc.id + '">' + usrdoc.title[uri.lang] + '</a>\n'
box = box + '</td></tr>\n'
box = box + '</table>\n'
return box
@ -794,15 +770,32 @@ class PageFactory:
page_factory = PageFactory()
combo_factory = ComboFactory()
def profile():
import profile
profile_reps = 100
def benchmark(url, reps):
for x in range(0, reps):
page = page_factory.page(url)
profile.run('page_factory.page("home")')
def main():
import profile
if len(sys.argv[1:]):
profile_it = 0
reps_flag = 0
for arg in sys.argv[1:]:
print page_factory.page(arg)
if reps_flag:
profile_reps = int(arg)
reps_flag = 0
elif arg=='-p' or arg=='--profile':
profile_it = 1
elif arg=='-r' or arg=='--reps':
reps_flag = 1
elif profile_it > 0:
print 'Profiling, ' + str(profile_reps) + ' repetitions...'
page = page_factory.page(arg)
profile.run('benchmark("' + arg + '", ' + str(profile_reps) + ')')
else:
print page_factory.page(arg)
else:
profile()

View File

@ -45,21 +45,21 @@ import os
class Lintadas:
def CheckAllDocs(self):
keys = lampadas.Docs.keys()
keys = lampadas.docs.keys()
for key in keys:
self.CheckDoc(key)
def CheckDoc(self, DocID):
log(3, 'Running Lintadas on document ' + str(DocID))
Doc = lampadas.Docs[int(DocID)]
def CheckDoc(self, doc_id):
log(3, 'Running Lintadas on document ' + str(doc_id))
Doc = lampadas.docs[int(doc_id)]
assert not Doc==None
Doc.Errs.Clear()
Doc.errs.Clear()
# Test document files
keys = Doc.Files.keys()
keys = Doc.files.keys()
for key in keys:
File = Doc.Files[key]
File = Doc.files[key]
if File.IsLocal:
log(3, 'Checking filename ' + key)
@ -82,38 +82,38 @@ class Lintadas:
FileFormat = ''
DocFormat = ''
formatkeys = lampadas.Formats.keys()
formatkeys = lampadas.formats.keys()
for formatkey in formatkeys:
if lampadas.Formats[formatkey].I18n['EN'].Name==FileFormat:
File.FormatID = formatkey
if lampadas.Formats[formatkey].I18n['EN'].Name==DocFormat:
Doc.FormatID = formatkey
if lampadas.formats[formatkey].I18n['EN'].Name==FileFormat:
File.Formatid = formatkey
if lampadas.formats[formatkey].I18n['EN'].Name==DocFormat:
Doc.Formatid = formatkey
log(3, 'file format is ' + FileFormat)
# Determine DTD for SGML and XML files
if FileFormat=='XML' or FileFormat=='SGML':
DTDVersion = ''
dtd_version = ''
try:
command = 'grep -i DOCTYPE ' + config.cvs_root + File.Filename + ' | head -n 1'
grep = os.popen(command, 'r')
DTDVersion = grep.read()
dtd_version = grep.read()
except IOError:
pass
DTDVersion = DTDVersion.upper()
if DTDVersion.count('DOCBOOK') > 0:
Doc.DTD = 'DocBook'
elif DTDVersion.count('LINUXDOC') > 0:
Doc.DTD = 'LinuxDoc'
dtd_version = dtd_version.upper()
if dtd_version.count('DOCBOOK') > 0:
Doc.dtd_code = 'DocBook'
elif dtd_version.count('LINUXDOC') > 0:
Doc.dtd_code = 'LinuxDoc'
else:
Doc.DTD = ''
Doc.dtd_code = ''
log(3, 'doc dtd is ' + Doc.DTD)
log(3, 'doc dtd is ' + Doc.dtd_code)
Doc.Save()
File.Save()
log(3, 'Lintadas run on document ' + str(DocID) + ' complete')
Doc.save()
File.save()
log(3, 'Lintadas run on document ' + str(doc_id) + ' complete')
lintadas = Lintadas()

View File

@ -46,20 +46,20 @@ class Makefile:
def write_all(self):
log(3, 'Writing Makefile for all documents')
for dockey in lampadas.Docs.keys():
for dockey in lampadas.docs.keys():
self.write_doc(dockey)
self.write_main_makefile()
def write_doc(self, DocID):
log(3, 'Writing Makefile for document ' + str(DocID))
self.Doc = lampadas.Docs[DocID]
def write_doc(self, doc_id):
log(3, 'Writing Makefile for document ' + str(doc_id))
self.Doc = lampadas.docs[doc_id]
# Determine where files live
#
self.cachedir = config.cache_dir + str(self.Doc.ID) + '/'
self.cachedir = config.cache_dir + str(self.Doc.id) + '/'
self.write_makefile(self.Doc, self.cachedir)
log(3, 'Writing Makefile for document ' + str(DocID) + ' complete.')
log(3, 'Writing Makefile for document ' + str(doc_id) + ' complete.')
def write_makefile(self, doc, dir):
@ -67,8 +67,8 @@ class Makefile:
Writes a Makefile to convert the source files into DocBook XML.
"""
for file in doc.Files.keys():
File = doc.Files[file]
for file in doc.files.keys():
File = doc.files[file]
if File.is_primary:
dbsgmlfile = File.basename + '.db.sgml'
xmlfile = File.basename + '.xml'
@ -78,21 +78,21 @@ class Makefile:
omffile = File.basename + '.omf'
Makefile = 'xmlfile = ' + xmlfile + "\n\n"
if File.FormatID==1 and doc.DTD=='DocBook':
if File.Formatid==1 and doc.dtd_code=='DocBook':
Makefile = Makefile + 'BUILD_XML = xmllint --sgml ' + File.file_only + ' > ' + xmlfile + " 2>>xmllint.log; "
elif File.FormatID==1 and doc.DTD=='LinuxDoc':
elif File.Formatid==1 and doc.dtd_code=='LinuxDoc':
Makefile = Makefile + 'LD2DBDIR = /usr/local/share/ld2db/' + "\n"
Makefile = Makefile + 'BUILD_XML = sgmlnorm -d $(LD2DBDIR)docbook.dcl ' + File.file_only + ' > expanded.sgml 2>>sgmlnorm.log; '
Makefile = Makefile + 'jade -t sgml -c $(LD2DBDIR)catalog -d $(LD2DBDIR)ld2db.dsl\\#db expanded.sgml > ' + dbsgmlfile + ' 2>>jade.log; '
Makefile = Makefile + 'xmllint --sgml ' + dbsgmlfile + ' > ' + xmlfile + " 2>>xmllint.log; "
elif File.FormatID==4 and doc.DTD=='DocBook':
elif File.Formatid==4 and doc.dtd_code=='DocBook':
pass
elif File.FormatID==3:
elif File.Formatid==3:
Makefile = Makefile + 'BUILD_XML = wt2db -n -s ' + File.file_only + ' -o ' + dbsgmlfile + " 2>>wt2db.log; "
Makefile = Makefile + 'xmllint --sgml ' + dbsgmlfile + ' > ' + xmlfile + " 2>>xmllint.log; "
elif File.FormatID==6:
elif File.Formatid==6:
Makefile = Makefile + 'BUILD_XML = wt2db -n -x ' + File.file_only + ' -o ' + xmlfile + " 2>>wt2db.log; "
elif File.FormatID==7:
elif File.Formatid==7:
Makefile = Makefile + 'BUILD_XML = texi2db -f ' + File.file_only + ' -o ' + xmlfile + " 2>>texi2db.log; "
else:
continue
@ -107,7 +107,7 @@ class Makefile:
Makefile = Makefile + "all:\tbuild\n\n"
Makefile = Makefile + "build:\txml html index txt omf\n\n"
if File.FormatID==4 and doc.DTD=='DocBook':
if File.Formatid==4 and doc.dtd_code=='DocBook':
Makefile = Makefile + "xml:\n\n"
else:
Makefile = Makefile + "xml:\t" + xmlfile + "\n\n"
@ -159,12 +159,12 @@ class Makefile:
cleanmake = ''
rebuildmake = ''
makeneeded = 0
for docid in lampadas.Docs.keys():
Doc = lampadas.Docs[docid]
for file in Doc.Files.keys():
File = Doc.Files[file]
for docid in lampadas.docs.keys():
Doc = lampadas.docs[docid]
for file in Doc.files.keys():
File = Doc.files[file]
if File.is_primary:
if (File.FormatID==1 and Doc.DTD=='DocBook') or (File.FormatID==1 and Doc.DTD=='LinuxDoc') or File.FormatID==3 or File.FormatID==6 or File.FormatID==7:
if (File.Formatid==1 and Doc.dtd_code=='DocBook') or (File.Formatid==1 and Doc.dtd_code=='LinuxDoc') or File.Formatid==3 or File.Formatid==6 or File.Formatid==7:
makeneeded = 1
docsmake = docsmake + "\tcd " + str(docid) + "; $(MAKE) -i all 2>>make.log\n"
xmlmake = xmlmake + "\tcd " + str(docid) + "; $(MAKE) -i xml 2>>make.log\n"

View File

@ -45,28 +45,28 @@ class Mirror:
def mirror_all(self):
log(3, 'Mirroring all documents')
for dockey in lampadas.Docs.keys():
for dockey in lampadas.docs.keys():
self.mirror_doc(dockey)
def mirror_doc(self, DocID):
log(3, 'Mirroring document ' + str(DocID))
self.Doc = lampadas.Docs[DocID]
def mirror_doc(self, doc_id):
log(3, 'Mirroring document ' + str(doc_id))
self.Doc = lampadas.docs[doc_id]
# decide if the document is remote
#
self.is_remote = 0
filekeys = self.Doc.Files.keys()
filekeys = self.Doc.files.keys()
for filekey in filekeys:
if not self.Doc.Files[filekey].IsLocal:
if not self.Doc.files[filekey].IsLocal:
self.is_remote = 1
# delete list of local files if document is remote
#
if self.is_remote:
filekeys = self.Doc.Files.keys()
filekeys = self.Doc.files.keys()
for filekey in filekeys:
if self.Doc.Files[filekey].IsLocal:
self.Doc.Files[filekey].Del()
if self.Doc.files[filekey].IsLocal:
self.Doc.files[filekey].Del()
# mirror all files into cache, whether from remote
# or local storage
@ -79,11 +79,11 @@ class Mirror:
# create cache directory for this document
#
self.cachedir = config.cache_dir + str(self.Doc.ID) + '/'
self.cachedir = config.cache_dir + str(self.Doc.id) + '/'
if not self.os.access(self.cachedir, self.os.F_OK):
self.os.mkdir(self.cachedir)
self.File = self.Doc.Files[filekey]
self.File = self.Doc.files[filekey]
self.filename = self.File.Filename
self.file_only = self.File.file_only
self.cachename = self.cachedir + self.file_only
@ -112,9 +112,9 @@ class Mirror:
if self.unpack(self.cachedir, self.file_only):
for file in self.os.listdir(self.cachedir):
if file[-5:] <> '.html':
self.Doc.Files.add(self.Doc.ID, file)
self.Doc.files.add(self.Doc.id, file)
log(3, 'Mirroring document ' + str(DocID) + ' complete.')
log(3, 'Mirroring document ' + str(doc_id) + ' complete.')
def unpack(self, dir, file):

View File

@ -137,7 +137,7 @@ class URI:
print "Path: [" + self.path + "]"
print "Language: [" + self.lang + "]"
print "Forced Language: [" + str(self.force_lang) + "]"
print "ID [" + str(self.id) + "]"
print "ID: [" + str(self.id) + "]"
print "Code [" + str(self.code) + "]"
print "Format [" + str(self.format) + "]"
print "Filename: [" + self.filename + "]"

View File

@ -88,75 +88,75 @@ class testDocs(unittest.TestCase):
def testDocs(self):
log(3, 'testing Docs')
assert not lampadas.Docs==None
assert lampadas.Docs.count() > 0
assert not lampadas.docs==None
assert lampadas.docs.count() > 0
db.runsql("DELETE FROM document where title='testharness'")
db.commit()
self.OldID = db.read_value('SELECT max(doc_id) from document')
self.NewID = lampadas.Docs.add('testharness', 1, 1, 'DocBook', '4.1.2', '1.0', '2002-04-04', 'http://www.example.com/HOWTO.html', 'ISBN', 'N', 'N', '2002-04-05', '2002-04-10', 'http://www.home.com', 'N', 'GFDL', 'This is a document.', 'EN', 'fooseries')
assert self.NewID > 0
assert self.OldID + 1==self.NewID
self.Oldid = db.read_value('SELECT max(doc_id) from document')
self.Newid = lampadas.docs.add('testharness', 1, 1, 'DocBook', '4.1.2', '1.0', '2002-04-04', 'http://www.example.com/HOWTO.html', 'ISBN', 'N', 'N', '2002-04-05', '2002-04-10', 'http://www.home.com', 'N', 'GFDL', 'This is a document.', 'EN', 'fooseries')
assert self.Newid > 0
assert self.Oldid + 1==self.Newid
self.Doc = lampadas.Doc(self.NewID)
self.Doc = lampadas.docs[self.Newid]
assert not self.Doc==None
assert self.Doc.ID==self.NewID
assert self.Doc.Title=='testharness'
assert self.Doc.FormatID==1
assert self.Doc.id==self.Newid
assert self.Doc.title=='testharness'
assert self.Doc.Formatid==1
lampadas.Docs.Del(self.NewID)
self.NewID = db.read_value('SELECT MAX(doc_id) from document')
assert self.NewID==self.OldID
lampadas.docs.Del(self.Newid)
self.Newid = db.read_value('SELECT MAX(doc_id) from document')
assert self.Newid==self.Oldid
keys = lampadas.Docs.keys()
keys = lampadas.docs.keys()
for key in keys:
self.Doc = lampadas.Docs[key]
assert self.Doc.ID==key
self.Doc = lampadas.docs[key]
assert self.Doc.id==key
log(3, 'testing Docs done')
def testMapping(self):
log(3, 'testing Docs Mapping')
self.Doc = lampadas.Docs[100]
self.Doc = lampadas.docs[100]
assert not self.Doc==None
assert not self.Doc.Title==''
assert self.Doc.ID==100
self.Doc = lampadas.Docs[2]
assert self.Doc.ID==2
assert not self.Doc.title==''
assert self.Doc.id==100
self.Doc = lampadas.docs[2]
assert self.Doc.id==2
log(3, 'testing Docs Mapping done')
def testSave(self):
log(3, 'testing Docs Save')
self.Doc = lampadas.Docs[100]
self.Title = self.Doc.Title
self.Doc.Title = 'Foo'
assert self.Doc.Title=='Foo'
self.Doc.Save()
self.Doc2 = lampadas.Docs[100]
assert self.Doc2.Title=='Foo'
def test_save(self):
log(3, 'testing doc.save()')
self.Doc = lampadas.docs[100]
self.title = self.Doc.title
self.Doc.title = 'Foo'
assert self.Doc.title=='Foo'
self.Doc.save()
self.Doc2 = lampadas.docs[100]
assert self.Doc2.title=='Foo'
self.Doc.Title = self.Title
assert self.Doc.Title==self.Title
self.Doc.Save()
self.Doc2 = lampadas.Docs[100]
assert self.Doc2.Title==self.Title
log(3, 'testing Docs Save done')
self.Doc.title = self.title
assert self.Doc.title==self.title
self.Doc.save()
self.Doc2 = lampadas.docs[100]
assert self.Doc2.title==self.title
log(3, 'testing doc.save done')
class testDocErrs(unittest.TestCase):
def testDocErrs(self):
log(3, 'testing DocErrs')
keys = lampadas.Docs.keys()
keys = lampadas.docs.keys()
for key in keys:
Doc = lampadas.Docs[key]
Doc = lampadas.docs[key]
assert not Doc==None
if Doc.Errs.count() > 0:
log("found a doc with errors")
for Err in Doc.Errs:
assert not Err==None
assert Err.DocID==Doc.ID
assert Err.ErrID > 1
assert Err.doc_id==Doc.id
assert Err.Errid > 1
log(3, 'testing DocErrs done')
@ -164,14 +164,14 @@ class testDocFiles(unittest.TestCase):
def testDocFiles(self):
log(3, 'testing DocFiles')
Doc = lampadas.Docs[100]
Doc = lampadas.docs[100]
assert not Doc==None
assert Doc.Files.count() > 0
keys = Doc.Files.keys()
assert Doc.files.count() > 0
keys = Doc.files.keys()
for key in keys:
File = Doc.Files[key]
File = Doc.files[key]
if File==None: break
assert File.DocID==Doc.ID
assert File.doc_id==Doc.id
assert File.Filename > ''
log(3, 'testing DocFiles done')
@ -180,27 +180,27 @@ class testDocRatings(unittest.TestCase):
def testDocRatings(self):
log(3, 'testing DocRatings')
Doc = lampadas.Docs[100]
Doc = lampadas.docs[100]
assert not Doc==None
Doc.Ratings.Clear()
assert Doc.Ratings.count()==0
assert Doc.Rating==0
# Add UserID: 1 Rating: 5 -- Avg: 5
# Add Userid: 1 Rating: 5 -- Avg: 5
Doc.Ratings.add(1, 5)
assert Doc.Ratings.count()==1
assert Doc.Ratings.Average==5
assert Doc.Rating==5
# Add UserID: 2 Rating: 7 -- Avg: 6
# Add Userid: 2 Rating: 7 -- Avg: 6
Doc.Ratings.add(2, 7)
assert Doc.Ratings.count()==2
assert Doc.Ratings.Average==6
assert Doc.Rating==6
# Del UserID: 1
# Del Userid: 1
Doc.Ratings.Del(1)
assert Doc.Ratings.count()==1
@ -220,19 +220,19 @@ class testDocVersions(unittest.TestCase):
def testDocVersions(self):
log(3, 'testing DocVersions')
keys = lampadas.Docs.keys()
keys = lampadas.docs.keys()
found = 0
for key in keys:
Doc = lampadas.Docs[key]
Doc = lampadas.docs[key]
assert not Doc==None
if Doc.Versions.count() > 0:
if Doc.versions.count() > 0:
found = 1
vkeys = Doc.Versions.keys()
vkeys = Doc.versions.keys()
for vkey in vkeys:
Version = Doc.Versions[vkey]
assert not Version==None
assert Version.PubDate > ''
assert Version.Initials > ''
version = Doc.versions[vkey]
assert not version==None
assert version.PubDate > ''
assert version.Initials > ''
assert found==1
log(3, 'testing DocVersions done')
@ -246,12 +246,12 @@ class testLicenses(unittest.TestCase):
log(3, 'testing Licenses done')
class testDTDs(unittest.TestCase):
class test_dtds(unittest.TestCase):
def testDTDs(self):
def test_dtdss(self):
log(3, 'testing DTDs')
assert lampadas.DTDs.count() > 0
assert not lampadas.DTDs['DocBook']==None
assert lampadas.dtds.count() > 0
assert not lampadas.dtds['DocBook']==None
log(3, 'testing DTDs done')
@ -259,12 +259,12 @@ class testFormats(unittest.TestCase):
def testFormats(self):
log(3, 'testing Formats')
assert lampadas.Formats.count() > 0
assert not lampadas.Formats[1]==None
assert not lampadas.Formats[1].I18n==None
assert not lampadas.Formats[1].I18n['EN']==None
assert lampadas.Formats[1].I18n['EN'].Name > ''
assert lampadas.Formats[1].I18n['EN'].Description > ''
assert lampadas.formats.count() > 0
assert not lampadas.formats[1]==None
assert not lampadas.formats[1].I18n==None
assert not lampadas.formats[1].I18n['EN']==None
assert lampadas.formats[1].I18n['EN'].Name > ''
assert lampadas.formats[1].I18n['EN'].Description > ''
log(3, 'testing Formats done')
@ -286,13 +286,13 @@ class testPubStatuses(unittest.TestCase):
def testPubStatuses(self):
log(3, 'testing PubStatuses')
assert not lampadas.PubStatuses==None
assert lampadas.PubStatuses.count() > 0
assert not lampadas.PubStatuses['A']==None
assert not lampadas.PubStatuses['A'].I18n==None
assert not lampadas.PubStatuses['A'].I18n['EN']==None
assert lampadas.PubStatuses['A'].I18n['EN'].Name > ''
assert lampadas.PubStatuses['A'].I18n['EN'].Description > ''
assert not lampadas.pub_statuses==None
assert lampadas.pub_statuses.count() > 0
assert not lampadas.pub_statuses['A']==None
assert not lampadas.pub_statuses['A'].I18n==None
assert not lampadas.pub_statuses['A'].I18n['EN']==None
assert lampadas.pub_statuses['A'].I18n['EN'].Name > ''
assert lampadas.pub_statuses['A'].I18n['EN'].Description > ''
log(3, 'testing PubStatuses done')
@ -320,20 +320,20 @@ class testUsers(unittest.TestCase):
db.runsql("DELETE FROM username where email='foo@example.com'")
db.commit()
self.OldID = db.read_value('SELECT MAX(user_id) from username')
self.NewID = lampadas.Users.add('testuser', 'j', 'random', 'hacker', 'foo@example.com', 1, 1, 'pw', 'notes go here', 'default')
assert self.NewID > 0
assert self.OldID + 1==self.NewID
self.Oldid = db.read_value('SELECT MAX(user_id) from username')
self.Newid = lampadas.Users.add('testuser', 'j', 'random', 'hacker', 'foo@example.com', 1, 1, 'pw', 'notes go here', 'default')
assert self.Newid > 0
assert self.Oldid + 1==self.Newid
self.User = lampadas.User(self.NewID)
self.User = lampadas.User(self.Newid)
assert not self.User==None
assert self.User.ID==self.NewID
assert self.User.id==self.Newid
assert self.User.Username=='testuser'
assert self.User.Email=='foo@example.com'
lampadas.Users.Del(self.NewID)
self.NewID = db.read_value('SELECT MAX(user_id) from username')
assert self.NewID==self.OldID
lampadas.Users.Del(self.Newid)
self.Newid = db.read_value('SELECT MAX(user_id) from username')
assert self.Newid==self.Oldid
log(3, 'testing Users done')
@ -347,8 +347,8 @@ class testUserDocs(unittest.TestCase):
assert not self.User.Docs==None
for UserDoc in self.User.Docs:
assert not UserDoc==None
assert not UserDoc.DocID==None
assert UserDoc.DocID > 0
assert not UserDoc.doc_id==None
assert UserDoc.doc_id > 0
assert UserDoc.Active==1 or UserDoc.Active==0
log(3, 'testing UserDocs done')
@ -363,10 +363,10 @@ class testUserDocs(unittest.TestCase):
assert not self.User.Docs==None
for UserDoc in self.User.Docs:
assert not UserDoc==None
assert not UserDoc.DocID==None
assert UserDoc.DocID > 0
assert not UserDoc.doc_id==None
assert UserDoc.doc_id > 0
assert UserDoc.Active==1 or UserDoc.Active==0
assert UserDoc.ID==UserDoc.DocID
assert UserDoc.id==UserDoc.doc_id
log(3, 'testing UserDocs done')

View File

@ -167,7 +167,7 @@ class String:
Each string is Unicode text, that can be used in a web page.
"""
def __init__(self, StringCode=None):
def __init__(self, string_code=None):
self.string = LampadasCollection()
def load(self, row):

View File

@ -36,27 +36,27 @@ def document(req, doc_id, title, url, ref_url, pub_status_code, type_code,
if not doc_id:
return error("A required parameter is missing. Please go back and correct the error.")
doc = lampadas.Docs[int(doc_id)]
doc = lampadas.docs[int(doc_id)]
if doc==None:
return error("Cannot find document " + str(doc_id))
doc.Title = title
doc.URL = url
doc.HomeURL = ref_url
doc.PubStatusCode = pub_status_code
doc.title = title
doc.url = url
doc.home_url = ref_url
doc.pub_status_code = pub_status_code
doc.type_code = type_code
doc.ReviewStatusCode = review_status_code
doc.TechReviewStatusCode = tech_review_status_code
doc.review_status_code = review_status_code
doc.tech_review_status_code = tech_review_status_code
doc.maintainer_wanted = int(maintainer_wanted)
doc.license_code = license_code
doc.PubDate = pub_date
doc.LastUpdate = last_update
doc.Version = version
doc.TickleDate = tickle_date
doc.ISBN = isbn
doc.Lang = lang
doc.Abstract = abstract
doc.Save()
doc.pub_date = pub_date
doc.last_update = last_update
doc.version = version
doc.tickle_date = tickle_date
doc.ibsn = isbn
doc.lang = lang
doc.abstract = abstract
doc.save()
referer = req.headers_in['referer']
req.headers_out['location'] = referer
req.status = apache.HTTP_MOVED_TEMPORARILY