
"""Utility classes to enhance process.properties.Properties usefulness."""


from buildbot.process.properties import WithProperties


class ListProperties(WithProperties):
  """Act like a list but skip over items that are None.

  This class doesn't use WithProperties methods but inherits from it since it is
  used as a flag in Properties.render() to defer the actual work to
  self.render()."""

  compare_attrs = ('items')

  def __init__(self, items):
    """items should be a list."""
    # Dummy initialization.
    WithProperties.__init__(self, '')
    self.items = items

  def render(self, pmap):
    results = []
    # For each optional item, look up the corresponding property in the
    # PropertyMap.
    for item in self.items:
      if isinstance(item, WithProperties):
        item = item.render(pmap)
      # Skip over None items.
      if item is not None and item != '':
        results.append(item)
    return results


"""Utility classes to enhance process.properties.Properties usefulness."""


from buildbot.process.properties import WithProperties


class ListProperties(WithProperties):
  """Act like a list but skip over items that are None.

  This class doesn't use WithProperties methods but inherits from it since it is
  used as a flag in Properties.render() to defer the actual work to
  self.render()."""

  compare_attrs = ('items')

  def __init__(self, items):
    """items should be a list."""
    # Dummy initialization.
    WithProperties.__init__(self, '')
    self.items = items

  # For buildbot 8.4 and below.
  def render(self, pmap):
    results = []
    # For each optional item, look up the corresponding property in the
    # PropertyMap.
    for item in self.items:
      if isinstance(item, WithProperties):
        item = item.render(pmap)
      # Skip over None items.
      if item is not None and item != '':
        results.append(item)
    return results

  # For buildbot 8.4p1 and above.
  def getRenderingFor(self, build):
    results = []
    # For each optional item, look up the corresponding property in the
    # PropertyMap.
    for item in self.items:
      if isinstance(item, WithProperties):
        item = item.getRenderingFor(build)
      # Skip over None items.
      if item is not None and item != '':
        results.append(item)
    return results

Fix ListProperties to be compatible with buildbot 0.8.4p1.
Fix ListProperties to be compatible with buildbot 0.8.4p1.

The duplicated code will be removed once 0.7.12 is removed.

Review URL: http://codereview.chromium.org/7193037

git-svn-id: 239fca9b83025a0b6f823aeeca02ba5be3d9fd76@91477 0039d316-1c4b-4281-b951-d872f2087c98

  
  """Utility classes to enhance process.properties.Properties usefulness."""
  
  
  from buildbot.process.properties import WithProperties
  
  
  class ListProperties(WithProperties):
    """Act like a list but skip over items that are None.
  
    This class doesn't use WithProperties methods but inherits from it since it is
    used as a flag in Properties.render() to defer the actual work to
    self.render()."""
  
    compare_attrs = ('items')
  
    def __init__(self, items):
      """items should be a list."""
      # Dummy initialization.
      WithProperties.__init__(self, '')
      self.items = items
  
+   # For buildbot 8.4 and below.
    def render(self, pmap):
      results = []
      # For each optional item, look up the corresponding property in the
      # PropertyMap.
      for item in self.items:
        if isinstance(item, WithProperties):
          item = item.render(pmap)
        # Skip over None items.
        if item is not None and item != '':
          results.append(item)
      return results
  
+   # For buildbot 8.4p1 and above.
+   def getRenderingFor(self, build):
+     results = []
+     # For each optional item, look up the corresponding property in the
+     # PropertyMap.
+     for item in self.items:
+       if isinstance(item, WithProperties):
+         item = item.getRenderingFor(build)
+       # Skip over None items.
+       if item is not None and item != '':
+         results.append(item)
+     return results
+ 
Fix ListProperties to be compatible with buildbot 0.8.4p1.
## Code Before:

"""Utility classes to enhance process.properties.Properties usefulness."""


from buildbot.process.properties import WithProperties


class ListProperties(WithProperties):
  """Act like a list but skip over items that are None.

  This class doesn't use WithProperties methods but inherits from it since it is
  used as a flag in Properties.render() to defer the actual work to
  self.render()."""

  compare_attrs = ('items')

  def __init__(self, items):
    """items should be a list."""
    # Dummy initialization.
    WithProperties.__init__(self, '')
    self.items = items

  def render(self, pmap):
    results = []
    # For each optional item, look up the corresponding property in the
    # PropertyMap.
    for item in self.items:
      if isinstance(item, WithProperties):
        item = item.render(pmap)
      # Skip over None items.
      if item is not None and item != '':
        results.append(item)
    return results

## Instruction:
Fix ListProperties to be compatible with buildbot 0.8.4p1.
## Code After:

"""Utility classes to enhance process.properties.Properties usefulness."""


from buildbot.process.properties import WithProperties


class ListProperties(WithProperties):
  """Act like a list but skip over items that are None.

  This class doesn't use WithProperties methods but inherits from it since it is
  used as a flag in Properties.render() to defer the actual work to
  self.render()."""

  compare_attrs = ('items')

  def __init__(self, items):
    """items should be a list."""
    # Dummy initialization.
    WithProperties.__init__(self, '')
    self.items = items

  # For buildbot 8.4 and below.
  def render(self, pmap):
    results = []
    # For each optional item, look up the corresponding property in the
    # PropertyMap.
    for item in self.items:
      if isinstance(item, WithProperties):
        item = item.render(pmap)
      # Skip over None items.
      if item is not None and item != '':
        results.append(item)
    return results

  # For buildbot 8.4p1 and above.
  def getRenderingFor(self, build):
    results = []
    # For each optional item, look up the corresponding property in the
    # PropertyMap.
    for item in self.items:
      if isinstance(item, WithProperties):
        item = item.getRenderingFor(build)
      # Skip over None items.
      if item is not None and item != '':
        results.append(item)
    return results
