1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import operator
19 from cStringIO import StringIO
20 from xml.sax.saxutils import quoteattr
21
22 from flumotion.common.xmlwriter import cmpComponentType, XMLWriter
23 from flumotion.configure import configure
24
25 __version__ = "$Rev: 6246 $"
26
27
29 """I am responsible for writing the state of a flow created by the
30 configuration assistant into XML.
31 I will try my best write pretty XML which can be editable by humans at a
32 later point.
33 """
34
35 - def __init__(self, flowName, flowComponents, atmosphereComponents):
36 """
37 @param flowName: name of the flow
38 @param flowComponents: components to be included in the flow
39 @param atmosphereComponents: components to be included
40 in the atmosphere
41 """
42 super(ConfigurationWriter, self).__init__()
43 self._flowName = flowName
44 self._flowComponents = flowComponents
45 self._atmosphereComponents = atmosphereComponents
46 self._writePlanet()
47
53
60
67
74
76
77
78
79 if component.exists:
80 return
81
82
83
84 attrs = [('name', component.name),
85 ('type', component.componentType),
86 ('project', configure.PACKAGE),
87 ('worker', component.worker),
88 ('version', configure.version)]
89 self.pushTag('component', attrs)
90 self._writeEaters(component.getEaters())
91 self._writeProperties(component.getProperties())
92 self._writeComponentPlugs(component.plugs)
93 self.popTag()
94
96 eaters = list(eaters)
97 if not eaters:
98 return
99 self.pushTag('eater', [('name', "default")])
100 for sourceName in eaters:
101 self.writeTag('feed', data=sourceName)
102 self.popTag()
103
105 if not properties:
106 return
107 self.writeLine()
108 propertyNames = properties.keys()
109 propertyNames.sort()
110
111 def serialize(propVal):
112 if isinstance(propVal, tuple):
113 return ["%d/%d" % propVal]
114 elif isinstance(propVal, list):
115 return propVal
116 else:
117 return [propVal]
118 for name, value in properties.items():
119 attrs = [('name', name)]
120 for value in serialize(value):
121 if isinstance(value, dict):
122 self.pushTag('compound-property', attrs)
123 self._writeProperties(value)
124 self.popTag()
125 else:
126 self.writeTag('property', attrs, value)
127
136
141