1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__='Base Classes for loading gunk in a ZenPack'
15
16 import Globals
17 from Products.ZenReports.ReportLoader import ReportLoader
18 from Products.ZenUtils.Utils import zenPath, binPath
19
20 import os
21 import ConfigParser
22 import subprocess
23 import logging
24 log = logging.getLogger('zen.ZPLoader')
25
26 CONFIG_FILE = 'about.txt'
27 CONFIG_SECTION_ABOUT = 'about'
28
30 result = []
31 if isinstance(pack, basestring):
32 path = os.path.join(pack, directory)
33 else:
34 path = pack.path(directory)
35 for p, ds, fs in os.walk(path):
36 if not os.path.split(p)[-1].startswith('.'):
37 for f in fs:
38 if filter is None or filter(f):
39 result.append(os.path.join(p, f))
40 return result
41
43 result = []
44 for p, ds, fs in os.walk(pack.path(directory)):
45 if not os.path.split(p)[-1].startswith('.'):
46 for d in ds:
47 result.append(os.path.join(p, d))
48 return result
49
51 "return the branch after the given directory name"
52 path = filename.split('/')
53 return prefix + '/'.join(path[path.index(directory)+1:])
54
55
57
58 name = "Set This Name"
59
60 - def load(self, pack, app):
61 """Load things from the ZenPack and put it
62 into the app"""
63
64 - def unload(self, pack, app, leaveObjects=False):
65 """Remove things from Zenoss defined in the ZenPack"""
66
67 - def list(self, pack, app):
68 "List the items that would be loaded from the given (unpacked) ZenPack"
69
71 "Run an upgrade on an existing pack"
72
73 from xml.sax import make_parser
74
76
77 name = "Objects"
78
79 - def load(self, pack, app):
95 importer = AddToPack(noopts=True, app=app)
96 importer.options.noindex = True
97 for f in self.objectFiles(pack):
98 log.info("Loading %s", f)
99 importer.loadObjectFromXML(xmlfile=f)
100
101
102 - def parse(self, filename, handler):
106
107
108 - def unload(self, pack, app, leaveObjects=False):
129
130 - def list(self, pack, unused):
132
133
135 def isXml(f): return f.endswith('.xml')
136 return findFiles(pack, 'objects', isXml)
137
138
140
141 name = "Reports"
142
143 - def load(self, pack, app):
149 rl = HookReportLoader(noopts=True, app=app)
150 rl.options.force = True
151 rl.loadDirectory(pack.path('reports'))
152
154 self.unload(pack, app)
155 self.load(pack, app)
156
157 - def list(self, pack, unused):
159
160
162
163 name = "Daemons"
164
165 extensionsToIgnore = ('.svn-base', '.pyc' '~')
167 for ext in self.extensionsToIgnore:
168 if f.endswith(ext):
169 return False
170 return True
171
172
175
176
178 """
179 Attempt to generate a conf file for any daemons.
180 """
181
182
183
184 try:
185 subprocess.Popen(binPath('create_sample_config.sh'),
186 stdout=subprocess.PIPE,
187 stderr=subprocess.PIPE,
188 cwd=pack.path())
189 except OSError:
190 pass
191
192
193 - def load(self, pack, unused):
201
202
204 self.unload(pack, app)
205 self.load(pack, app)
206
207
208 - def unload(self, pack, unused, leaveObjects=False):
214
215 - def list(self, pack, unused):
218
219
221
222 name = "Bin"
223
224 extensionsToIgnore = ('.svn-base', '.pyc' '~')
226 for ext in self.extensionsToIgnore:
227 if f.endswith(ext):
228 return False
229 return True
230
231 - def load(self, pack, unused):
234
236 self.unload(pack, app)
237 self.load(pack, app)
238
239 - def list(self, pack, unused):
242
243
245
246 name = "LibExec"
247
248 extensionsToIgnore = ('.svn-base', '.pyc' '~')
250 for ext in self.extensionsToIgnore:
251 if f.endswith(ext):
252 return False
253 return True
254
255 - def load(self, pack, unused):
258
260 self.unload(pack, app)
261 self.load(pack, app)
262
263 - def list(self, pack, unused):
266
267
269
270 name = "Modeler Plugins"
271
272
273 - def list(self, pack, unused):
276
277
279
280 name = "Skins"
281
282
283 - def load(self, pack, app):
288
289
291 self.unload(pack, app)
292 return self.load(pack, app)
293
294
295 - def unload(self, pack, app, leaveObjects=False):
300
301
302 - def list(self, pack, unused):
304
305
307
308 name = "DataSources"
309
310
311 - def list(self, pack, unused):
312 return [branchAfter(d, 'datasources')
313 for d in findFiles(pack, 'datasources',
314 lambda f: not f.endswith('.pyc') and f != '__init__.py')]
315
316
317
319
320 name = "Libraries"
321
322
323 - def list(self, pack, unused):
324 d = pack.path('lib')
325 if os.path.isdir(d):
326 return [l for l in os.listdir(d)]
327 return []
328
330
331 name = "About"
332
348
349
350 - def load(self, pack, unused):
353
354
357
358
359 - def list(self, pack, unused):
361