1
2
3
4
5
6
7
8
9
10
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
30 """
31 Utilities for handling ZenPack-provided daemons
32 """
33
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
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
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
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
79
80
81 if __name__ == '__main__':
82 zp = ZenPackDaemons()
83 zp.run()
84