1
2
3
4
5
6
7
8
9
10
11
12
13 __doc__ = "Convert old-style zenpacks to zenpack eggs"
14
15 import Globals
16 from Products.ZenUtils.ZenScriptBase import ZenScriptBase
17 from Products.ZenModel.ZenPack import ZenPackException
18 from Utils import zenPath
19 import ZenPackCmd
20 import os, sys
21 import shutil
22
23
25 "Eggify ZenPacks"
26
28 if not self.options.newid:
29 raise ZenPackException('You must specify a new id with the'
30 ' --newid option.')
31 zpName = self.args[0]
32 if not os.path.isdir(zenPath('Products', zpName)):
33 raise ZenPackException('Can not locate %s.' % zpName +
34 ' This command only operates on installed ZenPacks.')
35 (possible, msgOrId) = ZenPackCmd.CanCreateZenPack(
36 None, self.options.newid)
37 if possible:
38 newId = msgOrId
39 else:
40 raise ZenPackException('Unable to eggify %s: %s' % (
41 zpName, msgOrId))
42
43 self.connect()
44
45
46 eggDir = ZenPackCmd.CreateZenPack(newId, prevZenPackName=zpName)
47
48
49 parts = newId.split('.')
50 zpDir = os.path.join(eggDir, *parts)
51 os.system('rm -rf %s' % zpDir)
52 shutil.copytree(zenPath('Products', zpName), zpDir, symlinks=False)
53
54
55 skinsDir = os.path.join(zpDir, 'skins', zpName)
56 if not os.path.isdir(skinsDir):
57 os.makedirs(skinsDir)
58
59
60 ZenPackCmd.InstallEggAndZenPack(self.dmd, eggDir, link=True)
61
62
63 pack = self.dmd.ZenPackManager.packs._getOb(zpName, None)
64 success = pack and pack.isEggPack()
65
66 if success:
67 print('%s successfully converted to %s.' % (zpName, newId))
68 print('The code for %s is located at $ZENHOME/ZenPacks/%s' %
69 (newId, newId))
70 print('NOTE: If your ZenPack provides DataSource classes '
71 'or any other python class for objects that are stored '
72 'in the object database then further steps are '
73 'required. Please see the Zenoss Developer Guide for '
74 'more instructions.')
75
77 self.parser.add_option('--newid',
78 dest='newid',
79 default=None,
80 help='Specify a new name for this ZenPack. '
81 'It must contain at least three package names '
82 'separated by periods, the first one being '
83 '"ZenPacks"')
84 ZenScriptBase.buildOptions(self)
85
86
87 if __name__ == '__main__':
88 e = Eggify()
89 try:
90 e.run()
91 except ZenPackException, e:
92 import sys
93 sys.stderr.write('%s\n' % str(e))
94 sys.exit(-1)
95