Package flumotion :: Package component :: Package plugs :: Module wizard_gtk
[hide private]

Source Code for Module flumotion.component.plugs.wizard_gtk

  1  # -*- Mode: Python -*- 
  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  """Wizard plugin for the cortado http plug 
 23  """ 
 24   
 25  from zope.interface import implements 
 26   
 27  import gtk 
 28  import os 
 29   
 30  from flumotion.admin.assistant.interfaces import IHTTPServerPlugin 
 31  from flumotion.admin.assistant.models import Plug 
 32  from flumotion.common import messages 
 33  from flumotion.common.i18n import N_, gettexter 
 34  from flumotion.ui.fileselector import FileSelectorDialog 
 35  from flumotion.ui.plugarea import WizardPlugLine 
 36   
 37  __version__ = "$Rev$" 
 38  T_ = gettexter() 
 39   
 40   
41 -class RequestLoggerPlug(Plug):
42 """I am a model representing the configuration file for a 43 Request Logger plug. 44 """ 45 plugType = "requestlogger-file" 46
47 - def __init__(self, component):
48 Plug.__init__(self) 49 self.component = component 50 self.properties.logfile = '/tmp/access.log'
51
52 - def setActive(self, active):
53 if active: 54 self.component.addPlug(self) 55 else: 56 self.component.delPlug(self)
57 58
59 -class RequestLoggerPlugLine(WizardPlugLine):
60 gladeFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 61 'wizard.glade') 62 toplevel_name = 'requestlogger-window' 63
64 - def __init__(self, wizard, model, description):
65 WizardPlugLine.__init__(self, wizard, model, description) 66 67 self.logfile.data_type = str 68 self._proxy = self.add_proxy(self.model.properties, ['logfile']) 69 70 if self.getActive(): 71 self.model.setActive(True) 72 else: 73 self.plugActiveChanged(False)
74 75 # WizardPlugLine 76
77 - def plugActiveChanged(self, active):
78 self.logfile.set_sensitive(active) 79 self.select_logfile.set_sensitive(active) 80 self.model.setActive(active)
81 82 # Callbacks 83
84 - def on_select_logfile_clicked(self, button):
85 86 def response(fs, response): 87 fs.hide() 88 if response == gtk.RESPONSE_OK: 89 filename = os.path.join(fs.getFilename(), 'access.log') 90 self.model.properties.logfile = filename 91 self._proxy.update('logfile')
92 93 fs = FileSelectorDialog(self.wizard.window, 94 self.wizard.getAdminModel()) 95 96 fs.connect('response', response) 97 fs.selector.setOnlyDirectoriesMode(True) 98 fs.selector.setWorkerName(self.model.component.worker) 99 directory = os.path.dirname(self.model.properties.logfile) 100 fs.setDirectory(directory) 101 fs.show_all()
102
103 - def on_logfile_changed(self, button):
104 self._runChecks()
105
106 - def _runChecks(self):
107 self.wizard.waitForTask('ondemand check') 108 109 worker = self.model.component.worker 110 directory = os.path.dirname(self.logfile.get_text()) 111 112 def importError(failure): 113 failure.trap(ImportError) 114 self.info('could not import twisted-web') 115 message = messages.Warning(T_(N_( 116 "Worker '%s' cannot import module '%s'."), 117 worker, 'twisted.web')) 118 message.add(T_(N_("\nThis module is part of the '%s'."), 119 'Twisted Project')) 120 message.add(T_(N_("\nThe project's homepage is %s"), 121 'http://www.twistedmatrix.com/')) 122 message.id = 'module-twisted-web' 123 self.wizard.add_msg(message) 124 self.wizard.taskFinished(True) 125 return False
126 127 def checkPathFinished(pathExists): 128 if not pathExists: 129 message = messages.Warning(T_(N_( 130 "Directory '%s' does not exist, " 131 "or is not readable on worker '%s'.") 132 % (directory, worker))) 133 message.id = 'log-path-check' 134 self.wizard.add_msg(message) 135 self.wizard.taskFinished(True) 136 return False 137 else: 138 self.wizard.clear_msg('log-path-check') 139 self.wizard.taskFinished(False) 140 return True 141 142 self.wizard.taskFinished() 143 144 def checkPath(unused): 145 d = self.wizard.runInWorker( 146 worker, 'flumotion.worker.checks.check', 147 'checkDirectory', directory) 148 d.addCallback(checkPathFinished) 149 return d 150 151 d = self.wizard.checkImport(worker, 'twisted.web') 152 d.addCallback(checkPath) 153 d.addErrback(importError) 154 return d 155 156
157 -class RequestLoggerPlugWizardPlugin(object):
158 implements(IHTTPServerPlugin) 159
160 - def __init__(self, wizard, component):
161 self.wizard = wizard 162 self.model = RequestLoggerPlug(component)
163
164 - def workerChanged(self, worker):
165 pass
166
167 - def getPlugWizard(self, description):
168 return RequestLoggerPlugLine(self.wizard, self.model, description)
169 170
171 -class RequestModifierForceDownloadPlug(Plug):
172 """I am a model representing the configuration file for the 173 Force download plug. 174 """ 175 plugType = "requestmodifier-forcedownload" 176
177 - def __init__(self, component):
178 Plug.__init__(self) 179 self.component = component 180 self.properties.argument_name = 'force' 181 self.properties.trigger_value = 'true'
182
183 - def setActive(self, active):
184 if active: 185 self.component.addPlug(self) 186 else: 187 self.component.delPlug(self)
188 189
190 -class RequestModifierForceDownloadPlugLine(WizardPlugLine):
191
192 - def __init__(self, wizard, model, description):
193 WizardPlugLine.__init__(self, wizard, model, description) 194 195 if self.getActive(): 196 self.model.setActive(True)
197 198 # WizardPlugLine 199
200 - def plugActiveChanged(self, active):
201 self.model.setActive(active)
202 203
204 -class RequestModifierForceDownloadPlugWizardPlugin(object):
205 implements(IHTTPServerPlugin) 206
207 - def __init__(self, wizard, component):
208 self.wizard = wizard 209 self.model = RequestModifierForceDownloadPlug(component)
210
211 - def workerChanged(self, worker):
212 pass
213
214 - def getPlugWizard(self, description):
215 return RequestModifierForceDownloadPlugLine(self.wizard, self.model, 216 description)
217