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

Source Code for Module Products.ZenUtils.ZenPackDaemons

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2008, 2009 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 or (at your 
 8  # option) any later version as published by the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13   
14  __doc__ = """zenpackdaemons 
15  Manage ZenPack-provided daemons 
16  """ 
17   
18  import os 
19   
20  import Globals 
21  from Products.ZenUtils.PkgResources import pkg_resources 
22   
23  from Products.ZenUtils.ZenScriptBase import ZenScriptBase 
24  from Products.ZenUtils.ZenPackCmd import ZENPACK_ENTRY_POINT 
25  from Products.ZenModel.ZenPackLoader import ZPLDaemons 
26  from Products.ZenUtils.Utils import zenPath 
27   
28   
29 -class ZenPackDaemons(ZenScriptBase):
30 """ 31 Utilities for handling ZenPack-provided daemons 32 """ 33
34 - def nameZenPackDaemons(self, zenPackId=None):
35 """ 36 Return a list of the names of the daemons provided by the given ZenPack. 37 If no ZenPack is specified then list all daemons provided by all ZenPacks. 38 """ 39 dList = [] 40 zpl = ZPLDaemons() 41 # Get daemons from egg-based ZenPacks 42 for entry in pkg_resources.iter_entry_points(ZENPACK_ENTRY_POINT): 43 try: 44 module = entry.load() 45 dList += zpl.list(os.path.dirname(module.__file__), None) 46 except Exception, ex: 47 summary = "The ZenPack %s cannot be imported -- skipping." % entry.name 48 self.log.exception(summary) 49 50 # Get daemons from non-egg ZenPacks 51 prodDir = zenPath('Products') 52 for item in os.listdir(prodDir): 53 if not item.startswith('.'): 54 dList += zpl.list(os.path.join(prodDir, item), None) 55 return dList
56 57
58 - def run(self):
59 """ 60 Execute the user's request. 61 """ 62 63 if self.options.list: 64 dList = self.nameZenPackDaemons() 65 if dList: 66 print '\n'.join(dList) 67 else: 68 self.parser.print_help()
69 70
71 - def buildOptions(self):
72 self.parser.add_option('--list', 73 dest='list', 74 default=False, 75 action='store_true', 76 help='List the names of ZenPack-supplied daemons' 77 ) 78 ZenScriptBase.buildOptions(self)
79 80 81 if __name__ == '__main__': 82 zp = ZenPackDaemons() 83 zp.run() 84