# # 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.7 2005/01/30 19:46:31 vaclavslavik Exp $ # # Info pages documentation provider (Unix) # import sys if sys.platform == 'win32': raise ImportError('Info provider is for Unix only') from gettext import gettext as _ import providers import os.path, commands, string, urllib infopagesList = None def getInfopagesList(): global infopagesList if infopagesList == None: l = commands.getoutput("helpers/info2html/infocat 2>/dev/null").splitlines() infopagesList = [] url = None for i in l: if i == '': url = None continue if url == None: url = i else: key = i[:i.find(':')] infopagesList.append((key, i, url)) return infopagesList class InfoProvider(providers.DocumentationProvider): def getID(self): return 'info' def getName(self): return _('Info pages') def getDescription(self): return _("""Unix info pages.
This plugin is based on info2html by Karl Guggisberg.""") def serve(self, book, url): if url == "" or url == "index.html": url = "INFOCAT" if url[-5:] == ".html": url = url[:-5] urls = url.split("/") if len(urls) == 1: urls.append("Top") root_url = "." else: root_url = ".." catalog = urllib.quote(urls[0]) page = urllib.quote(string.join(urls[1:], "/")) if catalog == "INFOCAT": txt = """ Info pages

Info pages index

' return (txt, "text/html") else: root_str = "ROOT_URL='%s'" % root_url query_str = "QUERY_STRING='(%s)%s'" % (catalog, page) data = commands.getoutput("%s %s helpers/info2html/info2html 2>/dev/null" % (query_str, root_str)) return (data, 'text/html') def getHomeURL(self, book): p = book.getAttr('page') if p == '': return 'INFOCAT' else: for key, title, url in getInfopagesList(): if key == p: return url return 'notfound.404.html' # nonexistent file def getURLForIndexing(self, book): return self.getHomeURL(book) def getConfigurationDialog(self, parent): from confgui import InfoSettingsPanel return InfoSettingsPanel(parent, -1) providers.register(InfoProvider())