Package Products :: Package ZenUtils :: Module ZenPackDaemons
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenUtils.ZenPackDaemons

 1  ############################################################################## 
 2  #  
 3  # Copyright (C) Zenoss, Inc. 2008, 2009, all rights reserved. 
 4  #  
 5  # This content is made available according to terms specified in 
 6  # License.zenoss under the directory where your Zenoss product is installed. 
 7  #  
 8  ############################################################################## 
 9   
10   
11  __doc__ = """zenpackdaemons 
12  Manage ZenPack-provided daemons 
13  """ 
14   
15  import os 
16   
17  import Globals 
18  from Products.ZenUtils.PkgResources import pkg_resources 
19   
20  from Products.ZenUtils.ZenScriptBase import ZenScriptBase 
21  from Products.ZenUtils.ZenPackCmd import ZENPACK_ENTRY_POINT 
22  from Products.ZenModel.ZenPackLoader import ZPLDaemons 
23  from Products.ZenUtils.Utils import zenPath 
24   
25   
26 -class ZenPackDaemons(ZenScriptBase):
27 """ 28 Utilities for handling ZenPack-provided daemons 29 """ 30
31 - def nameZenPackDaemons(self, zenPackId=None):
32 """ 33 Return a list of the names of the daemons provided by the given ZenPack. 34 If no ZenPack is specified then list all daemons provided by all ZenPacks. 35 """ 36 dList = [] 37 zpl = ZPLDaemons() 38 # Get daemons from egg-based ZenPacks 39 for entry in pkg_resources.iter_entry_points(ZENPACK_ENTRY_POINT): 40 try: 41 module = entry.load() 42 dList += zpl.list(os.path.dirname(module.__file__), None) 43 except Exception, ex: 44 summary = "The ZenPack %s cannot be imported -- skipping." % entry.name 45 self.log.exception(summary) 46 47 # Get daemons from non-egg ZenPacks 48 prodDir = zenPath('Products') 49 for item in os.listdir(prodDir): 50 if not item.startswith('.'): 51 dList += zpl.list(os.path.join(prodDir, item), None) 52 return dList
53 54
55 - def run(self):
56 """ 57 Execute the user's request. 58 """ 59 60 if self.options.list: 61 dList = self.nameZenPackDaemons() 62 if dList: 63 print '\n'.join(dList) 64 else: 65 self.parser.print_help()
66 67
68 - def buildOptions(self):
69 self.parser.add_option('--list', 70 dest='list', 71 default=False, 72 action='store_true', 73 help='List the names of ZenPack-supplied daemons' 74 ) 75 ZenScriptBase.buildOptions(self)
76 77 78 if __name__ == '__main__': 79 zp = ZenPackDaemons() 80 zp.run() 81