# # 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: __init__.py,v 1.13 2005/01/30 19:46:30 vaclavslavik Exp $ # # Interface that providers must implement # import sys # -------------------------------------------------------------------------- # Provider interface: # -------------------------------------------------------------------------- class DocumentationProvider: def getID(self): """Returns unique id of the provider""" raise NotImplementedError def getName(self): """Returns human-readable string identifying the provider""" raise NotImplementedError def getDescription(self): """Returns human-readable description of the provider in HTML.""" raise NotImplementedError def initForBook(self, book): """Runs book-specific initialization of the provider. For example, cache objects may be added here. The default implementation adds fulltext index object.""" import indexer, cache cache.get(book).addObject(indexer.FulltextCacheObject(book, deps=[])) def serve(self, book, url): """Returns tuple (data_string,mime_type_string)""" raise NotImplementedError def getURLForIndexing(self, book): """Returns URL where the indexer should start""" raise NotImplementedError def getHomeURL(self, book): """Return URL where the browser should go if "Home" is pressed.""" raise NotImplementedError def getContents(self, book): """Returns tree structure with book's contents, or None if not supported.""" return None def getConfigurationDialog(self, parent): """Returns wxPython wxPanel object that can be used to configure the provider. This wxPanel must have - SetData function (accepting book.attr dictionary) - GetData that return the dict It must call UpdateBook method of object given as argument to its SetDialog method after any change).""" raise NotImplementedError def shutdown(self): """Called when Documancer exits to clean up the provider, if needed.""" pass # -------------------------------------------------------------------------- # book-keeping code: # -------------------------------------------------------------------------- providers = {} providersNameToId = {} def register(provider): global providers id = provider.getID() providers[id] = provider providersNameToId[provider.getName()] = id def shutdown(): """Shuts down all providers.""" for p in providers.values(): p.shutdown() # -------------------------------------------------------------------------- # import all available providers on startup: # -------------------------------------------------------------------------- import os, os.path, imp from utils import getDocumancerHome providers_path = os.path.join(getDocumancerHome(), 'providers') for module in os.listdir(providers_path): fn = os.path.join(providers_path, module) if (not os.path.isdir(fn) or not os.path.isfile(os.path.join(fn, 'provider.py'))): continue try: exec 'import %s.provider' % module except ImportError: pass