Package flumotion :: Package wizard :: Module scenarios
[hide private]

Source Code for Module flumotion.wizard.scenarios

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 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  """Scenarios for the ConfigurationWizard 
 23   
 24  This file contains the base classes, common steps 
 25  and two basic scenarios for the configuration wizard. 
 26  """ 
 27  import gettext 
 28   
 29  from flumotion.ui.wizard import WizardStep 
 30  from flumotion.wizard.basesteps import ConsumerStep 
 31  from flumotion.wizard.consumptionsteps import ConsumptionStep 
 32  from flumotion.wizard.conversionsteps import ConversionStep 
 33  from flumotion.wizard.ondemandstep import OnDemandStep 
 34  from flumotion.wizard.productionsteps import LiveProductionStep 
 35  from flumotion.wizard.save import WizardSaver 
 36   
 37  _ = gettext.gettext 
 38   
 39   
40 -class LicenseStep(WizardStep):
41 name = "ContentLicense" 42 title = _("Content License") 43 section = _('License') 44 icon = 'licenses.png' 45 gladeFile = "license-wizard.glade" 46 47 # Public API 48
49 - def getLicenseType(self):
50 """Get the selected license type 51 @returns: the license type or None 52 @rtype: string or None 53 """ 54 if self.set_license.get_active(): 55 return self.license.get_selected()
56 57 # WizardStep 58
59 - def setup(self):
60 self.license.prefill([ 61 (_('Creative Commons'), 'CC'), 62 (_('Commercial'), 'Commercial')])
63
64 - def getNext(self):
65 return None
66 67 # Callbacks 68
69 - def on_set_license__toggled(self, button):
70 self.license.set_sensitive(button.get_active())
71 72
73 -class SummaryStep(WizardStep):
74 name = "Summary" 75 title = _("Summary") 76 section = _("Summary") 77 icon = 'summary.png' 78 gladeFile = "summary-wizard.glade" 79 lastStep = True 80 81 # WizardStep 82
83 - def getNext(self):
84 return None
85 86
87 -class Scenario(object):
88 """Base class for Scenarios 89 90 A scenario decides the following:: 91 - Which steps should be shown 92 - How the configuration for the steps should be saved 93 """
94 - def __init__(self, wizard):
95 self.wizard = wizard 96 self._flowName = 'default' 97 self._existingComponentNames = []
98
99 - def getSaver(self):
100 """Returns a wizard saver that should be used to save the 101 configuration generated to be created by this scenario. 102 @returns: the wizard saver 103 @rtype: L{WizardSaver} 104 """ 105 saver = WizardSaver() 106 saver.setFlowName(self._flowName) 107 saver.setExistingComponentNames(self._existingComponentNames) 108 return saver
109
110 - def setExistingComponentNames(self, componentNames):
111 """Tells the scenario about the existing components available, so 112 we can resolve naming conflicts when saving the configuration 113 @param componentNames: existing component names 114 @type componentNames: list of strings 115 """ 116 self._existingComponentNames = componentNames
117
118 - def addSteps(self):
119 """Add the wizard section steps specific for this scenario""" 120 raise NotImplementedError("%s.addSteps" % ( 121 self.__class__.__name__,))
122
123 - def save(self):
124 """Save the content of the wizard 125 Can be overridden in a subclass 126 @returns: wizard saver 127 @rtype: L{WizardSaver} 128 """ 129 raise NotImplementedError("%s.save" % ( 130 self.__class__.__name__,))
131
132 -class LiveScenario(Scenario):
133 short = _("Set up a live stream") 134 description = _( 135 """Allows you to create a live stream from a device or a file. 136 """) 137 138 # Scenario 139
140 - def addSteps(self):
141 self.wizard.addStepSection(LiveProductionStep) 142 self.wizard.addStepSection(ConversionStep) 143 self.wizard.addStepSection(ConsumptionStep) 144 self.wizard.addStepSection(LicenseStep) 145 self.wizard.addStepSection(SummaryStep)
146
147 - def save(self):
148 saver = self.getSaver() 149 150 saver.setAudioProducer(self.wizard.getAudioProducer()) 151 saver.setVideoProducer(self.wizard.getVideoProducer()) 152 153 productionStep = None 154 if self.wizard.hasStep('Production'): 155 productionStep = self.wizard.getStep('Production') 156 157 if productionStep and productionStep.hasVideo(): 158 if self.wizard.hasStep('Overlay'): 159 overlayStep = self.wizard.getStep('Overlay') 160 saver.setVideoOverlay(overlayStep.getOverlay()) 161 162 encodingStep = self.wizard.getStep('Encoding') 163 saver.setAudioEncoder(encodingStep.getAudioEncoder()) 164 saver.setVideoEncoder(encodingStep.getVideoEncoder()) 165 saver.setMuxer(encodingStep.getMuxerType(), encodingStep.worker) 166 167 consumptionStep = self.wizard.getStep('Consumption') 168 httpPorter = consumptionStep.getHTTPPorter() 169 existingPorter = self.wizard.getHTTPPorter() 170 if existingPorter is None: 171 self.wizard.setHTTPPorter(httpPorter) 172 elif existingPorter.properties.port == httpPorter.properties.port: 173 httpPorter = existingPorter 174 assert httpPorter.exists, httpPorter 175 saver.addPorter(httpPorter, 'http') 176 177 for step in self._getConsumptionSteps(): 178 consumerType = step.getConsumerType() 179 consumer = step.getConsumerModel() 180 consumer.setPorter(httpPorter) 181 saver.addConsumer(consumer, consumerType) 182 183 for server in step.getServerConsumers(): 184 saver.addServerConsumer(server, consumerType) 185 186 if self.wizard.hasStep('ContentLicense'): 187 licenseStep = self.wizard.getStep('ContentLicense') 188 if licenseStep.getLicenseType() == 'CC': 189 saver.setUseCCLicense(True) 190 191 return saver
192 193 # Private 194
195 - def _getConsumptionSteps(self):
196 """Fetches the consumption steps chosen by the user 197 @returns: consumption steps 198 @rtype: generator of a L{ConsumerStep} instances 199 """ 200 for step in self.wizard.getVisitedSteps(): 201 if isinstance(step, ConsumerStep): 202 yield step
203 204
205 -class OnDemandScenario(Scenario):
206 short = _("Stream files on demand") 207 description = _("""Allows you to serve a collection of files from disk.""") 208 209 # Scenario 210
211 - def addSteps(self):
212 self.wizard.addStepSection(OnDemandStep) 213 self.wizard.addStepSection(SummaryStep)
214
215 - def save(self):
216 saver = self.getSaver() 217 218 ondemandStep = self.wizard.getStep('Demand') 219 consumer = ondemandStep.getServerConsumer() 220 saver.addServerConsumer(consumer, 'ondemand') 221 return saver
222