2002-05-17 14:21:45 +00:00
|
|
|
#!/usr/bin/python
|
2002-06-19 20:30:18 +00:00
|
|
|
#
|
|
|
|
# This file is part of the Lampadas Documentation System.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2000, 2001, 2002 David Merrill <david@lupercalia.net>.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
2002-05-17 14:21:45 +00:00
|
|
|
"""
|
|
|
|
Lampadas HTML Primitives Module
|
|
|
|
|
|
|
|
This module generates HTML primitives and web pages for the WWW front-end
|
|
|
|
to the Lampadas system.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Modules ##################################################################
|
|
|
|
|
2002-05-21 19:51:13 +00:00
|
|
|
from Globals import *
|
2002-06-19 20:30:18 +00:00
|
|
|
from Config import config
|
|
|
|
from Log import log
|
|
|
|
from URLParse import URI
|
2002-07-07 21:32:26 +00:00
|
|
|
from DataLayer import *
|
2002-07-25 10:56:40 +00:00
|
|
|
from SourceFiles import sourcefiles
|
2002-06-20 16:06:38 +00:00
|
|
|
from WebLayer import lampadasweb
|
2002-08-25 20:21:27 +00:00
|
|
|
from Tables import tables, tablemap
|
2002-08-03 04:44:22 +00:00
|
|
|
from Widgets import widgets
|
2002-07-12 21:24:15 +00:00
|
|
|
from Lintadas import lintadas
|
2002-07-02 18:34:12 +00:00
|
|
|
from Sessions import sessions
|
2002-05-17 21:09:42 +00:00
|
|
|
import commands
|
2002-07-08 20:35:44 +00:00
|
|
|
import string
|
2002-05-21 22:55:11 +00:00
|
|
|
import sys
|
2002-06-19 20:30:18 +00:00
|
|
|
import os
|
2002-07-26 22:41:35 +00:00
|
|
|
import time
|
|
|
|
import fpformat
|
2002-07-31 09:47:20 +00:00
|
|
|
import re
|
2002-05-24 08:27:57 +00:00
|
|
|
|
2002-05-17 14:21:45 +00:00
|
|
|
# Globals
|
|
|
|
|
2002-05-23 21:52:59 +00:00
|
|
|
|
2002-05-23 14:32:18 +00:00
|
|
|
# PageFactory
|
2002-05-17 16:12:43 +00:00
|
|
|
|
2002-05-23 14:32:18 +00:00
|
|
|
class PageFactory:
|
2002-05-20 19:50:54 +00:00
|
|
|
|
2002-07-26 22:41:35 +00:00
|
|
|
elapsed_time = 0
|
2002-06-19 20:30:18 +00:00
|
|
|
|
2002-06-29 16:48:06 +00:00
|
|
|
def page_exists(self, key):
|
|
|
|
uri = URI(key)
|
2002-07-17 14:41:58 +00:00
|
|
|
if uri.path=='' and lampadasweb.pages[uri.page_code]:
|
2002-06-30 08:12:45 +00:00
|
|
|
return 1
|
2002-06-29 16:48:06 +00:00
|
|
|
return
|
|
|
|
|
2002-07-21 14:24:55 +00:00
|
|
|
def page(self, uri):
|
|
|
|
if sessions.session:
|
|
|
|
log(3, 'user: ' + sessions.session.username)
|
2002-07-03 05:17:43 +00:00
|
|
|
|
2002-07-17 14:41:58 +00:00
|
|
|
page = lampadasweb.pages[uri.page_code]
|
2002-07-04 18:30:30 +00:00
|
|
|
if page==None:
|
2002-06-30 08:12:45 +00:00
|
|
|
page = lampadasweb.pages['404']
|
2002-07-04 18:30:30 +00:00
|
|
|
assert not page==None
|
2002-07-21 14:24:55 +00:00
|
|
|
html = self.build_page(page, uri)
|
2002-06-19 20:30:18 +00:00
|
|
|
|
2002-06-20 16:06:38 +00:00
|
|
|
return html
|
2002-06-19 20:30:18 +00:00
|
|
|
|
2002-07-21 14:24:55 +00:00
|
|
|
def build_page(self, page, uri):
|
2002-07-26 22:41:35 +00:00
|
|
|
start_time = time.time()
|
2002-06-20 16:06:38 +00:00
|
|
|
template = lampadasweb.templates[page.template_code]
|
2002-07-04 18:30:30 +00:00
|
|
|
assert not template==None
|
2002-06-20 16:06:38 +00:00
|
|
|
html = template.template
|
2002-06-19 20:30:18 +00:00
|
|
|
|
2002-07-29 22:46:42 +00:00
|
|
|
html = self.replace_tokens(page, uri, html)
|
|
|
|
|
|
|
|
end_time = time.time()
|
|
|
|
self.elapsed_time = end_time - start_time
|
|
|
|
html = html.replace('DCM_ELAPSED_TIME', fpformat.fix(self.elapsed_time, 3))
|
2002-07-31 09:47:20 +00:00
|
|
|
html = html.replace('DCM_PIPE', '|')
|
2002-07-29 22:46:42 +00:00
|
|
|
return html
|
|
|
|
|
|
|
|
def replace_tokens(self, page, uri, html):
|
|
|
|
temp = html.replace('\|', 'DCM_PIPE')
|
|
|
|
pos = temp.find('|')
|
2002-06-19 20:30:18 +00:00
|
|
|
while pos <> -1 :
|
2002-07-31 09:47:20 +00:00
|
|
|
temp = temp.replace('\|', 'DCM_PIPE')
|
2002-07-29 22:46:42 +00:00
|
|
|
pos2 = temp.find('|', pos+1)
|
2002-07-04 18:30:30 +00:00
|
|
|
if pos2==-1:
|
2002-06-19 20:30:18 +00:00
|
|
|
pos = -1
|
|
|
|
else:
|
2002-07-29 22:46:42 +00:00
|
|
|
token = temp[pos+1:pos2]
|
2002-07-02 18:34:12 +00:00
|
|
|
|
2002-07-13 02:41:25 +00:00
|
|
|
newstring = None
|
2002-06-19 20:30:18 +00:00
|
|
|
|
2002-07-26 22:41:35 +00:00
|
|
|
# System diagnostic tokens
|
|
|
|
if token=='elapsed_time':
|
2002-07-29 16:20:11 +00:00
|
|
|
newstring = 'DCM_ELAPSED_TIME'
|
2002-07-26 22:41:35 +00:00
|
|
|
|
2002-08-14 10:48:01 +00:00
|
|
|
# Session Tokens
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='session_id':
|
2002-07-21 14:24:55 +00:00
|
|
|
if sessions.session:
|
|
|
|
newstring = sessions.session.user.session_id
|
2002-07-03 05:17:43 +00:00
|
|
|
else:
|
|
|
|
newstring = ''
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='session_username':
|
2002-07-21 14:24:55 +00:00
|
|
|
if sessions.session:
|
|
|
|
newstring = sessions.session.username
|
2002-07-03 05:17:43 +00:00
|
|
|
else:
|
|
|
|
newstring = ''
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='session_name':
|
2002-07-21 14:24:55 +00:00
|
|
|
if sessions.session:
|
|
|
|
newstring = sessions.session.user.name
|
2002-07-03 05:17:43 +00:00
|
|
|
else:
|
2002-07-21 14:24:55 +00:00
|
|
|
newstring = ''
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='session_user_docs':
|
2002-07-21 14:24:55 +00:00
|
|
|
if sessions.session:
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.userdocs(uri, username=sessions.session.username)
|
2002-07-21 14:24:55 +00:00
|
|
|
else:
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = '|nopermission|'
|
2002-07-04 14:24:54 +00:00
|
|
|
|
2002-08-14 10:48:01 +00:00
|
|
|
# Page Meta-data
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='title':
|
2002-07-04 05:31:59 +00:00
|
|
|
newstring = page.title[uri.lang]
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='body':
|
2002-08-04 01:25:00 +00:00
|
|
|
if page.only_registered==1 and sessions.session==None:
|
|
|
|
newstring = '|blknopermission|'
|
|
|
|
elif page.only_admin==1 and (sessions.session==None or sessions.session.user.admin==0):
|
|
|
|
newstring = '|blknopermission|'
|
|
|
|
elif page.only_sysadmin==1 and (sessions.session==None or sessions.session.user.sysadmin==0):
|
|
|
|
newstring = '|blknopermission|'
|
|
|
|
else:
|
|
|
|
newstring = page.page[uri.lang]
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='base':
|
2002-07-01 22:32:30 +00:00
|
|
|
newstring = 'http://' + config.hostname
|
|
|
|
if config.port > '':
|
|
|
|
newstring = newstring + ':' + config.port
|
|
|
|
newstring = newstring + config.root_dir
|
2002-07-13 02:41:25 +00:00
|
|
|
|
2002-08-14 10:48:01 +00:00
|
|
|
# URI Meta-data
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='uri.lang_ext':
|
2002-07-13 02:41:25 +00:00
|
|
|
newstring = uri.lang_ext
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='uri.base':
|
2002-07-04 05:31:59 +00:00
|
|
|
newstring = uri.base
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='uri.page_code':
|
2002-07-21 14:24:55 +00:00
|
|
|
newstring = uri.page_code
|
2002-07-31 09:47:20 +00:00
|
|
|
elif token=='uri.id':
|
|
|
|
newstring = str(uri.id)
|
|
|
|
elif token=='uri.code':
|
|
|
|
newstring = uri.code
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='uri.filename':
|
2002-07-17 14:41:58 +00:00
|
|
|
newstring = uri.filename
|
2002-07-04 05:31:59 +00:00
|
|
|
|
2002-07-04 14:24:54 +00:00
|
|
|
|
2002-08-14 10:48:01 +00:00
|
|
|
# Configuration Tokens
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='hostname':
|
2002-07-04 14:24:54 +00:00
|
|
|
newstring = config.hostname
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='rootdir':
|
2002-07-04 14:24:54 +00:00
|
|
|
newstring = config.root_dir
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='port':
|
2002-07-04 14:24:54 +00:00
|
|
|
newstring = str(config.port)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='stylesheet':
|
2002-07-21 14:24:55 +00:00
|
|
|
if sessions.session:
|
|
|
|
newstring = sessions.session.user.stylesheet
|
2002-07-05 07:00:49 +00:00
|
|
|
else:
|
|
|
|
newstring='default'
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='version':
|
2002-07-04 14:24:54 +00:00
|
|
|
newstring = VERSION
|
|
|
|
|
2002-07-15 12:44:21 +00:00
|
|
|
###########################################
|
|
|
|
# Tokens for when a page embeds an object #
|
|
|
|
###########################################
|
|
|
|
|
|
|
|
# Embedded User
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='user.username':
|
2002-08-14 10:48:01 +00:00
|
|
|
newstring = uri.username
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='user.name':
|
2002-08-14 10:48:01 +00:00
|
|
|
user = lampadas.users[uri.username]
|
|
|
|
if user:
|
2002-07-09 16:09:24 +00:00
|
|
|
newstring = user.name
|
2002-07-21 14:24:55 +00:00
|
|
|
else:
|
2002-08-14 10:48:01 +00:00
|
|
|
newstring = ''
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='user.docs':
|
2002-08-14 10:48:01 +00:00
|
|
|
newstring = tables.userdocs(uri, uri.username)
|
2002-07-15 12:44:21 +00:00
|
|
|
|
|
|
|
# Embedded Type
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='type.name':
|
2002-07-04 14:24:54 +00:00
|
|
|
type = lampadas.types[uri.code]
|
2002-07-09 16:09:24 +00:00
|
|
|
if not type:
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = '|blknotfound|'
|
2002-07-09 16:09:24 +00:00
|
|
|
else:
|
|
|
|
newstring = type.name[uri.lang]
|
2002-07-15 12:44:21 +00:00
|
|
|
|
|
|
|
# Embedded Topic
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='topic.name':
|
2002-07-04 14:24:54 +00:00
|
|
|
topic = lampadas.topics[uri.code]
|
2002-07-09 16:09:24 +00:00
|
|
|
if not topic:
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = '|blknotfound|'
|
2002-07-09 16:09:24 +00:00
|
|
|
else:
|
|
|
|
newstring = topic.name[uri.lang]
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='topic.description':
|
2002-07-04 14:24:54 +00:00
|
|
|
topic = lampadas.topics[uri.code]
|
2002-07-09 16:09:24 +00:00
|
|
|
if not topic:
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = '|blknotfound|'
|
2002-07-09 16:09:24 +00:00
|
|
|
else:
|
|
|
|
newstring = topic.description[uri.lang]
|
2002-07-02 18:34:12 +00:00
|
|
|
|
2002-08-25 15:22:01 +00:00
|
|
|
# Embedded Collection
|
|
|
|
elif token=='collection.name':
|
|
|
|
collection = lampadas.collections[uri.code]
|
|
|
|
if not collection:
|
|
|
|
newstring = '|blknotfound|'
|
|
|
|
else:
|
|
|
|
newstring = collection.name[uri.lang]
|
|
|
|
elif token=='collection.description':
|
|
|
|
collection = lampadas.collections[uri.code]
|
|
|
|
if not collection:
|
|
|
|
newstring = '|blknotfound|'
|
|
|
|
else:
|
|
|
|
newstring = collection.description[uri.lang]
|
|
|
|
|
2002-08-14 10:48:01 +00:00
|
|
|
# Embedded Document
|
|
|
|
elif token=='doc.title':
|
|
|
|
doc = lampadas.docs[uri.id]
|
|
|
|
if not doc:
|
|
|
|
newstring = '|blknotfound|'
|
|
|
|
else:
|
|
|
|
newstring = doc.title
|
2002-08-18 01:49:29 +00:00
|
|
|
elif token=='doc.abstract':
|
|
|
|
doc = lampadas.docs[uri.id]
|
|
|
|
if not doc:
|
|
|
|
newstring = '|blknotfound|'
|
|
|
|
else:
|
|
|
|
newstring = doc.abstract
|
2002-08-14 10:48:01 +00:00
|
|
|
|
2002-07-10 17:44:21 +00:00
|
|
|
# Navigation Boxes
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='navlogin':
|
2002-08-25 15:51:15 +00:00
|
|
|
newstring = tables.navlogin(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='navmenus':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.section_menus(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='navtopics':
|
2002-08-13 03:08:54 +00:00
|
|
|
newstring = tables.navtopics(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='navtypes':
|
2002-08-25 15:51:15 +00:00
|
|
|
newstring = tables.navtypes(uri)
|
2002-08-25 15:22:01 +00:00
|
|
|
elif token=='navcollections':
|
|
|
|
newstring = tables.navcollections(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='navsessions':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.navsessions(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='navlanguages':
|
2002-08-25 15:51:15 +00:00
|
|
|
newstring = tables.navlanguages(uri)
|
2002-07-10 17:44:21 +00:00
|
|
|
|
|
|
|
# Tables
|
2002-08-25 15:22:01 +00:00
|
|
|
elif token=='tabcollections':
|
|
|
|
newstring = tables.tabcollections(uri)
|
|
|
|
elif token=='tabcollection':
|
|
|
|
newstring = tables.tabcollection(uri)
|
2002-08-13 03:08:54 +00:00
|
|
|
elif token=='tabtopics':
|
|
|
|
newstring = tables.tabtopics(uri)
|
|
|
|
elif token=='tabtopic':
|
|
|
|
newstring = tables.tabtopic(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabmaint_wanted':
|
2002-08-28 16:40:34 +00:00
|
|
|
newstring = tables.doctable(uri, maintainer_wanted='1', lang=uri.lang)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabunmaintained':
|
2002-08-28 16:40:34 +00:00
|
|
|
newstring = tables.doctable(uri, maintained='0', lang=uri.lang)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabpending':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.doctable(uri, pub_status_code='P', lang=uri.lang)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabwishlist':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.doctable(uri, pub_status_code='W', lang=uri.lang)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabeditdoc':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.doc(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabdocfiles':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.docfiles(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabdocusers':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.docusers(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabdocversions':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.docversions(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabdoctopics':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.doctopics(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabdocerrors':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.docerrors(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabfile_reports':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.filereports(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabfile_report':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.filereport(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabdocfileerrors':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.docfileerrors(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabdocnotes':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.docnotes(uri)
|
2002-08-13 13:53:41 +00:00
|
|
|
elif token=='tabdoctranslations':
|
|
|
|
newstring = tables.doctranslations(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabcvslog':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.cvslog(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabletters':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.letters(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabusers':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.users(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabuser':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.user(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabrecentnews':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.recent_news(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabtypedocs':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.doctable(uri, type_code=uri.code, lang=uri.lang)
|
2002-08-13 03:08:54 +00:00
|
|
|
elif token=='tabtopicdocs':
|
|
|
|
newstring = tables.doctable(uri, topic_code=uri.code, lang=uri.lang)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabsitemap':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.sitemap(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabsessions':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.tabsessions(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabmailpass':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.tabmailpass(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='taberrors':
|
2002-07-31 09:47:20 +00:00
|
|
|
newstring = tables.errors(uri)
|
2002-07-29 22:46:42 +00:00
|
|
|
elif token=='tabsearch':
|
2002-08-28 16:40:34 +00:00
|
|
|
newstring = tables.tabsearch(uri, lang=uri.lang)
|
2002-08-04 01:25:00 +00:00
|
|
|
elif token=='tabsplashlanguages':
|
|
|
|
newstring = tables.tabsplashlanguages(uri)
|
2002-08-28 16:40:34 +00:00
|
|
|
elif token=='tablint_time_stats':
|
|
|
|
newstring = tables.tablint_time_stats(uri)
|
2002-08-21 17:38:10 +00:00
|
|
|
elif token=='tabmirror_time_stats':
|
|
|
|
newstring = tables.tabmirror_time_stats(uri)
|
|
|
|
elif token=='tabpub_time_stats':
|
|
|
|
newstring = tables.tabpub_time_stats(uri)
|
2002-08-23 00:59:11 +00:00
|
|
|
elif token=='tabpub_status_stats':
|
|
|
|
newstring = tables.tabpub_status_stats(uri)
|
2002-08-23 01:45:26 +00:00
|
|
|
elif token=='tabdoc_error_stats':
|
|
|
|
newstring = tables.tabdoc_error_stats(uri)
|
2002-08-24 18:33:52 +00:00
|
|
|
elif token=='tabdoc_format_stats':
|
|
|
|
newstring = tables.tabdoc_format_stats(uri)
|
2002-08-28 12:54:45 +00:00
|
|
|
elif token=='tabdoc_dtd_stats':
|
|
|
|
newstring = tables.tabdoc_dtd_stats(uri)
|
2002-08-23 00:59:11 +00:00
|
|
|
elif token=='tabdocument_tabs':
|
|
|
|
newstring = tables.tabdocument_tabs(uri)
|
2002-08-28 16:40:34 +00:00
|
|
|
elif token=='tabdocument_icon_box':
|
|
|
|
newstring = tables.tabdocument_icon_box(uri)
|
2002-06-19 20:30:18 +00:00
|
|
|
|
2002-08-25 20:21:27 +00:00
|
|
|
# Tables, Blocks and Strings
|
2002-07-13 02:41:25 +00:00
|
|
|
if newstring==None:
|
2002-08-25 20:21:27 +00:00
|
|
|
tablegen = tablemap[token]
|
|
|
|
if tablegen==None:
|
|
|
|
block = lampadasweb.blocks[token]
|
|
|
|
if block==None:
|
|
|
|
string = lampadasweb.strings[token]
|
|
|
|
if string==None:
|
|
|
|
log(1, 'Could not replace token ' + token)
|
|
|
|
else:
|
|
|
|
newstring = string.string[uri.lang]
|
2002-06-19 20:30:18 +00:00
|
|
|
else:
|
2002-08-25 20:21:27 +00:00
|
|
|
newstring = block.block
|
2002-06-19 20:30:18 +00:00
|
|
|
else:
|
2002-08-25 20:21:27 +00:00
|
|
|
newstring = tablegen(uri)
|
2002-06-19 20:30:18 +00:00
|
|
|
|
2002-08-21 17:38:10 +00:00
|
|
|
# Just use the token if the token was not found
|
2002-07-13 02:41:25 +00:00
|
|
|
if newstring==None:
|
2002-06-20 16:06:38 +00:00
|
|
|
log(1, 'Could not replace token ' + token)
|
2002-08-21 17:38:10 +00:00
|
|
|
newstring = token
|
2002-07-01 18:33:12 +00:00
|
|
|
|
2002-07-31 09:47:20 +00:00
|
|
|
# Call myself recursively before replacing, so we do replacement on it only once,
|
|
|
|
# while it is still small. Replacing text in large pages is more costly on large
|
|
|
|
# strings.
|
|
|
|
#
|
|
|
|
# Routines that build potentially very large tables should be caching their
|
|
|
|
# static portions during page build.
|
|
|
|
temp = temp.replace(temp[pos:pos2+1], self.replace_tokens(page, uri, newstring))
|
2002-06-19 20:30:18 +00:00
|
|
|
|
2002-07-31 09:47:20 +00:00
|
|
|
temp = temp.replace('\|', 'DCM_PIPE')
|
2002-07-29 22:46:42 +00:00
|
|
|
pos = temp.find('|')
|
|
|
|
|
|
|
|
return temp
|
2002-06-19 20:30:18 +00:00
|
|
|
|
2002-05-17 21:09:42 +00:00
|
|
|
|
2002-06-20 16:06:38 +00:00
|
|
|
page_factory = PageFactory()
|
|
|
|
|
2002-07-05 03:54:50 +00:00
|
|
|
def benchmark(url, reps):
|
2002-07-05 07:00:49 +00:00
|
|
|
from DataLayer import Lampadas
|
2002-07-05 03:54:50 +00:00
|
|
|
for x in range(0, reps):
|
|
|
|
page = page_factory.page(url)
|
2002-06-30 15:36:49 +00:00
|
|
|
|
2002-05-21 22:55:11 +00:00
|
|
|
def main():
|
2002-07-05 03:54:50 +00:00
|
|
|
import profile
|
2002-07-05 07:00:49 +00:00
|
|
|
import pstats
|
2002-07-15 01:55:53 +00:00
|
|
|
|
2002-06-30 17:45:57 +00:00
|
|
|
if len(sys.argv[1:]):
|
2002-07-05 03:54:50 +00:00
|
|
|
profile_it = 0
|
|
|
|
reps_flag = 0
|
2002-07-05 07:00:49 +00:00
|
|
|
profile_reps = 100
|
2002-06-30 17:45:57 +00:00
|
|
|
for arg in sys.argv[1:]:
|
2002-07-05 03:54:50 +00:00
|
|
|
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)
|
2002-07-05 07:00:49 +00:00
|
|
|
profile.run('benchmark("' + arg + '", ' + str(profile_reps) + ')', 'profile_stats')
|
|
|
|
p = pstats.Stats('profile_stats')
|
|
|
|
p.sort_stats('time').print_stats()
|
|
|
|
|
2002-07-05 03:54:50 +00:00
|
|
|
else:
|
2002-07-10 21:16:21 +00:00
|
|
|
print page_factory.page(URI(arg))
|
2002-06-30 17:45:57 +00:00
|
|
|
else:
|
|
|
|
profile()
|
2002-05-21 22:55:11 +00:00
|
|
|
|
2002-05-23 15:28:03 +00:00
|
|
|
|
2002-07-04 18:30:30 +00:00
|
|
|
if __name__=="__main__":
|
2002-06-19 20:30:18 +00:00
|
|
|
main()
|
2002-07-05 07:00:49 +00:00
|
|
|
|