Trees | Indices | Help |
---|
|
1 # -*- Mode: Python; test-case-name: flumotion.test.test_wizard -*- 2 # vi:si:et:sw=4:sts=4:ts=4 3 # 4 # Flumotion - a streaming media server 5 # Copyright (C) 2004,2005,2006,2007,2008 Fluendo, S.L. (www.fluendo.com). 6 # All rights reserved. 7 8 # This file may be distributed and/or modified under the terms of 9 # the GNU General Public License version 2 as published by 10 # the Free Software Foundation. 11 # This file is distributed without any warranty; without even the implied 12 # warranty of merchantability or fitness for a particular purpose. 13 # See "LICENSE.GPL" in the source distribution for more information. 14 15 # Licensees having purchased or holding a valid Flumotion Advanced 16 # Streaming Server license may use this file in accordance with the 17 # Flumotion Advanced Streaming Server Commercial License Agreement. 18 # See "LICENSE.Flumotion" in the source distribution for more information. 19 20 # Headers in this file shall remain intact. 21 22 from cStringIO import StringIO 23 from xml.sax.saxutils import quoteattr 24 25 from flumotion.common.xmlwriter import cmpComponentType, XMLWriter 26 from flumotion.configure import configure 27 28 __version__ = "$Rev: 6246 $" 29 3032 """I am responsible for writing the state of a flow created by the 33 configuration assistant into XML. 34 I will try my best write pretty XML which can be editable by humans at a 35 later point. 36 """ 378539 """ 40 @param flowName: name of the flow 41 @param flowComponents: components to be included in the flow 42 @param atmosphereComponents: components to be included 43 in the atmosphere 44 """ 45 super(ConfigurationWriter, self).__init__() 46 self._flowName = flowName 47 self._flowComponents = flowComponents 48 self._atmosphereComponents = atmosphereComponents 49 self._writePlanet()5052 self.pushTag('planet') 53 self._writeAtmosphere(self._atmosphereComponents) 54 self._writeFlow(self._flowName, self._flowComponents) 55 self.popTag()5658 if not components: 59 return 60 self.pushTag('atmosphere') 61 self._writeComponents(components) 62 self.popTag()6365 if not components: 66 return 67 self.pushTag('flow', [('name', flowName)]) 68 self._writeComponents(components) 69 self.popTag()7072 # FIXME: When we can depend on Python 2.4, use 73 # sorted(flow.get('components'), 74 # cmp=cmpComponentType, 75 # key=operator.attrgetter('componentType')) 76 # 77 78 def componentSort(a, b): 79 return cmpComponentType(a.componentType, 80 b.componentType)81 components = list(components) 82 components.sort(cmp=componentSort) 83 for component in components: 84 self._writeComponent(component)87 # Do not write components which already exists in the flow, 88 # This is used to create configuration snippets sent to the 89 # asssistant which links to existing components 90 if component.exists: 91 return 92 93 # FIXME: when the assistant can be split among projects, "project" 94 # and "version" should be taken from the relevant project 95 attrs = [('name', component.name), 96 ('type', component.componentType), 97 ('project', configure.PACKAGE), 98 ('worker', component.worker), 99 ('version', configure.version)] 100 self.pushTag('component', attrs) 101 self._writeEaters(component.getEaters()) 102 self._writeProperties(component.getProperties()) 103 self._writeComponentPlugs(component.plugs) 104 self.popTag()105107 eaters = list(eaters) 108 if not eaters: 109 return 110 self.pushTag('eater', [('name', "default")]) 111 for sourceName in eaters: 112 self.writeTag('feed', data=sourceName) 113 self.popTag()114116 if not properties: 117 return 118 self.writeLine() 119 propertyNames = properties.keys() 120 propertyNames.sort() 121 for name in propertyNames: 122 value = properties[name] 123 # Fractions, perhaps we should do type introspection here? 124 if isinstance(value, tuple): 125 assert len(value) == 2 126 value = '%d/%d' % value 127 self.writeTag('property', [('name', name)], value)128130 if not plugs: 131 return 132 self.writeLine() 133 self.pushTag('plugs') 134 for plug in plugs: 135 self._writeComponentPlug(plug) 136 self.popTag()137139 self.pushTag('plug', [('type', plug.plugType)]) 140 self._writeProperties(plug.getProperties()) 141 self.popTag()142
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Jan 27 19:59:27 2011 | http://epydoc.sourceforge.net |