Trees | Indices | Help |
|
---|
|
1 ########################################################################### 2 # 3 # This program is part of Zenoss Core, an open source monitoring platform. 4 # Copyright (C) 2008, 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 14 __doc__=''' 15 ZenPackPersistence 16 ''' 17 18 ZENPACK_PERSISTENCE_CATALOG = 'zenPackPersistence' 19 2022 ''' 23 Create the zenPackPersistence catalog if it does not exist. 24 Return the catalog 25 ''' 26 from Products.ZCatalog.ZCatalog import manage_addZCatalog 27 from Products.ZenUtils.Search import makeCaseSensitiveFieldIndex 28 zcat = getattr(dmd, ZENPACK_PERSISTENCE_CATALOG, None) 29 if zcat is None: 30 manage_addZCatalog(dmd, ZENPACK_PERSISTENCE_CATALOG, 31 ZENPACK_PERSISTENCE_CATALOG) 32 zcat = dmd._getOb(ZENPACK_PERSISTENCE_CATALOG) 33 cat = zcat._catalog 34 cat.addIndex('getZenPackName',makeCaseSensitiveFieldIndex('getZenPackName')) 35 cat.addColumn('id') 36 cat.addColumn('getPrimaryId') 37 return zcat38 3941 """ 42 Return a list of all the objects in the zenPackPersistence catalog 43 for the given zenPack name. 44 If the catalog is not found, return None. 45 """ 46 zcat = getattr(dmd, ZENPACK_PERSISTENCE_CATALOG, None) 47 if zcat is None: 48 result = None 49 else: 50 brains = zcat(dict(getZenPackName=packName)) 51 result = [c.getObject() for c in brains] 52 return result53 5456 ''' 57 This is a mix-in class that should be used whenever a ZenPack-supplied 58 class is going to be stored persistently in the zodb. It provides 59 for a catalog to associate objects in zodb with the ZenPacks that provide 60 those objects' classes. 61 62 The motivation for this is that we usually need to delete all instances 63 of zenpack-supplied classes when that zenpack is deleted. This is 64 because the class for those objects no longer exists and they are just 65 sad, broken, unloved objects in the zodb at that point. This is 66 undesirable. 67 68 IMPORTANT: This should be the first class listed in any subclasses's 69 list of parents. Otherwise the manage_* methods of the other classes 70 will likely be called and these skipped. 71 ''' 72 73 # Subclasses should set this to the id of the ZenPack or they 74 # should override getZenPackName() 75 # ZENPACKID = 'ZenPacks.my.name' 7615378 ''' 79 ''' 80 if not self.ZENPACKID: 81 from ZenPack import ZenPackException 82 raise ZenPackException('The class %s must define ZENPACKID ' % 83 str(self.__class__) + 84 'or override getZenPackName().') 85 # Should we check to make sure ZENPACKID matches the name of an 86 # installed ZenPack? 87 return self.ZENPACKID88 8991 """ 92 Return the ZenPack instance that provides this object. 93 """ 94 return context.dmd.ZenPackManager.packs._getOb( 95 self.getZenPackName(), None)96 9799 """ 100 Return the path to the installed ZenPack directory or a subdirectory. 101 Example: zenpack.path('libexec') would return something like 102 $ZENHOME/ZenPacks/ZenPacks.Me.MyZenPack/ZenPacks/Me/MyZenPack/libexec 103 """ 104 zp = self.getZenPack(self) 105 return zp.path(*parts)106 107 108 # index_object and unindex_object are overridden so that instances 109 # can participate in other catalogs, not just the 110 # ZENPACK_PERSISTENCE_CATALOG. 111 # If we used the standard method of just setting default_catalog in 112 # this class then ZenPacks would not be able to override Zenoss 113 # classes that already participate in catalogs, eg DeviceClass. 114116 """A common method to allow Findables to index themselves.""" 117 cat = getattr(self, ZENPACK_PERSISTENCE_CATALOG, None) 118 if cat is not None: 119 cat.catalog_object(self, self.getPrimaryId()) 120 super(ZenPackPersistence, self).index_object()121 122124 """A common method to allow Findables to unindex themselves.""" 125 cat = getattr(self, ZENPACK_PERSISTENCE_CATALOG, None) 126 if cat is not None: 127 cat.uncatalog_object(self.getPrimaryId()) 128 super(ZenPackPersistence, self).unindex_object()129 130 131 # manage_afterAdd, manage_afterClose and manage_beforeDelete 132 # are the magic methods that make the indexing happen 133135 """ 136 """ 137 self.index_object() 138 super(ZenPackPersistence,self).manage_afterAdd(item, container)139 140 146 147149 """ 150 """ 151 super(ZenPackPersistence,self).manage_beforeDelete(item, container) 152 self.unindex_object()
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu May 7 11:46:32 2009 | http://epydoc.sourceforge.net |