# # 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 $ # # pydoc on the fly Python documentation browser provider # from gettext import gettext as _ import httplib import os.path import pydoc import threading import providers, utils PYDOC_SERVER_PORT = None pydoc_pathdirs_orig = pydoc.pathdirs class PyDocProvider(providers.DocumentationProvider): def __init__(self): self.thread = None def getID(self): return 'pydoc' def getName(self): return _('Python docs') def getDescription(self): return _("""Python modules documentation generated at runtime from docstrings.""") def _startPydocServer(self): # Make sure pydoc does not see Documancer's python code: def pydoc_pathdirs_my(): global pydoc_pathdirs_orig l = [] for p in pydoc_pathdirs_orig(): if not os.path.isfile(os.path.join(p, 'documancer.py')): l.append(p) return l pydoc.pathdirs = pydoc_pathdirs_my global PYDOC_SERVER_PORT if PYDOC_SERVER_PORT == None: PYDOC_SERVER_PORT = utils.getServerPort('pydoc') # Create PyDoc HTTP server. We will redirect all requests to it: class PyDocServerThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.running = threading.Event() def run(self): global PYDOC_SERVER_PORT self.running.set() pydoc.serve(PYDOC_SERVER_PORT) self.thread = PyDocServerThread() self.thread.setDaemon(1) self.thread.start() self.thread.running.wait() self.conn = httplib.HTTPConnection('localhost', PYDOC_SERVER_PORT) import time time.sleep(0.5) def serve(self, book, url): if self.thread == None: self._startPydocServer() if url == 'index.html' or url == '': url = '/' self.conn.request('GET', url) r = self.conn.getresponse() if r.status >= 400: return None else: return (r.read(), 'text/html') def getHomeURL(self, book): return 'index.html' def getURLForIndexing(self, book): return 'index.html' def getConfigurationDialog(self, parent): from wxPython.wx import wxPanel class EmptySettingsPanel(wxPanel): def SetDialog(self, dlg): pass def SetData(self, attr): pass def GetData(self): return {} return EmptySettingsPanel(parent, -1) providers.register(PyDocProvider())