1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""ManufacturerRoot
15
16 The Manufacturer classification class. default identifiers and screens,
17 live here.
18
19 $Id: ManufacturerRoot.py,v 1.10 2004/04/22 02:14:12 edahl Exp $"""
20
21 __version__ = "$Revision: 1.10 $"[11:-2]
22
23 import logging
24 log = logging.getLogger('zen')
25
26 import transaction
27
28 from Globals import InitializeClass
29 from Globals import DTMLFile
30 from Acquisition import aq_base
31 from AccessControl import Permissions as permissions
32
33 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
34 from Products.ZenRelations.PrimaryPathObjectManager import \
35 PrimaryPathBTreeFolder2
36
37 from ZenModelBase import ZenModelBase
38 from ZenPacker import ZenPacker
39 from Products.ZenUtils.Search import makeCaseSensitiveKeywordIndex
40
48
49
50
51
52
54 """
55 The root organizer for manufacturers. May become a BtreeFolder2 at
56 some point (to scale better). Has interface to manage Manufacturers
57 and the products that they create.
58 """
59 dmdRootName = "Manufacturers"
60 meta_type = "ManufacturerRoot"
61 sub_classes = ('Manufacturer',)
62 default_catalog = "productSearch"
63
64
65 factory_type_information = (
66 {
67 'id' : 'Manufacturer',
68 'meta_type' : 'Manufacturer',
69 'description' : """Arbitrary device grouping class""",
70 'icon' : 'Manufacturer_icon.gif',
71 'product' : 'ZenModel',
72 'factory' : 'manage_addManufacturer',
73 'immediate_view' : 'viewManufacturers',
74 'actions' :
75 (
76 { 'id' : 'overview'
77 , 'name' : 'Overview'
78 , 'action' : 'viewManufacturers'
79 , 'permissions' : (
80 permissions.view, )
81 },
82 { 'id' : 'viewHistory'
83 , 'name' : 'Modifications'
84 , 'action' : 'viewHistory'
85 , 'permissions' : (
86 permissions.view, )
87 },
88 )
89 },
90 )
91
92
98
99
106
107
114
115
126
127
129 """Return manufacturerName.
130 If trying to get Unknown and it doesn't exist, create it
131 """
132 createOnDemand = ['Unknown']
133 if not self.has_key(manufacturerName) \
134 and manufacturerName in createOnDemand:
135 man = self.createManufacturer(manufacturerName)
136 else:
137 man = self._getOb(manufacturerName)
138 return man
139
141 """return list of all companies"""
142 return self.objectIds(spec=("Manufacturer"))
143
144
146 """return a list of all products this Manufacturer makes"""
147 osFlag=False
148 if type=="OS": osFlag = True
149 prods = [""]
150 if hasattr(self, mname):
151 manuf = self.getManufacturer(mname)
152 if osFlag:
153 for prod in manuf.products.objectValues(spec="SoftwareClass"):
154 if prod.isOS: prods.append(prod.id)
155 else: prods.extend(manuf.products.objectIds(spec=type))
156 prods.sort()
157 return prods
158
159
171
172
178
179
187
188
189 - def _getProduct(self, prodName, manufacturer, factory, **kwargs):
190 prod = None
191 prodid = self.prepId(prodName)
192 if not manufacturer or manufacturer == "Unknown":
193 prod = self.findProduct(prodName)
194 if prod: return prod
195 manufobj = self.getManufacturer(manufacturer)
196 prod = manufobj._getOb(prodid, None)
197 if not prod:
198 prod = factory(prodid, prodName=prodName, **kwargs)
199 manufobj.products._setObject(prodid, prod)
200 prod = manufobj.products._getOb(prodid)
201 return prod
202
203
205 """Return a generator that gets all products.
206 """
207 for manuf in self.values(spec="Manufacturer"):
208 for prod in manuf.products.objectValuesGen():
209 yield prod
210
211
220
221
233
234
236 """Return an xml based representation of a RelationshipManager
237 <object id='/Devices/Servers/Windows/dhcp160.confmon.loc'
238 module='Products.Confmon.IpInterface' class='IpInterface'>
239 <property id='name'>jim</property>
240 <toone></toone>
241 <tomany></tomany>
242 <tomanycont></tomanycont>
243 </object>
244 """
245 modname = self.__class__.__module__
246 classname = self.__class__.__name__
247 id = root and self.getPrimaryId() or self.id
248 stag = "<object id='%s' module='%s' class='%s'>\n" % (
249 id , modname, classname)
250 ofile.write(stag)
251 for obj in self.objectValues():
252 if getattr(aq_base(obj), 'exportXml', False):
253 obj.exportXml(ofile, ignorerels)
254 ofile.write("</object>\n")
255
256
262
263
264 InitializeClass(ManufacturerRoot)
265