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

Source Code for Module ZenUtils.ZenPackDaemons

 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__ = "Manage ZenPack-provided daemons" 
15   
16  import Globals 
17  import os 
18   
19  from Products.ZenUtils.PkgResources import pkg_resources 
20   
21  from Products.ZenUtils.CmdBase import CmdBase 
22  from Products.ZenUtils.ZenPackCmd import ZENPACK_ENTRY_POINT 
23  from Products.ZenModel.ZenPackLoader import ZPLDaemons 
24  from Products.ZenUtils.Utils import zenPath 
25   
26   
27 -def NameZenPackDaemons(zenPackId=None):
28 """ 29 Return a list of the names of the daemons provided by the given ZenPack. 30 If no ZenPack is specified then list all daemons provided by all ZenPacks. 31 """ 32 dList = [] 33 zpl = ZPLDaemons() 34 # Get daemons from egg based ZenPacks 35 for entry in pkg_resources.iter_entry_points(ZENPACK_ENTRY_POINT): 36 module = entry.load() 37 dList += zpl.list(os.path.dirname(module.__file__), None) 38 # Get daemons from non-egg ZenPacks 39 prodDir = zenPath('Products') 40 for item in os.listdir(prodDir): 41 if not item.startswith('.'): 42 dList += zpl.list(os.path.join(prodDir, item), None) 43 return dList
44 45
46 -class ZenPackDaemons(CmdBase):
47 """ 48 Utilities for handling ZenPack-provided daemons 49 """ 50
51 - def run(self):
52 """ 53 Execute the user's request. 54 """ 55 56 if self.options.list: 57 dList = NameZenPackDaemons() 58 if dList: 59 print '\n'.join(dList) 60 else: 61 self.parser.print_help()
62 63
64 - def buildOptions(self):
65 self.parser.add_option('--list', 66 dest='list', 67 default=False, 68 action='store_true', 69 help='List the names of ZenPack-supplied daemons' 70 ) 71 CmdBase.buildOptions(self)
72 73 74 if __name__ == '__main__': 75 zp = ZenPackDaemons() 76 zp.run() 77