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