# __init__.py - plugin function module # # Copyright (C) 1998, 1999 Albert Hopkins (marduk) # Copyright (C) 2002 Mike W. Meyer # Copyright (C) 2005 Arthur de Jong # # 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import sys import urllib import string import debugio import config import xml.sax.saxutils problem_db = {} def get_title(link): """Returns the title of a link if it is set otherwise returns url.""" if link.title is None or link.title == '': return link.url return link.title def make_link(link,title=None): """Return an nchor to a url with title. If url is in the Linklist and is external, insert "class=external" in the tag.""" # try to fetch the link object for this url if link.isinternal: cssclass='internal' else: cssclass='external' if title is None: title=get_title(link) return ''+xml.sax.saxutils.escape(title)+'' def print_parents(fp,link,indent=' '): # present a list of parents parents = link.parents parents.sort(lambda a, b: cmp(a.title, b.title)) fp.write( indent+'
\n'+ \ indent+' referenced from:\n'+ \ indent+' \n'+ \ indent+'
\n' ) def add_problem(type,link): """ Add a problem link to the 'problems' database. Will not add external links """ if not link.isinternal: return global problem_db author = link.author if problem_db.has_key(author): problem_db[author].append((type,link)) else: problem_db[author]=[(type,link)] def open_file(filename): """ given config.OUTPUT_DIR checks if the directory already exists; if not, it creates it, and then opens filename for writing and returns the file object """ import os if os.path.isdir(config.OUTPUT_DIR) == 0: os.mkdir(config.OUTPUT_DIR) fname = os.path.join(config.OUTPUT_DIR,filename) if os.path.exists(fname) and not config.OVERWRITE_FILES: # mv: overwrite `/tmp/b'? # cp: overwrite `/tmp/b'? # zip: replace aap.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: ow = raw_input('webcheck: overwrite %s? [y]es, [a]ll, [q]uit: ' % fname) ow = ow.lower() + " " if ow[0] == 'a': config.OVERWRITE_FILES = True elif ow[0] != 'y': print 'Aborted.' sys.exit(0) return open(fname,'w') def generate(site,plugins): """Generate pages for plugins.""" # generate navigation part navbar=' \n' for plugin in plugins: debugio.info(' ' + plugin) # if this is the first plugin use index.html as filename filename = plugin + '.html' if plugin == plugins[0]: filename = 'index.html' report = __import__('plugins.' + plugin, globals(), locals(), [plugin]) fp = open_file(filename) # write basic html head # TODO: make it possible to use multiple stylesheets (possibly reference external stylesheets) fp.write( \ '\n' \ '\n' \ '\n' \ ' \n' \ ' Webcheck report for %(sitetitle)s\n' \ ' \n' \ ' \n' \ ' \n' \ ' \n' \ '

Webcheck report for %(sitetitle)s

\n' \ % { 'sitetitle': xml.sax.saxutils.escape(get_title(site.linkMap[site.base])), 'siteurl': site.base, 'version': config.VERSION }) # write navigation bar fp.write(navbar) # write plugin heading fp.write('

%s

\n' % xml.sax.saxutils.escape(report.__title__)) if hasattr(report,"__description__"): fp.write('

\n %s\n

\n' % xml.sax.saxutils.escape(report.__description__)) # write plugin contents fp.write('
\n') report.generate(fp,site) fp.write('
\n') # write bottom of page import time fp.write( \ ' \n' \ ' \n' \ '\n' \ % { 'time': xml.sax.saxutils.escape(time.ctime(time.time())), 'homepage': config.HOMEPAGE, 'version': xml.sax.saxutils.escape(config.VERSION) }) fp.close()