| Trees | Indices | Help |
|
|---|
|
|
1 ###########################################################################
2 #
3 # This program is part of Zenoss Core, an open source monitoring platform.
4 # Copyright (C) 2007, Zenoss Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License version 2 as published by
8 # the Free Software Foundation.
9 #
10 # For complete information please visit: http://www.zenoss.com/oss/
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 getObjByPath, zenPath
19
20 import os
21 import ConfigParser
22 import logging
23 log = logging.getLogger('zen.ZPLoader')
24
25 CONFIG_FILE = 'about.txt'
26 CONFIG_SECTION_ABOUT = 'about'
27
29 result = []
30 for p, ds, fs in os.walk(pack.path(directory)):
31 if not os.path.split(p)[-1].startswith('.'):
32 for f in fs:
33 if filter is None or filter(f):
34 result.append(os.path.join(p, f))
35 return result
36
38 result = []
39 for p, ds, fs in os.walk(pack.path(directory)):
40 if not os.path.split(p)[-1].startswith('.'):
41 for d in ds:
42 result.append(os.path.join(p, d))
43 return result
44
46 "return the branch after the given directory name"
47 path = filename.split('/')
48 return prefix + '/'.join(path[path.index(directory)+1:])
49
50
67
68 from xml.sax import saxutils, make_parser
69 from xml.sax.handler import ContentHandler
70
72
73 name = "Objects"
74
76 from Products.ZenRelations.ImportRM import ImportRM
77 class AddToPack(ImportRM):
78 def endElement(self, name):
79 if name == 'object':
80 obj = self.objstack[-1]
81 log.debug('Now adding %s', obj.getPrimaryUrlPath())
82 try:
83 obj.buildRelations()
84 obj.removeRelation('pack')
85 obj.addRelation('pack', pack)
86 except Exception, ex:
87 log.exception("Error adding pack to %s",
88 obj.getPrimaryUrlPath())
89
90 ImportRM.endElement(self, name)
91 importer = AddToPack(noopts=True, app=app)
92 importer.options.noindex = True
93 for f in self.objectFiles(pack):
94 log.info("Loading %s", f)
95 importer.loadObjectFromXML(xmlfile=f)
96
97
102
103
105 from Products.ZenRelations.Exceptions import ObjectNotFound
106 dmd = app.zport.dmd
107 objs = pack.packables()
108 objs.sort(lambda x, y: cmp(x.getPrimaryPath(), y.getPrimaryPath()))
109 objs.reverse()
110 for obj in objs:
111 path = obj.getPrimaryPath()
112 path, id = path[:-1], path[-1]
113 obj = dmd.getObjByPath(path)
114 if len(path) > 3: # leave /Services, /Devices, etc.
115 try:
116 try:
117 obj._delObject(id)
118 except ObjectNotFound:
119 obj._delOb(id)
120 except (AttributeError, KeyError), ex:
121 log.warning("Unable to remove %s on %s", id,
122 '/'.join(path))
123
125 return [obj.getPrimaryUrlPath() for obj in pack.packables()]
126
127
131
132
134
135 name = "Reports"
136
138 class HookReportLoader(ReportLoader):
139 def loadFile(self, root, id, fullname):
140 rpt = ReportLoader.loadFile(self, root, id, fullname)
141 rpt.addRelation('pack', pack)
142 return rpt
143 rl = HookReportLoader(noopts=True, app=app)
144 rl.options.force = True
145 rl.loadDirectory(pack.path('reports'))
146
148 self.load(pack, app)
149
152
153
155
156 name = "Daemons"
157
158 extensionsToIgnore = ('.svn-base', '.pyc' '~')
164
165
168
170 for fs in findFiles(pack, 'daemons', filter=self.filter):
171 os.chmod(fs, 0755)
172 path = self.binPath(fs)
173 if os.path.exists(path):
174 os.remove(path)
175 os.symlink(fs, self.binPath(fs))
176
178 self.load(pack, app)
179
181 for fs in findFiles(pack, 'daemons', filter=self.filter):
182 try:
183 os.remove(self.binPath(fs))
184 except OSError:
185 pass
186
190
191
193
194 name = "Bin"
195
196 extensionsToIgnore = ('.svn-base', '.pyc' '~')
202
206
208 self.load(pack, app)
209
213
214
216
217 name = "LibExec"
218
219 extensionsToIgnore = ('.svn-base', '.pyc' '~')
225
229
231 self.load(pack, app)
232
236
237
246
247
249
250 name = "Skins"
251
252
254 from Products.ZenUtils.Skins import registerSkin
255 from Products.ZenUtils.Utils import getObjByPath
256 registerSkin(app.zport.dmd, pack.path(''))
257
258
260 from Products.ZenUtils.Skins import unregisterSkin
261 unregisterSkin(app.zport.dmd, pack.path(''))
262
263
266
267
269
270 name = "DataSources"
271
272
274 return [branchAfter(d, 'datasources')
275 for d in findFiles(pack, 'datasources',
276 lambda f: not f.endswith('.pyc') and f != '__init__.py')]
277
278
289
291
292 name = "About"
293
295 about = pack.path(CONFIG_FILE)
296 result = []
297 if os.path.exists(about):
298 parser = ConfigParser.SafeConfigParser()
299 parser.read(about)
300 result = []
301 for key, value in parser.items(CONFIG_SECTION_ABOUT):
302 try:
303 value = eval(value)
304 except:
305 # Blanket exception catchers like this are evil.
306 pass
307 result.append((key, value))
308 return result
309
310
314
315
317 self.load(pack, app)
318
319
321 return [('%s %s' % av) for av in self.getAttributeValues(pack)]
322
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Thu Oct 25 16:28:37 2007 | http://epydoc.sourceforge.net |