You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gump.apache.org by le...@apache.org on 2005/01/07 16:15:22 UTC
svn commit: r124505 - in gump/branches/Dec04MajorCleanup: metadata pygump/python/gump pygump/python/gump/engine pygump/python/gump/plugins
Author: leosimons
Date: Fri Jan 7 07:15:20 2005
New Revision: 124505
URL: http://svn.apache.org/viewcvs?view=rev&rev=124505
Log:
More flexible plugin architecture with three stages and plugin initialization/cleanup support. Also add my current test profile as an example of what I'm working with.
Added:
gump/branches/Dec04MajorCleanup/metadata/giraffe.xml
Modified:
gump/branches/Dec04MajorCleanup/pygump/python/gump/config.py
gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/__init__.py
gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/walker.py
gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/__init__.py
gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/dynagumper.py
Added: gump/branches/Dec04MajorCleanup/metadata/giraffe.xml
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/metadata/giraffe.xml?view=auto&rev=124505
==============================================================================
--- (empty file)
+++ gump/branches/Dec04MajorCleanup/metadata/giraffe.xml Fri Jan 7 07:15:20 2005
@@ -0,0 +1,68 @@
+<?xml version="1.0"?>
+<!--+
+ | Copyright 2003-2005 The Apache Software Foundation
+ | Licensed under the Apache License, Version 2.0 (the "License");
+ | you may not use this file except in compliance with the License.
+ | You may obtain a copy of the License at
+ |
+ | http://www.apache.org/licenses/LICENSE-2.0
+ |
+ | Unless required by applicable law or agreed to in writing, software
+ | distributed under the License is distributed on an "AS IS" BASIS,
+ | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ | See the License for the specific language governing permissions and
+ | limitations under the License.
+ +-->
+<workspace
+ version="1.0"
+ name="gump3-test"
+ basedir="work"
+ pkgdir="work/packages"
+ jardir="work/jars"
+ logdir="work/log">
+
+ <repositories>
+ <repository name="ant" type="cvs">
+ <title>Ant</title>
+ <home-page>http://ant.apache.org/</home-page>
+ <cvsweb>http://cvs.apache.org/viewcvs/</cvsweb>
+ <redistributable/>
+
+ <hostname>cvs.apache.org</hostname>
+ <method>pserver</method>
+ <path>/home/cvspublic</path>
+ <user>anoncvs</user>
+ <password>anoncvs</password>
+ </repository>
+ </repositories>
+
+ <modules>
+ <module name="ant">
+ <repository name="ant"/>
+
+ <url>http://ant.apache.org/index.html</url>
+ <description>Java based build tool</description>
+ </module>
+ </modules>
+
+ <projects>
+ <project name="bogus">
+ <module name="ant"/>
+ </project>
+
+ <project name="bootstrap-ant">
+ <module name="ant"/>
+
+ <!-- commands -->
+ <script name="bootstrap"/>
+
+ <!-- outputs -->
+ <home nested="bootstrap"/>
+ <jar name="lib/ant.jar"/>
+ <jar name="lib/ant-launcher.jar" id="ant-launcher"/>
+
+ <!-- dependencies -->
+ <option project="bogus"/>
+ </project>
+ </projects>
+</workspace>
Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/config.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/config.py?view=diff&rev=124505&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/config.py&r1=124504&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/config.py&r2=124505
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/config.py (original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/config.py Fri Jan 7 07:15:20 2005
@@ -83,6 +83,10 @@
The config argument provided is an instance of the _Config class that is
returned from the get_config method below.
"""
+
+ pre_process_plugins = []
+ # TODO: append more plugins here...
+
plugins = []
from gump.plugins import LoggingPlugin
@@ -93,10 +97,12 @@
db = get_db(config)
log = get_logger(config.log_level, "plugin-dynagumper")
plugins.append(Dynagumper(db, log))
-
# TODO: append more plugins here...
- return plugins
+ post_process_plugins = []
+ # TODO: append more plugins here...
+
+ return (pre_process_plugins, plugins, post_process_plugins)
def get_error_handler(config):
@@ -206,7 +212,9 @@
"""Provide a Plugin implementation."""
from gump.plugins import MulticastPlugin
- plugins = get_plugins(config)
+ (pre_process_plugins, plugins, post_process_plugins) = get_plugins(config)
error_handler = get_error_handler(config)
- return MulticastPlugin(plugins, error_handler)
+ return (MulticastPlugin(pre_process_plugins, error_handler),
+ MulticastPlugin(plugins, error_handler),
+ MulticastPlugin(post_process_plugins, error_handler))
Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/__init__.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/__init__.py?view=diff&rev=124505&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/__init__.py&r1=124504&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/__init__.py&r2=124505
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/__init__.py (original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/__init__.py Fri Jan 7 07:15:20 2005
@@ -84,11 +84,12 @@
dropfile = os.path.join(config.paths_work, "dropped.xml")
walker = get_walker()
- visitor = get_plugin(config)
+ (pre_process_visitor, visitor, post_process_visitor) = get_plugin(config)
# create engine
engine = _Engine(log, modeller_loader, modeller_normalizer,
- modeller_objectifier, modeller_verifier, walker, visitor,
+ modeller_objectifier, modeller_verifier, walker,
+ pre_process_visitor, visitor, post_process_visitor,
config.paths_workspace, mergefile, dropfile)
# run it
@@ -115,7 +116,8 @@
"""This is the core of the core of the pygump application."""
def __init__(self, log, workspace_loader, workspace_normalizer,
- workspace_objectifier, workspace_verifier, walker, visitor,
+ workspace_objectifier, workspace_verifier, walker,
+ pre_process_visitor, visitor, post_process_visitor,
workspace, merge_to=None, drop_to=None):
"""Store all config and dependencies as properties.
@@ -131,8 +133,14 @@
is correct
- walker -- the component that knows how to traverse the gump
model in dependency order
+ - pre_process_visitor -- the component that gets called by the
+ walker while visiting parts of the model during the
+ pre-processing stage
- visitor -- the component that gets called by the walker while
- visiting parts of the model
+ visiting parts of the model during the build stage
+ - post_process_visitor -- the component that gets called by the
+ walker while visiting parts of the model during the
+ pre-processing stage
- workspace -- the resource containing the workspace xml.
- merge_to -- the resource to write the merged workspace xml to.
@@ -144,7 +152,10 @@
self.workspace_objectifier = workspace_objectifier
self.workspace_verifier = workspace_verifier
self.walker = walker
+
+ self.pre_process_visitor = pre_process_visitor
self.visitor = visitor
+ self.post_process_visitor = post_process_visitor
self.workspace = open_file_or_stream(workspace,'r')
self.merge_to = open_file_or_stream(merge_to,'w')
@@ -175,7 +186,10 @@
self.workspace_verifier.verify(domtree)
# * Pfew! All done. Now actually start *doing* stuff.
+ self.walker.walk(workspace, self.pre_process_visitor)
+ # (visited_repositories, visited_modules, visited_projects) = \
self.walker.walk(workspace, self.visitor)
+ self.walker.walk(workspace, self.post_process_visitor)
# That's it? Yeah! All other functionality is in the visitors :-D
except:
Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/walker.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/walker.py?view=diff&rev=124505&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/walker.py&r1=124504&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/walker.py&r2=124505
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/walker.py (original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/engine/walker.py Fri Jan 7 07:15:20 2005
@@ -41,6 +41,7 @@
Returns a tuple containing the repositories visited, the modules
visited, and the projects visited, in the order they were visited.
"""
+ visitor._initialize()
visitor._visit_workspace(workspace)
list = self._topsort_projects(workspace)
@@ -60,6 +61,7 @@
visitor._visit_project(project)
visited_projects.append(project)
+ visitor._finalize()
return (visited_repositories, visited_modules, visited_projects)
def _topsort_projects(self, workspace):
Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/__init__.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/__init__.py?view=diff&rev=124505&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/__init__.py&r1=124504&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/__init__.py&r2=124505
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/__init__.py (original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/__init__.py Fri Jan 7 07:15:20 2005
@@ -46,21 +46,25 @@
To create a concrete plugin, implement one or more of these methods:
+ - initialize()
- visit_workspace(workspace)
- visit_repository(repository)
- visit_module(module)
- visit_project(project)
+ - finalize()
Each of these methods will be called in a "topologically sorted" order.
Concretely, this means that:
+ * initialize will be called first;
* visit_workspace will be called first;
* visit_repository will be called before any contained module or
project is visited;
* visit_module will be called before any contained project is
visited;
* visit_project will be called only after all dependencies of that
- project have already been visited.
+ project have already been visited;
+ * finalize will be called last.
More concretely, this means plugins usually do not have to worry about
the correct ordering of events, since this is usually what you want.
@@ -68,6 +72,11 @@
def __init__(self, log):
self.log = log
+ def _initialize(self):
+ if not hasattr(self,'initialize'): return
+ if not callable(self.initialize): return
+ self.initialize()
+
def _visit_workspace(self, workspace):
if not hasattr(self,'visit_workspace'): return
if not callable(self.visit_workspace): return
@@ -88,12 +97,22 @@
if not callable(self.visit_project): return
self.visit_project(project)
+ def _finalize(self):
+ if not hasattr(self,'finalize'): return
+ if not callable(self.finalize): return
+ self.finalize()
+
class MulticastPlugin(AbstractPlugin):
"""Core plugin that redirects visit_XXX calls to other plugins."""
def __init__(self, plugin_list, error_handler=BaseErrorHandler()):
self.list = plugin_list
self.error_handler = error_handler
+ def initialize(self):
+ for visitor in self.list:
+ try: visitor._initialize()
+ except: self.error_handler.handle(visitor, error, "{{{initialization stage}}}")
+
def visit_workspace(self, workspace):
for visitor in self.list:
try: visitor._visit_workspace(workspace)
@@ -114,11 +133,19 @@
try: visitor._visit_project(project)
except: self.error_handler.handle(visitor, error, project)
+ def finalize(self):
+ for visitor in self.list:
+ try: visitor._finalize()
+ except: self.error_handler.handle(visitor, error, "{{{finalization stage}}}")
+
class LoggingPlugin(AbstractPlugin):
"""Plugin that prints debug messages as it visits model objects."""
def __init__(self, log):
self.log = log
+ def initialize(self):
+ self.log.debug("Initializing...")
+
def visit_workspace(self, workspace):
self.log.debug("Visiting workspace.")
@@ -130,3 +157,7 @@
def visit_project(self, project):
self.log.debug("Visiting project '%s'." % project.name)
+
+ def finalize(self):
+ self.log.debug("Finishing up...")
+
Modified: gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/dynagumper.py
Url: http://svn.apache.org/viewcvs/gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/dynagumper.py?view=diff&rev=124505&p1=gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/dynagumper.py&r1=124504&p2=gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/dynagumper.py&r2=124505
==============================================================================
--- gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/dynagumper.py (original)
+++ gump/branches/Dec04MajorCleanup/pygump/python/gump/plugins/dynagumper.py Fri Jan 7 07:15:20 2005
@@ -35,6 +35,10 @@
"""
self.db = db
self.log = log
+
+ def initialize(self):
+ #TODO call ensureThisHostIsInDatabase
+ pass
def ensureThisHostIsInDatabase(self):
"""Adds information about this server to the hosts table."""
@@ -48,13 +52,15 @@
def visit_workspace(self, workspace):
"""Add information about the workspace to the database."""
+ pass
#TODO do the actual work right here...
- #TODO call ensureThisHostIsInDatabase
def visit_module(self, module):
"""Add information about a module to the database."""
+ pass
#TODO do the actual work
def visit_project(self, project):
"""Add information about a project to the database."""
+ pass
#TODO do the actual work right here...