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

Source Code for Module flumotion.wizard.ondemandstep

  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  """A wizard step for configuring an on demand stream 
 23  """ 
 24   
 25  import gettext 
 26   
 27  import gobject 
 28  import gtk 
 29   
 30  from flumotion.common import messages 
 31   
 32  from flumotion.common.i18n import N_, gettexter 
 33  from flumotion.common.vfs import registerVFSJelly 
 34  from flumotion.ui.fileselector import FileSelectorDialog 
 35  from flumotion.wizard.models import HTTPServer 
 36  from flumotion.wizard.workerstep import WorkerWizardStep 
 37   
 38  __version__ = "$Rev: 7038 $" 
 39  _ = gettext.gettext 
 40  T_ = gettexter() 
 41   
 42   
43 -class OnDemand(HTTPServer):
44 """I am a model representing the configuration file for a 45 an on demand HTTP server component. 46 """ 47 componentType = 'http-server'
48 - def __init__(self, worker=None):
49 super(OnDemand, self).__init__(worker, mountPoint='/') 50 self.properties.path = '/tmp' 51 self.properties.port = 8800
52 53 # Component 54
55 - def getProperties(self):
56 properties = super(OnDemand, self).getProperties() 57 58 return properties
59 60
61 -class OnDemandStep(WorkerWizardStep):
62 """I am a step of the configuration wizard which allows you 63 to configure an on demand configuration over HTTP 64 """ 65 name = 'Demand' 66 title = _('Demand') 67 sidebarName = _('On demand') 68 section = _('Production') 69 gladeFile = 'ondemand-wizard.glade' 70
71 - def __init__(self, wizard):
72 self.model = OnDemand() 73 self._idleId = -1 74 WorkerWizardStep.__init__(self, wizard)
75 76 # WizardStep 77
78 - def setup(self):
79 self.path.data_type = str 80 self.port.data_type = int 81 self.mount_point.data_type = str 82 83 self._proxy = self.add_proxy(self.model.properties, 84 ['path', 85 'port', 86 'mount_point']) 87 88 self.mount_point.set_text("/") 89 registerVFSJelly()
90
91 - def workerChanged(self, worker):
92 self.model.worker = worker 93 self._runChecks()
94
95 - def getNext(self):
96 return None
97 98 # Public 99
100 - def getServerConsumer(self):
101 return self.model
102 103 # Private 104
105 - def _runChecks(self):
106 self.wizard.waitForTask('ondemand check') 107 108 def importError(failure): 109 failure.trap(ImportError) 110 self.info('could not import twisted-web') 111 message = messages.Warning(T_(N_( 112 "Worker '%s' cannot import module '%s'."), 113 self.worker, 'twisted.web')) 114 message.add(T_(N_("\nThis module is part of the '%s'."), 115 'Twisted Project')) 116 message.add(T_(N_("\nThe project's homepage is %s"), 117 'http://www.twistedmatrix.com/')) 118 message.id = 'module-twisted-web' 119 self.wizard.add_msg(message) 120 self.wizard.taskFinished(True)
121 122 def checkPathFinished(pathExists, path): 123 if not pathExists: 124 message = messages.Warning(T_(N_( 125 "Directory '%s' does not exist, " 126 "or is not readable on worker '%s'.") 127 % (path, self.worker))) 128 message.id = 'demand-directory-check' 129 self.wizard.add_msg(message) 130 else: 131 self.wizard.clear_msg('demand-directory-check') 132 133 self.wizard.taskFinished(blockNext=not pathExists)
134 135 def checkPath(unused): 136 path = self.path.get_text() 137 d = self.runInWorker('flumotion.worker.checks.check', 138 'checkDirectory', path) 139 d.addCallback(checkPathFinished, path) 140 141 d = self.wizard.checkImport(self.worker, 'twisted.web') 142 d.addCallback(checkPath) 143 d.addErrback(importError) 144
145 - def _abortScheduledCheck(self):
146 if self._idleId != -1: 147 gobject.source_remove(self._idleId) 148 self._idleId = -1
149
150 - def _scheduleCheck(self):
151 self._abortScheduledCheck() 152 self._idleId = gobject.timeout_add(300, self._runChecks)
153
154 - def _verify(self):
155 self._updateBlocked()
156
157 - def _updateBlocked(self):
158 # FIXME: This should be updated and only called when all pending 159 # tasks are done. 160 self.wizard.blockNext(self.mount_point.get_text() == '')
161
162 - def _showFileSelector(self):
163 def response(fs, response): 164 fs.hide() 165 if response == gtk.RESPONSE_OK: 166 self.model.properties.path = fs.getFilename() 167 self._proxy.update('path')
168 def deleteEvent(fs, event): 169 pass 170 fs = FileSelectorDialog(self.wizard.window, 171 self.wizard.getAdminModel()) 172 fs.connect('response', response) 173 fs.connect('delete-event', deleteEvent) 174 fs.selector.setWorkerName(self.model.worker) 175 fs.setDirectory(self.model.properties.path) 176 fs.show_all() 177 178 # Callbacks 179
180 - def on_mount_point_changed(self, entry):
181 self._verify() 182 self.wizard.blockNext(entry.get_text() == "/")
183
184 - def on_path__changed(self, entry):
185 self._scheduleCheck()
186
187 - def on_select__clicked(self, button):
188 self._showFileSelector()
189