1
2
3
4
5
6
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
27 """
28 Utilities for handling ZenPack-provided daemons
29 """
30
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
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
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
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
76
77
78 if __name__ == '__main__':
79 zp = ZenPackDaemons()
80 zp.run()
81