Package Products :: Package ZenModel :: Module ZenPacker |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.ZenPacker

     1  ###########################################################################
     2  #
     3  # This program is part of Zenoss Core, an open source monitoring platform.
     4  # Copyright (C) 2007, Zenoss Inc.
     5  #
     6  # This program is free software; you can redistribute it and/or modify it
     7  # under the terms of the GNU General Public License version 2 as published by
     8  # the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13  import Globals
    14  from AccessControl import ClassSecurityInfo
    15  from Products.ZenWidgets import messaging
    16
    17 -class ZenPacker(object):
    18      security = ClassSecurityInfo()
    19
    20      security.declareProtected('Manage DMD', 'addToZenPack')
    21 -    def addToZenPack(self, ids=(), organizerPaths=(), pack=None, REQUEST=None):
    22          "Add elements from a displayed list of objects to a ZenPack"
    23          from Products.ZenModel.ZenPackable import ZenPackable
    24          from Products.ZenModel.ZenPack import ZenPack
    25          ids = list(ids) + list(organizerPaths)
    26          message = "You must provide a valid ZenPack"
    27          if pack:
    28              pack = self.dmd.ZenPackManager.packs._getOb(pack)
    29              message = 'Saved to %s' % pack.id
    30              if ids:
    31                  for id in ids:
    32                      try:
    33                          obj = self.findObject(id)
    34                      except AttributeError, ex:
    35                          message = str(ex)
    36                          break
    37                      obj.buildRelations()
    38                      pack.packables.addRelation(obj)
    39              else:
    40                  if isinstance(self, ZenPackable):
    41                      self.buildRelations()
    42                      pack.packables.addRelation(self)
    43                  else:
    44                      message = 'Nothing to save'
    45          if REQUEST:
    46              if isinstance(pack, ZenPack):
    47                  messaging.IMessageSender(self).sendToBrowser(
    48                      'Add To ZenPack', message)
    49              return self.callZenScreen(REQUEST)
    50
    51 -    def findObject(self, id):
    52          "Ugly hack for inconsistent object structure accross Organizers"
    53          result = []
    54          try:
    55              result.append(self._getOb(id))
    56          except AttributeError:
    57              pass
    58          for name, relationship in self._relations:
    59              try:
    60                  result.append(getattr(self, name)._getOb(id))
    61              except AttributeError:
    62                  pass
    63          if len(result) == 1:
    64              return result[0]
    65          raise AttributeError('Cannot find a unique %s on %s' % (id, self.id))
    66
    67
    68 -    def eligiblePacks(self):
    69          """
    70          Return a list of zenpacks that objects can be added to.  (The
    71          development mode zenpacks.)
    72          """
    73          return [zp for zp in self.dmd.ZenPackManager.packs()
    74                  if zp.isDevelopment()]
    75