design a way to walk part of the tree very efficiently
------------------------------------------------------

         Key: GUMP-104
         URL: http://issues.apache.org/jira/browse/GUMP-104
     Project: Gump
        Type: Task
  Components: Python-based Gump  
    Versions: Gump3-alpha    
    Reporter: Leo Simons
     Fix For: Gump3-alpha


We need a convention between plugins that enables them to communicate about the 
state of the tree, and make somewhat intelligent decisions about what to build 
and what not to build. Ideally that is extracted nearly completely into a few 
"policy" or "algorithm" plugins.

Perhaps
{{{
class DependencyStateVerifierPlugin(AbstractPlugin):
  def visit_project(p):
    for rel in p.dependencies:
      if p.rel.dependency.state == FAILED:
         p.state == PREREQ_FAILURE

class AbstractBuilderPlugin(AbstractPlugin):
  def visit_project(p):
    if not p.rel.dependency.state == PREREQ_FAILURE and getattr(self, 
"do_build", None):
      self.do_build(p)

# NB: MkdirPlugin doesn't need to know about project states, but it still 
depends on the policy in
# AbstractBuilderPlugin
class MkdirPlugin(AbstractBuilderPlugin):
  def do_filter(p):
    for c in p.commands:
      if isinstance(c,gump.model.Mkdir)
      yield c

  def do_build(p):
    for c in do_filter(p):
      raise NotImplementedError, "TODO: actually create a directory here"
}}}

Or maybe we'd like

{{{
class DependencyStateVerifierPlugin(AbstractPlugin):
  def visit_project(p):
    for rel in p.dependencies:
      if p.rel.dependency.state <= FAILED:
         p.state == PREREQ_FAILURE

class StateAwareWalker(Walker):
  def filter_walk(visitor,project):
    if project.state <= FAILED and not has_attribute(visitor.visit_project, 
"visit_failed"):
      return
    yield y

# NB: the builder plugins are now cleaner again but the mkdir plugin knows that
# it only wants to visit successful projects...
class MkdirPlugin(AbstractPlugin):
  @visit_failed
  visit_project(p):
    raise NotImplementedError, "TODO: actually create a directory here"
}}}

hmm. It might make sense to have a FilteringWalker that supports a different 
kind of plugin, where that plugin can tell the walker to not walk some 
projects. Ugh!

I have a hunch that the real thing to do here is get up to speed on all 
python's fancy list comprehensions, generators and generator expressions. 
There's probably a real elegant way to do this...

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to