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

Source Code for Module 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   
16 -class ZenPacker(object):
17 security = ClassSecurityInfo() 18 19 security.declareProtected('Manage DMD', 'addToZenPack')
20 - def addToZenPack(self, ids=(), organizerPaths=(), pack=None, REQUEST=None):
21 "Add elements from a displayed list of objects to a ZenPack" 22 from Products.ZenModel.ZenPackable import ZenPackable 23 from Products.ZenModel.ZenPack import ZenPack 24 ids = list(ids) + list(organizerPaths) 25 message = "You must provide a valid ZenPack" 26 if pack: 27 pack = self.dmd.packs._getOb(pack) 28 message = 'Saved to %s' % pack.id 29 if ids: 30 for id in ids: 31 try: 32 obj = self.findObject(id) 33 except AttributeError, ex: 34 message = str(ex) 35 break 36 obj.buildRelations() 37 pack.packables.addRelation(obj) 38 else: 39 if isinstance(self, ZenPackable): 40 self.buildRelations() 41 pack.packables.addRelation(self) 42 else: 43 message = 'Nothing to save' 44 if REQUEST: 45 if isinstance(pack, ZenPack): 46 REQUEST['message'] = message 47 return self.callZenScreen(REQUEST)
48
49 - def findObject(self, id):
50 "Ugly hack for inconsistent object structure accross Organizers" 51 result = [] 52 try: 53 result.append(self._getOb(id)) 54 except AttributeError: 55 pass 56 for name, relationship in self._relations: 57 try: 58 result.append(getattr(self, name)._getOb(id)) 59 except AttributeError: 60 pass 61 if len(result) == 1: 62 return result[0] 63 raise AttributeError('Cannot find a unique %s on %s' % (id, self.id))
64