# # This file is part of Documancer (http://documancer.sf.net) # # Copyright (C) 2002-2005 Vaclav Slavik # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # 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 # # $Id: provider.py,v 1.11 2005/01/30 19:46:31 vaclavslavik Exp $ # # HTML documentation provider # from gettext import gettext as _ import providers import os.path, sys, urllib class HtmlProvider(providers.DocumentationProvider): def __init__(self): self.mimeTypes = {} def _getBasedir(self, book): """Returns basedir attribute, possibly merged with book.definitionFile if it is !=None.""" basedir = book.getAttr('basedir') if book.definitionFile != None: return os.path.join(os.path.dirname(book.definitionFile), basedir) else: return basedir def getID(self): return 'html' def getName(self): return _('HTML') def getDescription(self): return _('Documentation in HTML format.') def serve(self, book, url): if url == '': return None if url[0] != "/": url = "/" + url if sys.platform == 'win32' and not book.hasAttr('basedir'): url = '%s:%s' % (url[1], url[2:]) if book.hasAttr('basedir'): url = os.path.join(self._getBasedir(book), url[1:]) try: if os.path.isdir(url): nm = os.path.join(url, "index.html") if not os.path.isfile(nm): nm = os.path.join(url, "index.htm") if os.path.isfile(nm): url = nm f = open(url, 'rb') data = f.read() f.close() if not self.mimeTypes.has_key(url): uo = urllib.urlopen(urllib.quote(url)) self.mimeTypes[url] = uo.info().gettype() uo.close() return (data, self.mimeTypes[url]) except IOError, e: return None def getHomeURL(self, book): filename = book.getAttr('rootfile') if sys.platform == 'win32': filename = filename.replace('\\','/') if filename[1] == ':' and not book.hasAttr('basedir'): filename = '/%s%s' % (filename[0], filename[2:]) return urllib.quote(filename) def getURLForIndexing(self, book): return self.getHomeURL(book) def getConfigurationDialog(self, parent): from confgui import HtmlSettingsPanel return HtmlSettingsPanel(parent, -1) providers.register(HtmlProvider())