# HG changeset patch # User Atul Varma # Date 1204140904 28800 # Node ID 09cc6fd3ddd2a418df7aae35c38940d74c6ec74f # Parent d3c0220c5895c141a95dab4d2db2d31ce32e2588 Added a really basic plugin architecture. Also implemented a rc-file mechanism whereby the ~/.ensorc file is interpreted as a Python file and run before Enso starts. It's intended to make any changes it wants to the default enso.config--such as adding to config.PLUGINS--before Enso starts running. diff -r d3c0220c5895 -r 09cc6fd3ddd2 enso/__init__.py --- a/enso/__init__.py Wed Feb 27 10:50:26 2008 -0800 +++ b/enso/__init__.py Wed Feb 27 11:35:04 2008 -0800 @@ -37,10 +37,18 @@ Initializes and runs Enso. """ + import enso.plugins import enso.ui enso.ui.init() try: - enso.ui.run() + enso.ui.events.eventManager.registerResponder( + enso.plugins.init, + "init" + ) + try: + enso.ui.run() + finally: + enso.plugins.shutdown() finally: enso.ui.shutdown() diff -r d3c0220c5895 -r 09cc6fd3ddd2 enso/config.py --- a/enso/config.py Wed Feb 27 10:50:26 2008 -0800 +++ b/enso/config.py Wed Feb 27 11:35:04 2008 -0800 @@ -55,5 +55,10 @@ " these mini-messages.

" # List of modules/packages that support the provider interface to -# provide platform-specific functionality to Enso. +# provide required platform-specific functionality to Enso. PROVIDERS = ["enso_osx"] + +# List of modules/packages that support the plugin interface to +# extend Enso. The plugins are loaded in the order that they +# are specified in this list. +PLUGINS = [] diff -r d3c0220c5895 -r 09cc6fd3ddd2 enso/plugins.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/enso/plugins.py Wed Feb 27 11:35:04 2008 -0800 @@ -0,0 +1,34 @@ +# TODO: Add documentation for this module. + +import logging + +import enso.config + +_plugins = [] + +def init(): + for moduleName in enso.config.PLUGINS: + try: + # Import the module; most of this code was taken from the + # Python Library Reference documentation for __import__(). + module = __import__( moduleName, {}, {}, [], 0 ) + components = moduleName.split( "." ) + for component in components[1:]: + module = getattr( module, component ) + + module.load() + _plugins.append( (module, moduleName) ) + except: + logging.warn( "Error while loading plugin '%s'." % moduleName ) + raise + logging.info( "Loaded plugin '%s'." % moduleName ) + +def shutdown(): + for module, moduleName in _plugins: + try: + module.unload() + except: + logging.warn( "Error while unloading plugin '%s'." % moduleName ) + raise + logging.info( "Unloaded plugin '%s'." % moduleName ) + _plugins[:] = [] diff -r d3c0220c5895 -r 09cc6fd3ddd2 scripts/run_enso.py --- a/scripts/run_enso.py Wed Feb 27 10:50:26 2008 -0800 +++ b/scripts/run_enso.py Wed Feb 27 11:35:04 2008 -0800 @@ -1,9 +1,20 @@ #! /usr/bin/env python +import os import logging import enso if __name__ == "__main__": logging.basicConfig( level=logging.INFO ) + + homeDir = os.getenv( "HOME" ) + if homeDir: + ensorcPath = os.path.join( homeDir, ".ensorc" ) + if os.path.exists( ensorcPath ): + logging.info( "Loading '%s'." % ensorcPath ) + contents = open( ensorcPath, "r" ).read() + compiledContents = compile( contents, ensorcPath, "exec" ) + exec compiledContents in {}, {} + enso.run()